“Nonrepresentable section on output” error during linking on linux

六月ゝ 毕业季﹏ 提交于 2019-11-30 09:00:52

I've received the "nonrepresentable section on output" error when crosscompiling for ARM and some of the libraries was not correctly compiled with -fPIC. Pretty sure that's not the error here though...

My answer is specific to the combination of the hidden symbol (...) is referenced by DSO and Nonrepresentable section on output errors.

The short answer is: a symbol was marked extern but also marked hidden (see Visibility (GCC wiki) and How To Write Shared Libraries (Ulrich Drepper)). No objects or archives were linked in to satisfy the dependency, but a shared object was linked in with a matching symbol.

You probably compiled with -fvisibility=hidden, and whether it was a compiler-added feature (like stack protector) or something else entirely, the symbol emitted in your code overrode the default visibility of an undefined symbol reference of the same name in libc_nonshared.a that would normally be satisfied by libc.so.

You can reproduce a similar problem like this:

#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 );
}

... then compiling it:

# 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

In short: I've forward declared the existence of a symbol, marked it hidden, then didn't link in a static library or object file that satisfied the dependency. Since it's marked hidden, the dependency must be satisfied, otherwise it's an invalid ELF object.

In my specific case, a header was going down the wrong #if path and causing the above hidden declaration of open_memstream.

Please try removing the -fvisibility=hidden option from the commandline. It will produce a larger object (with some unnecessary symbols, which won't matter in the end because it is an execultable), but should eliminate the problem. This is not a solution; rather a workaround. Please check (this is just a hunch) if there are no libc version mismatches between libraries and GtkLauncher.o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!