Content originally posted in LPCWare by toddatm on Thu Oct 27 14:31:51 MST 2011
I'm moving some code from another compiler and the following constant data is eventually to be placed in ROM. The source code does not access the symbols, so it appears the compiler/linker is removing the variables. I tried adding __attribute__((used)), but the compiler/linker is still removing the data/symbols.
#define CODE_MAJOR_VERSION (0)
#define CODE_MINOR_VERSION (1)
#define BOOT_CODE_VERSION ((unsigned short)(CODE_MAJOR_VERSION<<8 | CODE_MINOR_VERSION))
#define BUILD_DATE_LEN (22) // 11 + 1 + 8 + 1(for Null) + 1 to force it on an even word boundary
#define BUILD_DATE (__DATE__ " " __TIME__)
#define BUILD_DATE_ADDR (BOOT_CODE_VERSION_ADDR - BUILD_DATE_LEN) // Null-terminated date/time stored before that
const unsigned short codeVersion __attribute__((used)) = BOOT_CODE_VERSION;
const unsigned char buildDateTime[BUILD_DATE_LEN] __attribute__((used)) = BUILD_DATE;
Any advice on how to force this data into the ROM section would be appreciated? I'd rather not do it in the linker file, because I'm using the automatically generated linker files right now. If I must, though, OK. Is it possible to mix and match auto-generated linker file and my own? Thanks.