It is a requirement to initialize all global and static variables to 0 according to C standard specification.
- Initialization all global and static variables is a common requirement of all CRTs above.
- The separate routine
_crtinitinitializes memory in the.bsssection of the program. The_crtinitroutine is also the wrapper that invokes the main procedure. - Before invoking the main procedure, it can invoke other initialization functions.
The
_crtinitroutine 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
- The profiling process uses the second stage startup file. This file 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
- When the compiler uses the
-mno-clearbssswitch, it uses this second-stage startup file. This file 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
- During profiling with the
-mno-clearbssswitch, this second-stage startup file 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