According to the C standard specification, all global and static variables must be
initialized to 0. This is a common functionality required by all the CRTs above. Another
routine, _crtinit, is invoked. The _crtinit routine
initializes memory in the .bss section of the program. The
_crtinit routine is also the wrapper that invokes the main
procedure. Before invoking the main procedure, it might invoke other initialization
functions. The _crtinit routine is supplied by the startup files
described below.
- crtinit.o
-
This default, second stage, C startup file performs the following steps:
- Clears the
.bsssection to zero. - Invokes
_program_init. - Invokes “constructor” functions (
_init). - Sets up the arguments for main and invokes main.
- Invokes “destructor” functions (
_fini). - Invokes
_program_cleanand returns.
- Clears the
- pgcrtinit.o
-
This second stage startup file is used during profiling, and performs the following steps:
- Clears the
.bsssection to zero. - Invokes
_program_init. - Invokes
_profile_initto initialize the profiling library. - Invokes “constructor” functions (
_init). - Sets up the arguments for main and invokes main.
- Invokes “destructor” functions (
_fini). - Invokes
_profile_cleanto cleanup the profiling library. - Invokes
_program_clean, and then returns.
- Clears the
- sim-crtinit.o
-
This second-stage startup file is used when the
-mno-clearbssswitch is used in the compiler, and performs the following steps:- Invokes
_program_init. - Invokes “constructor” functions (
_init). - Sets up the arguments for main and invokes main.
- Invokes “destructor” functions (
_fini). - Invokes
_program_clean, and then returns.
- Invokes
- sim-pgcrtinit.o
-
This second stage startup file is used during profiling in conjunction with the
-mno-clearbssswitch, and performs the following steps in order:- Invokes
_program_init. - Invokes
_profile_initto initialize the profiling library. - Invokes “constructor” functions (
_init). - Sets up the arguments for and invokes main.
- Invokes “destructor” functions (
_fini). - Invokes
_profile_cleanto cleanup the profiling library. - Invokes
_program_clean, and then returns.
- Invokes