小编use*_*514的帖子

如何从共享库中删除*ALL*未使用的符号?

我有一个代码,我需要编译到共享库并删除所有未使用的代码,但我找不到合适的解决方案.这是一个简单的例子:

// 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"
Run Code Online (Sandbox Code Playgroud)

-fvisibility=hidden使它默认隐藏所有函数,并手动标记公共函数__attribute__((visibility("default"))).但是,除非标记为隐藏函数,否则不会删除隐藏函数static(显然,我无法对C++方法执行此操作).

无论我做什么,海湾合作委员会将始终保持void Foo::bar()hello周围.有没有办法在不破坏编译器的情况下删除这些符号?(是的,我现在正在考虑它!)

谢谢!

c c++ shared-libraries

3
推荐指数
1
解决办法
2011
查看次数

标签 统计

c ×1

c++ ×1

shared-libraries ×1