DSO正在引用的隐藏符号的警告是什么意思? [英] What does exactly the warning mean about hidden symbol being referenced by DSO?

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

问题描述

我有一个链接一些共享库与g ++的问题。它给我一个警告,如:

 隐藏的符号XXX在YYY由DSO / usr / lib / ...引用

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


  1. 什么是DSO?

  2. 什么是隐藏


解决方案

什么是DSO?



或更低版本的 共享库 。 / p>

什么是隐藏符号?



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

  int x __attribute__((visibility(hidden)) ; 

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



如果它被隐藏,如何引用?



它不能被引用,这是你被警告的。例如。 linktime警告:


隐藏符号/ stat / in /usr/lib/libc_nonshared.a(stat.oS)由DSO


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



这个问题如果问题DSO没有正确建立使用
作为DSO。请参见此示例
并按照解决方案的后续操作。



继续执行OP的后续操作


由一些DSO引用,那么为什么问题是与DSO?


链接器说:



DSO X 包含对符号 S 的引用。我可以找到符号 S的定义是另一个链接模块 Y
,但该定义不会可动态地满足 X )的引用,因为 code>在 Y 中有隐藏的连结。


...



$ b。这是一个非共享的对象[...] $ b

您可能没有明确标记隐藏在非共享对象中的任何符号。根据其构建方式,符号
可以默认隐藏,除非明确标记为否则



说非共享对象是 libnonshared.a ,据称隐藏的符号是 foo 。执行:

  objdump -t libnonshared.a 

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

  0000000000000000 g F .text 000000000000000b .hidden foo 

此条目表示 foo 是一个全局符号(标记为 g - 这就是为什么链接器能够看到它) 原来是这样的情况下,你需要去修复 libnonshared.a 的构建,以便它不隐藏 foo
如果没有,那么我很难受。


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. What is DSO?
  2. What is a hidden symbol?
  3. How can it be referenced, if it's hidden?

解决方案

What is a DSO?

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

What is a hidden symbol?

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")));

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

How can it be referenced, if it's hidden?

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

hidden symbol `stat' in /usr/lib/libc_nonshared.a(stat.oS) is referenced by 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.

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.

Continued for OP's followups

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

The linker is saying:

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.

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

objdump -t libnonshared.a

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

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.

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正在引用的隐藏符号的警告是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆