Bug 20800 - BFD Linker failing (unresolvable R_X86_64_PLTOFF64) with -mcmodel=large and --start-group
Summary: BFD Linker failing (unresolvable R_X86_64_PLTOFF64) with -mcmodel=large and -...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.27
: P2 normal
Target Milestone: 2.28
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-09 21:49 UTC by Keno Fischer
Modified: 2016-11-15 21:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2016-11-10 00:00:00


Attachments
My test.o (556 bytes, application/x-object)
2016-11-11 21:07 UTC, Keno Fischer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Keno Fischer 2016-11-09 21:49:23 UTC
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
```
Comment 1 H.J. Lu 2016-11-10 22:34:41 UTC
I can't reproduce this on Fedora 24.
Comment 2 Keno Fischer 2016-11-10 22:37:24 UTC
This is on stock Ubuntu 16.10. Try adding `-fPIE` to the compile invocation maybe? I know Debian recently switched that on by default.
Comment 3 H.J. Lu 2016-11-11 15:38:59 UTC
(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]$
Comment 4 Keno Fischer 2016-11-11 21:07:10 UTC
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.
Comment 5 Keno Fischer 2016-11-11 21:07:26 UTC
Created attachment 9625 [details]
My test.o
Comment 6 H.J. Lu 2016-11-11 21:26:00 UTC
(In reply to Keno Fischer from comment #5)
> Created attachment 9625 [details]
> My test.o

Your test.o works for me.
Comment 7 H.J. Lu 2016-11-11 21:29:16 UTC
(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.
Comment 8 H.J. Lu 2016-11-14 16:01:01 UTC
[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]$
Comment 9 Sourceware Commits 2016-11-14 18:18:50 UTC
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.
Comment 10 H.J. Lu 2016-11-14 18:19:18 UTC
Fixed for 2.28.
Comment 11 Keno Fischer 2016-11-15 21:33:42 UTC
Awesome, thank you so much!