关于 DSO 引用隐藏符号的警告到底意味着什么?

What does exactly the warning mean about hidden symbol being referenced by DSO?(关于 DSO 引用隐藏符号的警告到底意味着什么?)

本文介绍了关于 DSO 引用隐藏符号的警告到底意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将某些共享库与 g++ 链接时遇到问题.它给了我一个警告,例如:

I have a problem linking some shared library with g++. It gives me a warning like:

hidden symbol XXX in YYY is referenced by DSO /usr/lib/...

我已经阅读了一些关于特定问题的相关问题,但我想整体理解它——这个警告是什么意思,原因是什么:

I've read some related questions about particular problems, but I want to understand it in a whole - what does this warning mean and what is a cause:

  1. 什么是 DSO?
  2. 什么是隐藏符号?
  3. 如果隐藏了,如何引用?

推荐答案

什么是 DSO?

DSO 是一个动态共享对象,或者不太正式的 共享库.

A DSO is a Dynamic Shared Object, or less formally a shared library.

什么是隐藏符号?

隐藏符号是一个符号(即函数或数据对象的名称)已使用隐藏链接编译,例如根据(特定于 GCC)声明:

A hidden symbol is a symbol (i.e. name of function or data object) that has been compiled with hidden linkage, e.g. as per the (GCC specific) declaration:

int x __attribute__ ((visibility ("hidden")));

如果在一个 DSO 中定义了 x,则动态链接不能从一个 DSO 中引用它不同的 DSO.链接器可以看到x(不是static),但不是可用于动态链接.文档这里

If x is defined in one DSO then dynamic linkage cannot reference it from a different DSO. The linker can see x (it is not static), but it is not available for dynamic linkage. Documentation here

如果隐藏了怎么引用?

不可能,这是你被警告的.例如.链接时警告:

It can't be, which is what you are being warned about. E.g. the linktime warning:

/usr/lib/libc_nonshared.a(stat.oS) 中的隐藏符号 `stat' 被 DSO 引用

hidden symbol `stat' in /usr/lib/libc_nonshared.a(stat.oS) is referenced by DSO

告诉您链接中的 DSO 引用了符号 stat,并且链接器可以在 /usr/lib/libc_nonshared.a 中找到 stat 的定义,但是(显然)该定义不在引用它的 DSO 中并且无法从该 DSO 中引用,因为它是隐藏的.

is telling you that a DSO in the linkage references the symbol stat, and the linker can locate a definition of stat in /usr/lib/libc_nonshared.a, but (obviously) that definition is not in the DSO that references it and cannot be referenced from that DSO, because it is hidden.

如果问题 DSO 未正确构建以供使用,则会出现此问题作为 DSO.参见这个例子并跟进解决方案.

You get this problem if the problem DSO has not been built correctly for use as a DSO. See this example and follow the follow-ups for the solution.

继续 OP 的跟进

如果某个 DSO 已经引用了隐藏符号,那么为什么 DSO 会出现问题?

If hidden symbol is already referenced by some DSO, then why the problem is with DSO?

链接器说:

DSO X 包含对符号 S 的引用.我可以找到符号S的定义是另一个链接模块Y,但是该定义将无法满足 X dynamically 中的引用(即 在运行时),因为 S 具有Y 中的隐藏链接.

The DSO X contains a reference to symbol S. I can find a definition of symbol S is another linked module Y, but that definition will not be available to satisfy the reference in X dynamically (i.e. at runtime) because S has hidden linkage in Y.

我可以确认问题出在非共享对象 [...][但] 我没有在我的非共享对象中明确隐藏这些符号.

I can confirm that the problem comes with a non-shared object [...][but] I don't explicitly hide those symbols in my non-shared object.

您可能没有明确标记非共享对象中隐藏的任何符号.根据它的构建方式,符号默认情况下可能隐藏,除非明确标记否则.

You may not have explicitly marked any symbols hidden in the non-shared object. Depending on how it was built, symbols may be hidden by default unless explicitly marked otherwise.

假设非共享对象是libnonshared.a,据称隐藏的符号是foo.运行:

Say the non-shared object is libnonshared.a and the allegedly hidden symbol is foo. Run:

objdump -t libnonshared.a

获取有关 libnonshared.a 中符号的信息.在输出中,查找 foo 的条目.它是否包含标签 .hidden?- 例如

to get info about the symbols in libnonshared.a. In the output, look for the entry for foo. Does it contain the tag .hidden? - e.g.

0000000000000000 g     F .text  000000000000000b .hidden foo

这个条目说 foo 是一个全局符号(标记为 g - 这就是链接器能够看到它的原因)但是它是隐藏的用于动态链接.

This entry says that foo is a global symbol (marked g - that's why the linker is able to see it) but it's hidden for dynamic linkage.

如果是这种情况,那么您需要修复 libnonshared.a 的构建,以便它不会隐藏 foo.如果没有,那我就难住了.

If this turns out to be the case then you need to go and fix the build of libnonshared.a so that it doesn't hide foo. If not, then I'm stumped.

这篇关于关于 DSO 引用隐藏符号的警告到底意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:关于 DSO 引用隐藏符号的警告到底意味着什么?

基础教程推荐