我最近在GNU ld中发现了链接器选项“-Bsymbolic-functions”:
-Bsymbolic
When creating a shared library, bind references to global symbols to the
definition within the shared library, if any. Normally, it is possible
for a program linked against a shared library to override the definition
within the shared library.
This option is only meaningful on ELF platforms which support shared libraries.
-Bsymbolic-functions
When creating a shared library, bind references to global function symbols
to the definition within the shared library, if any.
This option is only meaningful on ELF platforms which support shared libraries.
这似乎与GCC选项
-fvisibility=hidden
相反,因为它阻止了该函数的库内部引用绑定(bind)到另一个共享对象的导出函数,而不是阻止将引用的函数导出到其他共享对象。 。我告诉自己,-Bsymbolic-functions
将阻止为函数创建PLT条目,这是一个很好的副作用。-Bsymbolic
。 -Bsymbolic-functions
的任何陷阱?我打算只使用它,因为-Bsymbolic
会打破异常,我认为(这样做会使对typeinfo对象的引用不统一)。 谢谢!
最佳答案
回答我自己的问题,因为我刚刚为此获得了风滚草徽章...后来我发现了
是的,有一个--dynamic-list
选项可以做到这一点
我仔细研究了一下,似乎没有问题。 libstdc++库显然是这样做的,或者至少是考虑过的,他们只需要添加--dynamic-list-cpp-new
即可使operator new
统一(以防止程序中多个分配器/解除分配器混合在一起的问题,但我认为这样的程序还是被破坏了)。 Ubuntu使用它或默认使用它,似乎它与某些软件包引起冲突。但是总的来说,它应该能很好地工作。
关于linker - 使用-Bsymbolic-functions有不利之处吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7216973/