my-server
← Wiki Redirected from Global constructor

Crt0

(also known as ) is a set of execution startup routines linked into a C program that performs any initialization work required before calling the program's main function. After the main function completes the control returns to crt0, which calls the library function exit(0) to terminate the process.

Form and usage

Crt0 generally takes the form of an object file called , often written in assembly language, which is automatically included by the linker into every executable file it builds.

contains the most basic parts of the runtime library. As such, the exact work it performs depends on the program's compiler, operating system and C standard library implementation. Beside the initialization work required by the environment and toolchain, can perform additional operations defined by the programmer, such as executing C++ global constructors and C functions carrying GCC's attribute.

"crt" stands for "C runtime", and the zero stands for "the very beginning". However, when programs are compiled using GCC, it is also used for languages other than C. Alternative versions of are available for special usage scenarios; for example, to enable profiling with gprof, programs must be compiled with instead.

Example crt0.s

This example is for Linux x86-64 with AT&T syntax, without an actual C runtime.

See also

References

External links