Cygwin:为什么 libc.a 中的 POSIX 符号是强符号?
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.