Reduced from UML Linux Kernel build. ld.bfd fails with the following error, ld.gold seems to work fine: ``` keno@anubis:~/linkerbug$ cat test.c #include <stdio.h> int main(void) { printf("Hello World"); } keno@anubis:~/linkerbug$ gcc -shared -mcmodel=large -fno-builtin -c test.c keno@anubis:~/linkerbug$ gcc -Wl,-rpath,/lib64 -m64 -Wl,--start-group test.o -Wl,--end-group /usr/bin/ld: test.o(.text+0x36): unresolvable R_X86_64_PLTOFF64 relocation against symbol `printf@@GLIBC_2.2.5' /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status keno@anubis:~/linkerbug$ sudo cp -a /usr/bin/ld.gold /usr/bin/ld keno@anubis:~/linkerbug$ gcc -Wl,-rpath,/lib64 -m64 -Wl,--start-group test.o -Wl,--end-group keno@anubis:~/linkerbug$ #worked ```
I can't reproduce this on Fedora 24.
This is on stock Ubuntu 16.10. Try adding `-fPIE` to the compile invocation maybe? I know Debian recently switched that on by default.
(In reply to Keno Fischer from comment #2) > This is on stock Ubuntu 16.10. Try adding `-fPIE` to the compile invocation > maybe? I know Debian recently switched that on by default. Works for me: [hjl@gnu-6 pr20800]$ cat test.c #include <stdio.h> int main(void) { printf("Hello World"); return 0; } [hjl@gnu-6 pr20800]$ gcc -shared -mcmodel=large -fno-builtin -c test.c -fPIE [hjl@gnu-6 pr20800]$ gcc -Wl,-rpath,/lib64 -m64 -Wl,--start-group test.o -Wl,--end-group -pie [hjl@gnu-6 pr20800]$
Attaching my test.o here. Maybe it's a compiler problem. What version of ld are you using? Maybe it's already fixed? I have: ``` ld --version GNU ld (GNU Binutils for Ubuntu) 2.27 Copyright (C) 2016 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. ``` I'd also be happy to give you SSH access to this machine.
Created attachment 9625 [details] My test.o
(In reply to Keno Fischer from comment #5) > Created attachment 9625 [details] > My test.o Your test.o works for me.
(In reply to Keno Fischer from comment #4) > ``` > I'd also be happy to give you SSH access to this machine. I sent you my ssh key.
[hjl@gnu-6 pr20800]$ cat test.c #include <stdio.h> int main(void) { printf("Hello World"); return 0; } [hjl@gnu-6 pr20800]$ gcc -fpie -mcmodel=large -fno-builtin test.c [hjl@gnu-6 pr20800]$ gcc -pie test.o -Wl,-z,now /usr/local/bin/ld: test.o(.text+0x36): unresolvable R_X86_64_PLTOFF64 relocation against symbol `printf@@GLIBC_2.2.5' /usr/local/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status [hjl@gnu-6 pr20800]$
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9d734efa1034d266249751978f95a686ec9d19c6 commit 9d734efa1034d266249751978f95a686ec9d19c6 Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Nov 14 10:13:03 2016 -0800 Also check GOT PLT for R_X86_64_PLTOFF64 Since "-z now" replaces PLT with GOT PLT, we should also check GOT PLT for R_X86_64_PLTOFF64 relocation. bfd/ PR ld/20800 * elf64-x86-64.c (elf_x86_64_relocate_section): Also check plt_got.offset for R_X86_64_PLTOFF64. ld/ PR ld/20800 * testsuite/ld-x86-64/pr20800a.S: New file. * testsuite/ld-x86-64/pr20800b.S: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run PR ld/20800 test.
Fixed for 2.28.
Awesome, thank you so much!