[LLVMbugs] [Bug 17562] New: R_X86_64_TPOFF64 shows up in an invalid place

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Oct 13 02:42:49 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=17562

            Bug ID: 17562
           Summary: R_X86_64_TPOFF64 shows up in an invalid place
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: nlewycky at google.com
                CC: llvmbugs at cs.uiuc.edu, rafael.espindola at gmail.com
    Classification: Unclassified

C testcase:

  __thread int obj;

  int test() {
    return ((int)&obj) > 0;
  }

The assembly for this produced by clang -O2 is:

# BB#0:                                 # %entry
        movabsq $obj at TPOFF, %rax
        movq    %fs:0, %rcx
        addl    %eax, %ecx
        testl   %ecx, %ecx

while the assembly produced by gcc -O2 is:

.LFB0:
        .cfi_startproc
        movq    %fs:0, %rax
        addq    $obj at tpoff, %rax
        testl   %eax, %eax

I'll admit it's subtle, but that's a 32-bit immediate on the addq (addq will
sign extend to 64 bits if you give it a mere 32-bit immediate). This is
important because the ABI does not permit an R_X86_64_TPOFF64 relocation here,
that may only be used in conjunction with a GOT lookup:

  "R_X86_64_TPOFF64 and R_X86_64_TPOFF32 resolve to the offset from
the thread pointer to a thread-local variable. The former is generated in
response
to R_X86_64_GOTTPOFF, that resolves to a PC-relative address of a GOT entry
containing such a 64-bit offset." - amd64 psABI 0.99.6

and the linker (gold) does indeed check this:

ld: error: y.o: unexpected reloc 18 in object file
y.o:y5.c:function test: error: unexpected reloc 18 in object file

when compiling the clang-produced .o file, but not the gcc-produced .o file.
(To be clear, this is not an error in the MC layer.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131013/7090a8ee/attachment.html>


More information about the llvm-bugs mailing list