GCC 4.9 Linker is not removing unused constant strings
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
New
|
Undecided
|
Unassigned |
Bug Description
I am using GCC for Arm version 4.9 (previously version 4.7 had same issue)
with following link options:
-nostdlib
-nostartfiles
-nodefaultlibs
--gc-sections
--cref
--allow-
my issue is the linker is not removing unused strings from printf()
functions that are unused in the file. I have tried adding the
compiler options -flto and -fdata-sections with no success.
Example file included in build:
functionInclude
{
printf("THIS SHOULD BE INCLUDED IN EXECUTATBLE ");
}
functionNOTIncl
{
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
functionNOTIncl
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.
So to summarize: The linker is not removing unused constant strings from the final build, even though it removed the unused functions that those strings were found in.