Bug 15685 - R_X86_64_DTPOFF64 incorrectly handled
Summary: R_X86_64_DTPOFF64 incorrectly handled
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-26 22:03 UTC by David Blaikie
Modified: 2022-11-24 10:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A patch (443 bytes, patch)
2013-06-27 19:18 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Blaikie 2013-06-26 22:03:06 UTC
Given the following simpl.s:

        .file   "simpl.c"
        .globl  thrd
        .section        .tdata,"awT",@progbits
        .align 4
        .type   thrd, @object
        .size   thrd, 4
thrd:
        .long   2
        .text
        .globl  func
        .type   func, @function
func:
        .byte 0x42
        .quad thrd@dtpoff
        .byte 0x42
        .long thrd@dtpoff
        .byte 0x42

Assembled with gas and then linked with gold produces:
00000e0 0004 0000 0000 0000 fc42 ffff ffff ffff
00000f0 42ff fffc ffff 0042 0002 0000 0004 0000

ie: fffffffffffffffc
            fffffffc

Whereas with binutils-ld:
00000e0 0004 0000 0000 0000 f842 6000 0000 0000
00000f0 4200 fffc ffff 0042 0002 0000 2e00 7973

ie: 00000000006000f8
            fffffffc
Comment 1 David Blaikie 2013-06-26 22:15:51 UTC
(this came up while implementing TLS debug info in Clang - it's possible that TLS support in Clang will use this relocation & thus be broken when using binutils-ld to link)
Comment 2 David Blaikie 2013-06-26 22:17:26 UTC
& I guess http://sourceware.org/ml/binutils/2002-09/msg00601.html might be relevant (mentions that this wasn't implemented way back in 2002, perhaps it's still just as unimplemented)
Comment 3 H.J. Lu 2013-06-27 18:59:08 UTC
(In reply to David Blaikie from comment #0)
> Given the following simpl.s:
> 
>         .file   "simpl.c"
>         .globl  thrd
>         .section        .tdata,"awT",@progbits
>         .align 4
>         .type   thrd, @object
>         .size   thrd, 4
> thrd:
>         .long   2
>         .text
>         .globl  func
>         .type   func, @function
> func:
>         .byte 0x42
>         .quad thrd@dtpoff
>         .byte 0x42
>         .long thrd@dtpoff
>         .byte 0x42
> 

This insn sequence isn't valid in text section. It can only appear
in debug section.
Comment 4 H.J. Lu 2013-06-27 19:18:31 UTC
Created attachment 7098 [details]
A patch

Please try this.
Comment 5 David Blaikie 2013-06-28 00:53:48 UTC
Apologies for the problematic reproduction - just trying to reduce this & accidentally dropped the debug_info section. Of course it does reproduce from within the debug_info section as well.

(In reply to H.J. Lu from comment #4)
> Created attachment 7098 [details]
> A patch
> 
> Please try this.

This patch works for me - once I fix a bug in LLVM regarding these very same relocations (for some reason Clang was assembling these as "R_X86_64_64       tls" instead of "R_X86_64_DTPOFF64  tls" yet Gold was somehow OK with that & seemed to give the right answer)
Comment 6 Sourceware Commits 2013-06-28 15:07:57 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2013-06-28 15:07:55

Modified files:
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-x86-64: tlsg.s tlsg.sd 
	bfd            : ChangeLog elf64-x86-64.c 

Log message:
	Handle R_X86_64_DTPOFF64
	
	bfd/
	
	PR ld/15685
	* elf64-x86-64.c (elf_x86_64_relocate_section): Handle
	R_X86_64_DTPOFF64.
	
	ld/testsuite/
	
	PR ld/15685
	* ld-x86-64/tlsg.s: Add a test for R_X86_64_DTPOFF64.
	* ld-x86-64/tlsg.sd: Updated.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1732&r2=1.1733
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/tlsg.s.diff?cvsroot=src&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/tlsg.sd.diff?cvsroot=src&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.6089&r2=1.6090
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf64-x86-64.c.diff?cvsroot=src&r1=1.297&r2=1.298
Comment 7 Alan Modra 2022-11-24 10:39:38 UTC
.