Keil Logo

Removing unused variables that are used in unused functions

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Bru No
Posted
2-Aug-2018 13:29 GMT
Toolset
ARM
New! Removing unused variables that are used in unused functions

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 ?

Read-Only
Author
Andrew Neil
Posted
2-Aug-2018 14:06 GMT
Toolset
ARM
New! RE: Removing unused variables that are used in unused functions

There was no need to start a whole new thread!

http://www.keil.com/forum/63797

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.