Cygwin:为什么 libc.a 中的 POSIX 符号是强符号?

发布于 2025-01-15 17:46:50 字数 967 浏览 3 评论 0原文

在 Cygwin 上,libc.a 中的 POSIX 符号是强符号(例如 accept):

$ nm /usr/lib/libc.a | grep 'accept' -w
0000000000000000 T accept

在 Linux 上,它们是弱符号(例如 accept):

$ nm /usr/lib/x86_64-linux-gnu/libc.a |& grep 'accept' -w
accept.o:
0000000000000000 W accept
                 U accept
                 U accept
                 U accept
                 U accept

而 :libc.a 中包含 POSIX 符号可能有点意外。

但是,为什么在 Cygwin 的 libc.a 中,POSIX 符号是符号?

示例:如果用户的 mylib.a 包含 accept 的定义,并且 mylib.a 位于之后 < code>libc.a 位于命令行参数列表中,则可以(并且通常是)选择 libc.a 中的 accept


UPD。 https://stackoverflow.com/a/2290838/1778275

MSVC++ 有__declspec(selectany),它涵盖了弱符号的部分功能。

On Cygwin POSIX symbols in libc.a are strong symbols (e.g. accept):

$ nm /usr/lib/libc.a | grep 'accept' -w
0000000000000000 T accept

while on Linux they are weak symbols (e.g. accept):

$ nm /usr/lib/x86_64-linux-gnu/libc.a |& grep 'accept' -w
accept.o:
0000000000000000 W accept
                 U accept
                 U accept
                 U accept
                 U accept

Note: having POSIX symbols in libc.a may be a bit unexpected.

However, why in Cygwin's libc.a POSIX symbols are strong symbols?

Example: If user has mylib.a containing the definition of accept and the mylib.a goes after the libc.a in the list of command line arguments, then the accept from the libc.a may be (and usually is) selected.


UPD. https://stackoverflow.com/a/2290838/1778275:

MSVC++ has __declspec(selectany) which covers part of the functionality of weak symbols.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然 2025-01-22 17:46:50

https://en.wikipedia.org/wiki/Weak_symbol

COFF 上不提供弱符号PE 二进制。
这也是所有符号必须在编译时定义的原因之一。

https://en.wikipedia.org/wiki/Weak_symbol

Weak Symbol are not available on COFF PE binary.
It is also one of the reason why all symbols must be defined at compilation time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文