crt0.o

crt1.o, crti.o, crtbegin.o, crtend.o, crtn.o and other object files and daemon.o (produced by our own C program files) linked into an executable file. Action front five target files are started, initialization, configuration, and destructors end, they will generally be automatically linked to the application. For example, main application () function is invoked by these documents. If you do not link standard, then (compile option -nostdlib), we must identify those necessary target file, if not specified, the linker will not able to find _start symbol, and therefore lead to a link failure. Moreover, the order of the target file to the compiler is also important, because the GNU linker (compiler will automatically call the linker to link object files) just a single treatment linker.

 

There are several auxiliary Glibc running runtime (C RunTime Library), and are /usr/lib/crt1.o,/usr/lib/crti.o /usr/lib/crtn.o, wherein the crt1.o containing program entry function _start undefined symbols and two main and __libc_start_main, the _start responsible for calling the libc __libc_start_main initialization, and then calls the main function that we defined in the source code; in addition, since a global static object like this code needs to be executed before the main function, crti.o and crtn.o responsible for starting aid code. Further, there are also of Gcc in crtend.o crtbegin.o and two files, object files used in conjunction with these two glibc C ++ to achieve global constructors and destructors.


android bionic, the C runtime library design is not particularly powerful, and the function of some gnu glic not achieved, this is a problem encounter transplantation. Moreover, the C runtime library also does not use crt0.o, crt1. o, crti.o crtn.o, crtbegin.o crtend.o, instead of using the android own crtbegin_dynamic.o, crtbegin_static.o and crtend_android.o. crt1.o is crt0.o follow the evolution version of the entrance ..init segment crt1.o will be a very important segment and .init .fini segment and _start function and .fini segment is actually on crti.o and crtn . init section .o implemented before the main function initialization code, such as construction of global variables. fini section is responsible for cleaning up after .crti.o crtn.o main function is responsible for the initialization of C, and C ++, you must Depending crtbegin.o and to help achieve crtend.o
        So, under standard linux platform, the link sequence is: ld crt1.o crti.o [user_objects] [ system_libraries] crtn.o
        while in android, the link order They are: arm-eabi-g ++ crtbegin_dynamic.o [user_objects] [system_libraries] crtend_android.o
        so that's why from the other side is not suitable codesourcery like to compile things develop android underlying reasons, and this does not include BSP and the like.

 

main () is a function.

This is because the function when compiling the connection as it will crt0.s assembler is called. crt0.s is a pile (Stub) program, the name of "crt" is an abbreviation for "C run-time" of. The goal of the program file will be linked at the beginning of each user program execution, mainly used to set some initial global variables. During normal use gcc compiler generates link files, gcc automatically document the code as the first module is linked into the executable. At compile time using the Show Details option "-v" can be clearly seen that the process of this link. Therefore, in the usual compilation process, we do not need to specify the particular stub module crt0.o. To use the ELF object file format as well as the establishment of a shared library module file, the compiler has now expanded into the crt0 several modules: crt1.0, crti.o, crtbegin.o, crtend.o and crtn.o. These modules link order for crt1.o, crti.o, crtbegin.o (crtbeginS.o), all program modules, crtend.o (crtendS.o), crtn.o, the library module file. gcc specfile configuration file specifies that the link order. Which, crt1.o, crti.o and crtn.o provided by the C library is the "start" module C program; crtbegin.o and crtend.o is C ++ language startup module, provided by the compiler gcc; and crt1. o the role of crt0.o and similar, mainly for calling main () to do some initialization before, _start global symbol is defined in this module. crtbegin.o and crtend.o mainly for C ++ language, performing a global configuration (constructor) and destructor (destructor) function and .dtors .ctors region. CrtbeginS.o action with both front and crtendS.o similar, but for creating shared module. crti.o for performing initialization function init .init zone in (). .Init area initialization code contained in the process, that is, when the program started, the system will first execute the code in .init before calling main (). crtn.o are used.

 


----------------
Disclaimer: This article is CSDN blogger "Dartagnan" of the original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/dadoneo/article/details/8201403

Guess you like

Origin www.cnblogs.com/xpylovely/p/11412380.html