http://blog.csdn.net/dadoneo/article/details/8201403
glibc Auxiliary Runtime (C Runtime Library): CRT0.O,CRT1.O,CRTI.O crtn.o,crtbegin.o crtend.oCategory: Linux2012-11-19 21:46 6036 people read reviews (2) favorite reports
CRT1.O, CRTI.O, CRTBEGIN.O, CRTEND.O, CRTN.O, etc. target files and DAEMON.O (generated by our own C program files) are linked into an execution file. The previous 5 target files were started, initialized, constructed, destroyed, and ended, and they are usually automatically linked to the application. For example, the main () function of an application is called by these files. If you do not have a standard link (compile option-nostdlib), we must indicate these necessary target files, and if not specified, the linker will prompt for the _start symbol and therefore cause the link to fail. Also, the order in which the target file is given to the compiler is important because the GNU linker (the compiler automatically calls the linker for a link to the target file) is just a single-processing linker.
GLIBC has several runtime libraries (C Runtime Library) run by the helper program, namely/USR/LIB/CRT1.O,/USR/LIB/CRTI.O, and/USR/LIB/CRTN.O, where CRT1.O contains the program's entry function _ Start and two undefined symbols, __libc_start_main and main, are called by _start to initialize libc __libc_start_main, and then invoke the main function defined in our source code; Because code like a global static object needs to be executed before the main function, CRTI.O and CRTN.O are responsible for assisting in initiating the code. In addition, GCC also has CRTBEGIN.O and crtend.o two files, these two target files are used in conjunction with GLIBC to achieve the global construction and destruction of C + +.
Android Bionic, this C runtime library design is not particularly powerful, and some of the GNU Glic functions are not implemented, this is the problem of porting. and the C Runtime library didn't use CRT0.O, CRT1.O,CRTI.O CRTN.O,CRTBEGIN.O CRTEND.O, but uses Android's own CRTBEGIN_DYNAMIC.O, CRTBEGIN_STATIC.O and CRTEND_ANDROID.O. CRT1.O is a subsequent evolutionary version of CRT0.O, which is important in CRT1.O. The entry for the Init and. Fini segments, and the _start function: The init and. Fini segments are actually implemented by CRTI.O and CRTN.O. The init segment is the initialization work code before the main function, such as the construction of a global variable. The Fini section is responsible for the cleanup work after the main function. CRTI.O CRTN.O is responsible for the initialization of C, while C + + must rely on CRTBEGIN.O and CRTEND.O to help implement it.
So, in the standard Linux platform, link order is: ld CRT1.O CRTI.O [user_objects] [system_libraries] crtn.o
In Android, the Order of link is: arm-eabi-g++ crtbegin_dynamic.o [user_objects] [SYSTEM_LIBRARIES]CRTEND_ANDROID.O
So that's why there's another way to explain why it's not appropriate to compile for codesourcery and so on, not including BSP.
Main () is also a function.
This is because it will be called as a function of the CRT0.S assembler when compiling the connection. Crt0.s is a stub program in which the "CRT" in the name is the abbreviation for "C run-time". The program's target file will be linked at the beginning of each user execution program, primarily for setting up some initialization global variables. Typically, when the GCC compilation chain is used to deliver a file, GCC automatically links the file's code as the first module in the executable program. Use the Show Details option "-V" at compile time to clearly see the link operation process. Therefore, in the usual compilation process, we do not need to specifically specify the stub module CRT0.O. In order to use the ELF-formatted target file and to create a shared library module file, now the compiler has expanded crt0 into several modules: crt1.0, CRTI.O, CRTBEGIN.O, CRTEND.O, and CRTN.O. These modules are linked in the order of CRT1.O, CRTI.O, CRTBEGIN.O (CRTBEGINS.O), all program modules, CRTEND.O (CRTENDS.O), CRTN.O, and library module files. The configuration file for gcc specfile specifies this link order. Among them, CRT1.O, CRTI.O and CRTN.O are provided by C library, which is the "boot" module of C program; CRTBEGIN.O and CRTEND.O are the startup modules of the C + + language, provided by the compiler GCC While CRT1.O is similar to CRT0.O, which is used primarily to do some initialization work before calling main (), the global symbol _start is defined in this module. CRTBEGIN.O and CRTEND.O are used primarily in the C + + language to perform global construction (constructor) and destructor (destructor) functions in the. ctors and. Dtors districts. The CRTBEGINS.O and CRTENDS.O functions are similar to the previous two, but are used to create shared modules. CRTI.O is used to perform initialization functions in the. Init area init (): The init area contains the initialization code for the process, that is, when the program starts executing, the system executes the code in. Init before calling main (). The CRTN.O is used in the. Fini zone to execute the process termination exit handler function fini () function, that is, when the program exits normally (after main () is returned), the system will schedule execution. Fini code.
Go to an article about GCC