使用弱符号时如何避免对 GLIBC_X.Y 的依赖
在 Hurd 中进行信号实现时,我遇到了以下问题。
基本上,我向 glibc 添加了一个新函数,该函数由 libpthread 使用(这些函数来自 Hurd 上的不同来源)。为了让新的 libpthread 仍然可以与旧的 glibc 一起工作,我在 libpthread 代码中将新函数声明为弱符号。 (请参阅补丁此处。
)是用较旧的 glibc 构建的,一切都按预期工作。 然而,当构建时在 glibc 中实际找到该符号时, 链接器发出与新符号版本相对应的“VERNEED” 使用较旧的 glibc 运行会产生:
foo: ./libc.so.0.3: version `GLIBC_X.Y' not found
(required by /lib/libpthread.so.0.3)
其中 GLIBC_X.Y 是新引入的符号的版本。
我正在寻找的结果是新符号为 NULL 当 glibc 没有它时, 这就是我使用较旧的 glibc 构建 libpthread 时发生的情况。
知道如何解决这个问题吗? 链接 libpthread 时可以禁止符号的版本控制吗?
While working on the signal implementation in Hurd, I have run into the following problem.
Basically, I add a new function to glibc, which is used by libpthread (those are from separate sources on Hurd). In order for the new libpthread to still work with older glibc's, I declare the new function as a weak symbol in the libpthread code. (See the patch here.)
When libpthread is built with an older glibc, everything works as indended.
However, when the symbol is actually found in glibc at build time,
the linker emits a "VERNEED" corresponding to the new symbol's version
and running with an older glibc results in:
foo: ./libc.so.0.3: version `GLIBC_X.Y' not found
(required by /lib/libpthread.so.0.3)
where GLIBC_X.Y is the version for the newly introduced symbol.
The result I'm looking for is for the new symbol to be NULL
when glibc doesn't have it,
which is what happens when I build libpthread with an older glibc.
Any idea how to fix this?
Can I inhibit versionning for my symbol when linking libpthread?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我对默认实现使用了弱别名
与
NULL
相比,它不仅仅是一个弱符号,出于某种原因事实证明
链接时符号版本不会从 glibc 中拉取。
So I used a weak alias to a default implementation
instead of just a weak symbol compared to
NULL
,and for some reason it turns out
the symbol version is not pulled in from glibc at link time.