How do I prevent uninitialized data from being initialized to zero?
Applies to: ARM Developer Suite (ADS), Compilers, General Build Issues, Linker, RealView Developer Kit for XScale (RVXDK), RealView Developer Suite (RVDS) 2.0, RealView Developer Suite (RVDS) 2.1, RealView Developer Suite (RVDS) 2.2, RealView Development Suite (RVDS) 3.0, RealView Development Suite (RVDS) 3.1 | |
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-file 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 your Compilers and Libraries Guide, and your Linker and Utilities Guide, found at our Software Development Tools Documentation page. Note: #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 instead of #pragma arm section, when compiling with –gnu. For example, given the C code: int i, j; //uninit (in .bss section)<br />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, e.g: #pragma arm section zidata = "non_init"<br />int i, j; //uninit (in non_init section)<br />#pragma arm section zidata //back to default (.bss section)<br />int k=0, l=0; //zero-init (in .bss section) The non_init section can then be placed into its own UNINIT execution region, e.g: LOAD_1 0x0<br />{<br /> EXEC_1 +0<br /> {<br /> * (+RO)<br /> * (+RW)<br /> * (+ZI) ;ZI data will be initialized to zero<br /> } EXEC_2 +0 UNINIT<br /> {<br /> * (non_init) ;ZI data will not be initialized to zero<br /> }<br />} |
转载请注明:在路上 » How do I prevent uninitialized data from being initialized to zero?