11

在我的 Ubuntu 9.04 机器上编译 webkit-1.1.5 包时,我在链接器阶段收到此错误:

libtool: link: gcc -ansi -fno-strict-aliasing -O2 -Wall -W -Wcast-align -Wchar-subscripts -Wreturn-type -Wformat -Wformat-security -Wno-format-y2k -Wundef -Wmissing-format-attribute -Wpointer-arith -Wwrite-strings -Wno-unused-parameter -Wno-parentheses -fno-exceptions -fvisibility=hidden -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libsoup-2.4 -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -g -O2 -O2 -o Programs/.libs/GtkLauncher WebKitTools/GtkLauncher/Programs_GtkLauncher-main.o -pthread  ./.libs/libwebkit-1.0.so /usr/lib/libgtk-x11-2.0.so /usr/lib/libgdk-x11-2.0.so /usr/lib/libatk-1.0.so /usr/lib/libpangoft2-1.0.so /usr/lib/libgdk_pixbuf-2.0.so -lm /usr/lib/libpangocairo-1.0.so /usr/lib/libgio-2.0.so /usr/lib/libcairo.so /usr/lib/libpango-1.0.so /usr/lib/libfreetype.so -lfontconfig /usr/lib/libgmodule-2.0.so /usr/lib/libgobject-2.0.so /usr/lib/libgthread-2.0.so -lrt /usr/lib/libglib-2.0.so -pthread
make[1]: Leaving directory `/home/nagul/build_area/webkit-1.1.5'
WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp: In function ‘NPError webkit_test_plugin_get_value(NPP_t*, NPPVariable, void*)’:
WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp:221: warning: deprecated conversion from string constant to ‘char*’
WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp:224: warning: deprecated conversion from string constant to ‘char*’
WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp: In function ‘char* NP_GetMIMEDescription()’:
WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/TestNetscapePlugin.cpp:260: warning: deprecated conversion from string constant to ‘char*’
/usr/bin/ld: Programs/.libs/GtkLauncher: hidden symbol `__stack_chk_fail_local' in /usr/lib/libc_nonshared.a(stack_chk_fail_local.oS) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[1]: *** [Programs/GtkLauncher] Error 1
make: *** [all] Error 2

我想要一些关于如何解决这个问题的指示,或者通过查看“隐藏的 sybmol”错误,或者帮助我理解来自链接器的“输出不可表示部分”消息的实际含义。

我已经检查过这是在make clean;make调用中持续存在的一致行为。

4

3 回答 3

8

在为 ARM 进行交叉编译时,我收到了“输出中不可表示的部分”错误,并且某些库未使用 -fPIC 正确编译。很确定这不是这里的错误......

于 2009-10-05T22:37:40.000 回答
7

我的答案是特定于hidden symbol (...) is referenced by DSONonrepresentable section on output错误的组合。

简短的回答是:一个符号被标记extern但也被标记为隐藏(参见可见性(GCC wiki)如何编写共享库(Ulrich Drepper))。没有链接任何对象或档案来满足依赖关系,但一个共享对象用匹配的符号链接的。

您可能使用 编译-fvisibility=hidden,无论它是编译器添加的功能(如堆栈保护器)还是完全其他的东西,代码中发出的符号覆盖了同名的未定义符号引用的默认可见性,libc_nonshared.a通常可以满足libc.so.

您可以重现类似的问题,如下所示:

#include <stdio.h>

extern __attribute__((visibility ("hidden")))
FILE* open_memstream( char**, size_t* );

char* asdf;
size_t mysize;

FILE* blah() {
  return open_memstream( &asdf, &mysize );
}

...然后编译它:

# with gcc 4.9.2:
~ gcc badcode.c -shared -fPIC -o libbad.so -lc
/tmp/ccC0uG80.o: In function `blah':
badcode.c:(.text+0x19): undefined reference to `open_memstream'
/usr/bin/ld: /tmp/libbad.so: hidden symbol `open_memstream' isn't defined
/usr/bin/ld: final link failed: Bad value

# with gcc 4.4.7:
~ gcc badcode.c -shared -fPIC -o libbad.so -lc
/tmp/cc2SHUFD.o: In function `blah':
badcode.c:(.text+0x26): undefined reference to `open_memstream'
/usr/bin/ld: /tmp/libbad.so: hidden symbol `open_memstream' isn't defined
/usr/bin/ld: final link failed: Nonrepresentable section on output

# with oracle solaris studio (still in Linux) 12.3:
~ cc -shared -Kpic -o /tmp/libbad.so badcode.c -lc
badcode.o: In function `blah':
badcode.c:(.text+0x32): undefined reference to `open_memstream'
/usr/bin/ld: /tmp/libbad.so: hidden symbol `open_memstream' isn't defined
/usr/bin/ld: final link failed: Nonrepresentable section on output

简而言之:我已经提前声明了符号的存在,将其标记为隐藏,然后没有链接到满足依赖关系的静态库或目标文件中。由于它被标记为隐藏,因此必须满足依赖关系,否则它是无效的 ELF 对象。

在我的具体情况下,标头走错了#if路,导致上述隐藏的open_memstream.

于 2015-10-07T22:28:12.790 回答
5

请尝试从命令行中删除 -fvisibility=hidden 选项。它会产生一个更大的对象(带有一些不必要的符号,这最终无关紧要,因为它是一个可执行文件),但应该消除这个问题。这不是解决方案;而是一种解决方法。如果库和 GtkLauncher.o 之间没有 libc 版本不匹配,请检查(这只是预感)

于 2009-11-21T10:29:26.727 回答