SLAU132Y September 2004 – June 2021
The tables in the .cinit section consist of variable-size initialization records. Each variable that must be autoinitialized has a record in the .cinit section. Figure 7-6 shows the format of the .cinit section and the initialization records.
The fields of an initialization record contain the following information:
Each variable that must be autoinitialized has an initialization record in the .cinit section.
The following example shows initialized global variables defined in C.
int x;
short i = 23;
int *p =
int a[5] = {1,2,3,4,5};
The corresponding initialization table is as follows. The section .cinit:c is a subsection in the .cinit section that contains all scalar data. The subsection is handled as one record during initialization, which minimizes the overall size of the .cinit section.
.global _x
.bss _x,4,4
.sect ".cinit:c"
.align 8
.field (CIR - $) - 8, 32
.field _I+0,32
.field 23,16 ; _I @ 0
.sect ".text"
.global _I
_I: .usect ".bss:c",2,2
.sect ".cinit:c"
.align 4
.field _x,32 ; _p @ 0
.sect ".text"
.global _p
_p: .usect ".bss:c",4,4
.sect ".cinit"
.align 8
.field IR_1,32
.field _a+0,32
.field 1,32 ; _a[0] @ 0
.field 2,32 ; _a[1] @ 32
.field 3,32 ; _a[2] @ 64
.field 4,32 ; _a[3] @ 96
.field 5,32 ; _a[4] @ 128
IR_1: .set 20
.sect ".text"
.global _a
.bss _a,20,4
;**********************************************************************
;* MARK THE END OF THE SCALAR INIT RECORD IN CINIT:C *
;**********************************************************************
CIR: .sect ".cinit:c"
The .cinit section must contain only initialization tables in this format. When interfacing assembly language modules, do not use the .cinit section for any other purpose.
The table in the .pinit section simply consists of a list of addresses of constructors to be called (as shown in the following figure). The constructors appear in the table after the .cinit initialization.
When you use the --rom_model or --ram_model option, the linker combines the .cinit sections from all the C/C++ modules and appends a null word to the end of the composite .cinit section. This terminating record appears as a record with a size field of 0 and marks the end of the initialization tables.
Likewise, the --rom_model or --ram_model link option causes the linker to combine all of the .pinit sections from all C/C++ modules and append a null word to the end of the composite .pinit section. The boot routine knows the end of the global constructor table when it encounters a null constructor address.
The const-qualified variables are initialized differently; see Section 6.8.1.