|ARM Technical Support Knowledge Articles|
The ANSI C specification states that static data that is not initialized explicitly should be initialized to zero. The compiler therefore places both zero-initialized and uninitialized data in the same
ZI section, which is zero-filled at run time by the C library initialization code.
There may be situations where you do not want uninitialized data to be initialized to zero. For example, you may have memory-mapped peripherals or non-volatile memory which you do not want to be initialized at run-time.
If you do not want
ZI sections to be initialized to zero, use the
UNINIT scatter-loading execution region attribute.
UNINIT is described in the Linker and Utilities Guide.
UNINIT prevents all of the
ZI data in the execution region from being initialized to zero, including both zero-initialized and uninitialized data. To stop only uninitialized data from being initialized to zero, you must place it in a different section to any explicitly zero-initialized data, using the compiler pragma:
#pragma arm section.
#pragma arm section is documented in the RVCT Compiler Reference Guide.
#pragma arm section can only be used with ADS 1.2 and later compilers. In RVCT 2.1 and later the GNU
__attribute__ ((section ("...")))syntax can be used as an alternative to
#pragma arm section, when compiling with
For example, given the C code:
int i, j; //uninit (in .bss section)
int k=0, l=0; //zero-init (in .bss section)
You can use
#pragma arm section to place the uninitialized data into a different section to the zero-initialized data, for example:
#pragma arm section zidata = "non_init"
int i, j; // uninit (in non_init section)
#pragma arm section zidata // back to default (.bss section)
int k=0, l=0; // zero-init (in .bss section)
non_init section can then be placed into its own
UNINIT execution region, for example:
* (+ZI) ;ZI data will be initialized to zero
EXEC_2 +0 UNINIT
* (non_init) ;ZI data will not be initialized to zero
More information on the
UNINIT execution region attribute is available in the ARM Linker documentation.
Article last edited on: 2012-02-14 11:34:58
Did you find this article helpful? Yes No
How can we improve this article?