EmbDev.net

Forum: ARM programming with GCC/GNU tools GNU Linker not removing unused constant strings..


von David (Guest)


Rate this post
useful
not useful
I am using GNU version 4.7

with following link options:

 --relax -Xld -nostdlib --gc-sections -Xld --cref -Xld --whole-archive

my issue is the linker is not removing unused strings from printf() 
functions that are unused in the file.  I have tried removing the 
--relax and --whole-archive without any results to this issue.

Example file included in build:

functionIncludedInLink
{
   printf("THIS SHOULD BE INCLUDED IN EXECUTATBLE ");
}

functionNOTIncludedInLink
{
   printf("THIS SHOULD BE REMOVED BY LINKER");
}


The issue is that after the file is compiled that includes both 
functions, constant data is grouped together.  However, because 
functionNOTIncludedInLink is not used by the executable, it is removed 
by the linker, however, the linker is not removing the constant string 
data that was previously allocated by the compiler for the function 
("THIS SHOULD BE REMOVED BY LINKER" remains in const data section).

Are there any ld options that can be used to fix this issue?

I do not want to have to eliminate all my unused functions from files to 
keep the constant data from getting compiled and linked into my 
executable.

von ArminJ (Guest)


Rate this post
useful
not useful
Do you used the compiler flags -ffunction-sections -fdata-sections 
before???

von Clemens L. (Guest)


Rate this post
useful
not useful
Alternatively, use LTO (-flto).

And consider upgrading to gcc 5.2.

von David (Guest)


Rate this post
useful
not useful
I tried adding the compiler flags that were suggested:

-fdata-sections
-flto

I a was already using -ffunction-sections

but none of those options solved the problem.  I think It is more of a 
linker issue and I haven't found an option so far that i will solve this 
issue.  I will attempt to upgrade to 5.2 to see if that makes a 
difference or not.

thanks for the suggestions.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.