c++ - How to remove *ALL* unused symbols from a shared library? -
i have code need compile shared library , remove unused code from, can't find proper solution. here simple example:
// test.cpp, compiled gcc -fpic -shared -fvisibility=hidden #include <stdio.h> class foo { void bar(); }; void foo::bar() { printf("hello"); } // unused , should removed // i'm using printf("hello") can detect symbols `strings` __attribute__((visibility("default"))) void test() {} // function "used"
-fvisibility=hidden
makes functions hidden default, , manually mark public functions __attribute__((visibility("default")))
. however, hidden functions not removed unless marked static
(which can't c++ methods, obviously).
no matter do, gcc keep void foo::bar()
, hello
around. there way remove these symbols without hacking compiler? (yes, considering @ point!)
thanks!
compile flag -ffunction-sections
. link -wl,--gc-sections
. think can achieved lto, i'm not sure of details.
note public symbols in dylib considered live. hidden symbols stripped way.
Comments
Post a Comment