简体   繁体   English

gcc在编译时或链接时的可见性

[英]gcc's fvisibility at compile time or link time

I am trying to limit the ABI of a shared library using the gcc's fvisibility feature. 我试图使用gcc的fvisibility功能限制共享库的ABI。 However I am confused what is the correct way to do it. 但是我很困惑,这是正确的方法。

My makefile organizes the build process in two stages. 我的makefile分两个阶段组织构建过程。 At the first step all .cpp files are built to object files using some gcc options. 在第一步,使用一些gcc选项将所有.cpp文件构建到目标文件。 Then all the object files are linked together using another set of gcc and ld options. 然后使用另一组gcc和ld选项将所有目标文件链接在一起。 From what I have read fvisibility is relevant to the second step. 从我所看到的可见性与第二步相关。 However this contradicts with the results I observer. 然而,这与我观察到的结果相矛盾。 If I add fvisibility=hidden to the compile time options the result is as expected, nm -D reporting a much smaller set of exported symbols. 如果我在编译时选项中添加fvisibility = hidden,结果是预期的,nm -D报告的导出符号集要小得多。 On the contrary if I add it to the link time options it does not seem to affect the build. 相反,如果我将它添加到链接时选项,它似乎不会影响构建。

While looking for an explanation I have compared the object files produced with and without fvisibility. 在寻找解释时,我已经比较了使用和不使用fvisibility生成的目标文件。 The difference seems to be in the addresses of the symbols inside the object file. 差异似乎在目标文件内的符号地址中。 However I am not aware how that difference in addresses carries the message to the linker so that it is able to hide the symbols in one of the cases and expose them in the other. 但是我不知道地址中的差异如何将消息传递给链接器,以便它能够隐藏其中一个案例中的符号并将它们暴露给另一个案例。

Could anyone please explain to me that. 任何人都可以向我解释一下。 Thank you for your time. 感谢您的时间。

您可能会发现http://gcc.gnu.org/wiki/Visibility非常有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM