<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - R_X86_64_TPOFF64 shows up in an invalid place"
   href="http://llvm.org/bugs/show_bug.cgi?id=17562">17562</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>R_X86_64_TPOFF64 shows up in an invalid place
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nlewycky@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, rafael.espindola@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>