HOME

TheInfoList




(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 In computer programming, an entry point is where the first instructions of a program are executed, and where the program has access to command line arguments. To start a program's execution (computing), execution, the Loader (computing), loader ...
.


Form and usage

Crt0 generally takes the form of an
object file An object file is a computer file containing object code In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and ...
called , often written in
assembly language In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gene ...
, which is automatically included by the
linker Linker or linkers may refer to: Computing * Linker (computing) In computing, a linker or link editor is a computer System software, system program that takes one or more object files (generated by a compiler or an assembler (computing), asse ...
into every
executable file In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...
it builds. contains the most basic parts of the
runtime library In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gene ...
. As such, the exact work it performs depends on the program's compiler, operating system and
C standard library The C standard library or libc is the standard library A standard library in computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to per ...
implementation. Beside the initialization work required by the environment and
toolchain In software Software is a collection of instructions that tell a computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern computers can perform generic sets ...
, can perform additional operations defined by the programmer, such as executing
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

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 Gprof is a Profiling (computer programming), performance analysis tool for Unix applications. It used a hybrid of instrumentation and samplingSusan L. Graham, Peter B. Kessler, and Marshall K. Mckusick''gprof: a Call Graph Execution Profiler''// Pr ...
, programs must be compiled with instead.


Example crt0.s

This example is for
Linux Linux ( or ) is a family of open-source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product ...
x86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging mod ...
with , without an actual C runtime. .text .globl _start _start: # _start is the entry point known to the linker xor %ebp, %ebp # effectively RBP := 0, mark the end of stack frames mov (%rsp), %edi # get argc from the stack (implicitly zero-extended to 64-bit) lea 8(%rsp), %rsi # take the address of argv from the stack lea 16(%rsp,%rdi,8), %rdx # take the address of envp from the stack xor %eax, %eax # per ABI and compatibility with icc call main # %edi, %rsi, %rdx are the three args (of which first two are C standard) to main mov %eax, %edi # transfer the return of main to the first argument of _exit xor %eax, %eax # per ABI and compatibility with icc call _exit # terminate the program


See also

*
Entry point In computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, cau ...

Entry point
*
Runtime system In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gen ...


References

{{Reflist


External links


crt0.o vs crt1.o



Hello from a libc-free world! (Part 1)
March 16, 2010
glibc x86_64 start.S
C standard library C programming language family