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 ?
Well, the whole thing here is more complicated:
I have a full program, that builds OK using another IDE, and I want to build it with ARM-MDK. It's not that big, but still is something like a few dozens source files and at least as many include files, spread over several libraries + our own files.
I'm indeed considering monitoring everything and manually finding the biggest variables that are not needed. This is a long and tedious process, but more importantly, it is a recurring process. I'm sure I'll manage to modify what's needed to build now, but what I want is to be able to do this automatically in my future developments.
Last but not least, I like not to modify the libraries I use, to allow easier updates. So automatic removal really is the right option.