GCC Linker not removing unused constant strings..

Asked by David

I am using GCC for Arm version 4.7, not sure if ver 4.9 solves this issue or not.

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.

Question information

Language:
English Edit question
Status:
Needs information
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
David (dcavanau-u) said :
#1

I did upgrade to arm-non-eabi-gcc 4.9, but still had same results.

Any file that had constant strings in non linked functions, still has the unused constant strings from those functions included in the final image (linker does not remove unused constant strings0.

Revision history for this message
Prakhar Bahuguna (prakhar-deactivatedaccount) said :
#2

Hi, does the issue still occur for you with GCC 6-2017Q1? If so, please could you provide a reproducer and full command line that demonstrates the issue?

Can you help with this problem?

Provide an answer of your own, or ask David for more information if necessary.

To post a message you must log in.