This is the mail archive of the
mailing list for the GCC project.
Re: Removing unused functions/dead code
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: "Dr. Torsten Rupp" <rupp at aicas dot com>, gcc-help at gcc dot gnu dot org
- Date: Tue, 12 Aug 2003 15:58:08 -0500
- Subject: Re: Removing unused functions/dead code
Hi Dr. Rupp,
I was just looking into this very thing!
Do this in your Makefile...
DEADCODESTRIP := -Wl,-static -fvtable-gc -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-s
foo : foo.c
g++ $(DEADCODESTRIP) $< -o $@
Step by step...
Link against static libraries. Required for dead-code elimination.
C++ virtual method table instrumented with garbage collection information for the linker.
Keeps data in separate data sections, so they can be discarded if unused.
Keeps funcitons in separate data sections, so they can be discarded if unused.
Tell the linker to garbage collect and discard unused sections.
Strip the debug information, so as to make the code as small as possible. (I presume that you'd want to do this in a dead-code removal build.)
The requirement to link against the static libraries was surprising to me. But there you go.