MyTetra Share
Делитесь знаниями!
Как убрать неиспользуемый код, вариант 2
Время создания: 06.12.2008 00:03
Текстовые метки: gcc, static compiling, статическая компиляция
Раздел: Компьютер - Программирование - Компилятор GCC
Запись: xintrea/mytetra_syncro/master/base/0000000337/text.html на raw.github.com

Removing unused functions/dead code

I was just looking into this very thing! Do insert this in your Makefile...

--------8<--------

DEADCODESTRIP := -Wl,-static -fvtable-gc -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-s

foo : foo.c

g++ $(DEADCODESTRIP) $< -o $@

--------8<--------

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. (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.

HTH,

--Eljay

Так же в этом разделе:
 
MyTetra Share v.0.65
Яндекс индекс цитирования