链接到libcurl时,_end符号消失 [英] _end symbol disappears when linking to libcurl

查看:124
本文介绍了链接到libcurl时,_end符号消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,D运行时库在确定GC根范围(man 3 end)时依靠_end符号,这实际上与Boehm GC的行为非常相似.但是,在libcurl中链接时,链接器不再找到该符号:

On Linux, the D runtime library relies on the _end symbol in determining the GC root ranges (man 3 end), which is in fact very similar to what the Boehm GC does. However, when linking in libcurl, the symbol is no longer found by the linker:

$ cat test.c
#include <stdio.h>

extern char _end[];
int main() {
    printf("%p\n", &_end);
    return 0;
}

$ gcc test.c # works
$ gcc test.c -lcurl
/usr/bin/ld: /tmp/ccOPtbEv.o: undefined reference to symbol '_end'
/usr/bin/ld: note: '_end' is defined in DSO /usr/lib/libssl.so.1.0.0 so try adding it to the linker command line
/usr/lib/libssl.so.1.0.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

通过在D论坛上的快速搜索,libpq,libdw和其他几个库似乎触发了相同的问题.知道这里会发生什么吗? test.c甚至都不依赖libcurl中的符号.(Arch Linux x86_64,GCC 4.7.2,ld 2.23)

From a quick search on the D forums, libpq, libdw and several other libraries seem to trigger the same problem. Any idea what could be happening here? test.c doesn't even depend on symbols from libcurl. (Arch Linux x86_64, GCC 4.7.2, ld 2.23)

另外,请注意,»尝试链接libssl«不是我要的答案,我想了解这里发生的情况.我正在尝试在正在使用的编译器中解决此问题,因此您可以假定基本熟悉链接过程的工作原理.

Also, please note that »try linking in libssl« is not the answer I am looking for, I want to understand what is happening here. I'm trying to fix this problem in a compiler I'm working on, so you can assume basic familiarity with how the linking process works.

我对告诉用户仅链接libssl并不特别满意,原因是pkg-config --libs curlcurl-config --libs等不包含此信息.要求它会因此破坏构建系统.如果有人对确定数据段的边界(初始化的和BSS的)有更好的主意,我很想知道.

The reason why I'm not particularly satisfied with telling the users to just link in libssl, ..., explicitly is that pkg-config --libs curl, curl-config --libs, etc. don't contain this information; requiring it would thus break build systems. If anyone has a better idea for determining the bounds of the data (initialized and BSS) segments, I'd be keen to know.

使用上述工具链,似乎也定义了end(不带下划线),并且不会触发问题.不过,仍然不清楚为什么会发生这种情况.

Edit 2: With the toolchain mentioned above, end (without the underscore) also seems to be defined, and it doesn't trigger the problem. Still baffled as to why it occurs, though.

推荐答案

_end符号由链接器提供.它指向bss中的最后一个对象.但是,这只是一个约定,没有任何标准要求这样做.您的工具链的链接器显然没有执行此操作.

_end symbol is provided by linker. It points past the last object in bss. However, it's just a convention, no standard requires this. Your toolchain's linker doesn't do that, apparently.

这篇关于链接到libcurl时,_end符号消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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