GNU Linker not removing unused constant strings..

Guest #4304833
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.
Guest #4307501
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.

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now