GCC 4.9 Linker is not removing unused constant strings

Bug #1506552 reported by David
6
This bug affects 1 person
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-multiple-definition

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:

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.

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.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.