Removing variables used in unused functions
I'm having issue with removing unused variables, when they are
used in unused functions.
I'm using Keil 184.108.40.206, armcc.exe and armlink.exe V5.06 update 6
build 750. My project options are set for space optimization:
- Use cross-module optimization
- One ELF section per function
- -O2 -Ospace
My MCU is a STM32F0, Cortex M0.
Here is a sample of what I do :
some more code...
for(i=0; i<100; i++) unused_data[i] = i;
When adding unused_data and my_unused_function(), I can see the
code increasing, and 100 bytes of data being added to ZI-data. So far
When commenting the call to my_unused_function(), the code
decreases as expected. I get the original code size (when the
function was not there), which means it has been successfully
But ZI-data doesn't decrease, the variable is still there. And
only if I comment "unused_data[i] = i;", then unused_data is
So I have this variable, used only in an unused function, which is
virtually unused. But the linker doesn't seem to see this, and
doesn't remove it. Which is quite a problem, this actually prevents
my code to fit into the RAM of my MCU.
So how can I tell the linker to remove this (and all the other)
unused variables ?