Removing unused functions and dead codeΒΆ

To remove dead code, add the follow to 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...

-Wl,-static:
Link against static libraries. Required for dead-code elimination.
-fvtable-gc:
C++ virtual method table instrumented with garbage collection information for the linker.
-fdata-sections:
Keeps data in separate data sections, so they can be discarded if unused.
-ffunction-sections:
Keeps funcitons in separate data sections, so they can be discarded if unused.
-Wl,–gc-sections:
Tell the linker to garbage collect and discard unused sections.
-s:
Strip the debug information, so as to make the code as small as possible.

Previous topic

Building the ARM Tool chain

Next topic

Projects

This Page