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'm using similar string, but with one difference. It is transmitted via serial port to the host PC. In this case, string is present in flash memory. If you don't want to tansmit it, try to use some dummy function, in which this string is somehow used.
Andrey Shemet, that's my last resort. I'd prefer to find another way if there is one.
"--keep date_time"
seems to work instead of
"--keep=date_time"
Just const data in flash, no RAM allocated.
Robert McNamara Weirdly that doesn't work for me. Linker keeps saying