You copied the Doc URL to your clipboard.

How to prevent uninitialized data from being initialized to zero

The ANSI C specification states that static data that is not explicitly initialized, is to be initialized to zero. Therefore, by default, the compiler puts both zero-initialized and uninitialized data into the same ZI data section, which is populated with zeroes at runtime by the C library initialization code.

You can prevent uninitialized data from being initialized to zero by placing that data in a different section. This can be achieved using #pragma arm section, or with the GNU attribute __attribute__((section("name"))) when compiling with --gnu.

#pragma arm section zidata = "non_initialized"
int i, j; // uninitialized data in non_initialized section (without the pragma,
             would be in .bss section by default)
#pragma arm section zidata // back to default (.bss section)
int k = 0, l = 0; // zero-initialized data in .bss section

The non_initialized section is then placed into its own UNINIT execution region:

LOAD_1 0x0
  EXEC_1 +0
    * (+RO)
    * (+RW)
    * (+ZI) ; ZI data gets initialized to zero
    * (non_init) ; ZI data does not get initialized to zero

Was this page helpful? Yes No