C Programs Before main Function

What does the program do before main() function

The picture from Patrick Horgan describes what will the c program do before main function.

before main

crt0.o, ctri.o, ctrbegin.o, ctrn.o

If you compile a c program, the linker will link crt0.o, ctri.o, ctrbegin.o, ctrn.o with the target object together.

crt0.o contains _start function, it will initialize the process before call main function, it is defined in libc’s crt0.s file.

According to osdev, ctri.o defines the header of _init and _fini function, and ctrn.o defines the footer of _init and _fini function. And linker will link ctrbegin.o’s section .init and .fini between ctri.o and ctrn.o

ctrbegin.o also defines some functions such as deregister_tm_clones, register_tm_clones, __do_global_dtors_aux, frame_dummy

Reference