请输入您要查询的百科知识:

 

词条 Crt0
释义

  1. Example crt0.s

  2. See also

  3. References

  4. External links

{{Lowercase title}}{{Program execution}}crt0 (also known as c0) 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. It generally takes the form of an object file called crt0.o, often written in assembly language, which is automatically included by the linker into every executable file it builds.[1]crt0 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.[1] Beside the initialization work required by the environment and toolchain, crt0 can perform additional operations defined by the programmer, such as executing C++ global constructors and C functions carrying GCC's ((constructor)) attribute.[2][3]

"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 crt0 are available for special usage scenarios; for example, the profiler gprof requires its programs to be compiled with gcrt0.[4]

Example crt0.s

This example is for linux x86_64 with at&t syntax.

.text

.globl _start

_start: # _start is the entry point known to the linker

    mov %rsp, %rbp    # setup a new stack frame    mov 0(%rbp), %rdi # get argc from the stack    lea 8(%rbp), %rsi # get argv from the stack    call main         # %rdi, %rsi are the first two args to main
    mov %rax, %rdi    # mov the return of main to the first argument    call exit         # terminate the program

See also

{{Portal|Computer programming}}
  • Entry point
  • Runtime system

References

1. ^{{cite web | url = http://www.embecosm.com/appnotes/ean9/html/ch05s02.html | title = The C Runtime Initialization, crt0.o | year = 2010 | accessdate = 2013-12-30 | website = embecosm.com}}
2. ^{{cite web | url = http://wiki.osdev.org/Creating_a_C_Library#Program_Initialization | title = Program initialization: Creating a C library | date = 2014-02-25 | accessdate = 2014-04-21 | website = osdev.org}}
3. ^{{cite web | url = http://wiki.osdev.org/Calling_Global_Constructors | title = Calling Global Constructors | date = 2014-04-08 | accessdate = 2014-04-21 | website = osdev.org}}
4. ^{{cite web | url = http://sourceware.org/binutils/docs-2.16/gprof/Compiling.html | title = Compiling a Program for Profiling: GNU gprof | accessdate = 2013-12-30 | website = sourceware.org}}

External links

  • crt0.o vs crt1.o
  • Linux x86 program start-up
  • [https://blogs.oracle.com/ksplice/entry/hello_from_a_libc_free Hello from a libc-free world! (Part 1)], March 16, 2010

1 : C standard library

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/22 9:45:02