I'm using Keil 5.23 and trying to use arm-clang compiler v6.6.
I want to create an array that will contain compilation date and time. I need this array to be placed in flash memory, so I made it const. I don't need to access this array, so I made it static.
Now I have a problem. If I declare it like this:
static const char date_time[] = { "compilation time: " __DATE__ ", " __TIME__ };
It gets removed by compiler, even though I set -O0. Adding __attribute__((used)). According to this page www.keil.com/.../armclang_mig_chr1398848377314.htm even objects marked as 'used' can be removed by linker nonetheless. So I need to add a linker option --keep=symbol_name or --noremove.
If I add --noremove, linker keeps to much data, bloating binary size from 4KiB to 17KiB. If I use --keep, linker tells me that it can't find that symbol:
.\obj\dummy.axf: Warning: L6320W: Ignoring --keep command. Cannot find argument 'date_time'.
Even if I don't declare it as static.
Adding volatile doesn't help either.
Please, tell me, what am I doing wrong? How can I tell compiler and linker not to remove this array?
I don't know if it is formally standardised, but it is certainly very common & widespread - if not universal.
stackoverflow.com/.../why-do-c-compilers-prepend-underscores-to-external-names