EmbDev.net

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


Author: David (Guest)
Posted on:

Rate this post
0 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.

Author: ArminJ (Guest)
Posted on:

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

Author: Clemens L. (Guest)
Posted on:

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

And consider upgrading to gcc 5.2.

Author: David (Guest)
Posted on:

Rate this post
0 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

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.