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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    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@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@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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to