On ARM GCC (plain C code), when I declare a constant as in
__attribute__((used,section(".rodata.$AppID")))const uint8_t ApplicationID[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00};
and I don't refer to it in the code, it's optimized out, and listed in Discarded input sections on map file.It's included in binary output only if I refer to it, somewhere else in the sources.
Shouldn't the "used
" tag alone be enough? In GCC manual (6.32.1 Common Variable Attributes) I read:
used
This attribute, attached to a variable with static storage, means that the variable must be emitted even if it appears that the variable is not referenced.
The meaning is to have it at a fixed memory address, in the specified section, for a separate application to check for it
I'm running ARM GCC as provided with NXP MCUXpresso 11.1, reporting verbose version as
GNU C17 (GNU Tools for Arm Embedded Processors 8-2019-q3-update) version 8.3.1 20190703 (release) [gcc-8-branch revision 273027] (arm-none-eabi)compiled by GNU C version 5.3.1 20160211, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP