Removing variables used in unused functions
Hello,
I'm having issue with removing unused variables, when they are used in unused functions.
I'm using Keil 5.25.2.0, 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 - --remove My MCU is a STM32F0, Cortex M0.
Here is a sample of what I do :
int unused_data[100]; main(){ some code... my_unused_function(); some more code... } void my_unused_function(void){ int i; 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 so good.
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 removed.
But ZI-data doesn't decrease, the variable is still there. And only if I comment "unused_data[i] = i;", then unused_data is successfully removed.
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 ?
There was no need to start a whole new thread!
http://www.keil.com/forum/63797