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

von David (Guest)

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:



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 

von ArminJ (Guest)

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

von Clemens L. (Guest)

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

And consider upgrading to gcc 5.2.

von David (Guest)

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


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.


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]
  • [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.