https://sourceware.org/bugzilla/show_bug.cgi?id=19805
H.J. Lu <hjl.tools at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |WAITING CC| |hjl.tools at gmail dot com --- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Felix von Leitner from comment #0) > Problem 1: > > /usr/bin/ld: > /hdd/home/leitner/projects/dietlibc-0.32/bin-x86_64/dietlibc.a(perror.o): > relocation R_X86_64_PC32 against symbol `sys_errlist' can not be used when > making a shared object; recompile with -fPIC > > This code was already compiled with -fPIC. You can actually tell from the > relocation, it is PC-relative, i.e. position independent. > > $ nm bin-x86_64/dietlibc.a | grep sys_errlist > 0000000000000000 R sys_errlist > U sys_errlist > U sys_errlist > > so the symbol is being exported, and somebody else is using it with a PIC > reference. ld should not be refusing to do this. Never use nm to report linker issue since it doesn't provide complete info. Please show me "readelf -sWr bin-x86_64/dietlibc.a | grep sys_errlist" and provide complete linker command line. > Note that I compiled all the code with -fvisibility=hidden, and I am also > passing that flag to gcc when creating the "shared library" PIE binary here, > to make sure the reference is resolved internally. > > I know that gcc is telling ld about the visibility, because calls are doing > directly (as opposed to through the PLT). > > Problem 2: .a vs loose object files: > > $ gcc -nostdlib -shared -L/opt/diet/lib-x86_64 > /opt/diet/lib-x86_64/start-pie.o -fpie -fvisibility=hidden -o y c.o d.o > -isystem /opt/diet/include -D__dietlibc__ /opt/diet/lib-x86_64/libc.a -lgcc > > -> works, produces a working binary. > > $ ar cru x.a c.o d.o > $ gcc -nostdlib -shared -L/opt/diet/lib-x86_64 > /opt/diet/lib-x86_64/start-pie.o -fpie -fvisibility=hidden -o y x.a -isystem > /opt/diet/include -D__dietlibc__ /opt/diet/lib-x86_64/libc.a -lgcc > /opt/diet/lib-x86_64/libc.a(stackgap-pie.o): In function `stackgap_pie': > stackgap-pie.c:(.text+0x39b): undefined reference to `main' > /usr/bin/ld: y: hidden symbol `main' isn't defined > /usr/bin/ld: final link failed: Bad value > collect2: error: ld returned 1 exit status > $ nm x.a > [...] > d.o: > U _GLOBAL_OFFSET_TABLE_ > U __you_tried_to_link_a_dietlibc_object_against_glibc > U foo > 0000000000000000 T main > U puts Please place x.a and libc.a between --start-group and --end-group. -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils