removing unused functions during final link
Melvin Blades
melvin.blades@gmail.com
Wed Sep 3 15:09:00 GMT 2014
For a simple example I created 3 files.
root.c -- has main() which calls one function in show.c
show.c - has two functions, one is called by main, one is not
called. ( both use puts to print a message.)
show2.c -- has two functions. Neither are called
--------Makefile--------
OBJS := root.o show.o show2.o
SOURCE := root.c show.c show2.c
all: $(SOURCE)
${CC} -mips32 -fdata-sections -ffunction-sections -c $(SOURCE)
${CC} $(OBJS) -Wl,--gc-sections -o root.exe
-------End --------
The resulting executable contains the texts strings and function names
from both functions in show.c and neither function of show2.c My
usage of -fdata-section -ffunction-section and -gc-sections prevents
the functions in show2.c from being linked in , but not the unused
functions in show.c
$home/dev1/>file root.exe
root.exe: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV),
dynamically linked (uses shared libs), not stripped
~
On Wed, Sep 3, 2014 at 3:21 AM, Andrew Haley <aph@redhat.com> wrote:
> On 09/03/2014 04:20 AM, Melvin Blades wrote:
>> Using gcc instead of ld, I was able to get it to strip unused
>> functions if all the functions in a file are not called.
>> But I could not get it to strip unused functions if they are in the
>> same source file as used functions .
>>
>> Is there a way to get it strip ALL the unused functions?
>
> That should have worked. Please tell us the exact command you used.
>
> Andrew.
>
>
More information about the Gcc-help
mailing list