共有ライブラリにコンパイルし、未使用のコードをすべて削除する必要があるコードがありますが、適切な解決策が見つかりません。簡単な例を次に示します。
// test.cpp, compiled with GCC -fPIC -shared -fvisibility=hidden
#include <stdio.h>
class Foo {
    void bar();
};
void Foo::bar() { printf("hello"); } // unused and should be removed
// I'm using printf("hello") so I can detect the symbols with `strings`
__attribute__((visibility("default"))) void test() {} // this function is "used"
-fvisibility=hiddenすべての関数がデフォルトで非表示になるようにし、パブリック関数を手動で__attribute__((visibility("default"))). ただし、非表示の関数は、としてマークされていない限り削除されstaticません (明らかに、C++ メソッドに対してはできません)。
私が何をしようとも、GCC は常に維持void Foo::bar()さhelloれます。コンパイラをハッキングせずにこれらのシンボルを削除する方法はありますか? (はい、現時点で検討中です!)
ありがとう!