<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Odd PC rel for thread local"
   href="https://bugs.llvm.org/show_bug.cgi?id=34306">34306</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Odd  PC rel for thread local
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>COFF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ck@remobjects.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>With latest llvm/lld on Win32 (link flavor) I get an odd PC rel for thread
local statics:

_GetCurrent:
  402000:       55      pushl   %ebp
  402001:       89 e5   movl    %esp, %ebp
  402003:       e8 00 00 00 00  calll   0 <_GetCurrent+0x8>
  402008:       58      popl    %eax
  402009:       8b 88 00 10 40 00       movl    4198400(%eax), %ecx
  40200f:       64 8b 80 2c 00 00 00    movl    %fs:44(%eax), %eax
  402016:       8b 04 88        movl    (%eax,%ecx,4), %eax
  402019:       8b 80 00 00 00 00       movl    (%eax), %eax
  40201f:       5d      popl    %ebp
  402020:       c3      retl

notice 402009, which does a movl 4198400 (_tls_index)%eax, %ecx, where %eax is
PC, this crashes here and I'm having trouble seeing how this would ever work
since 4198400 is already the real address.


Steps:
- llvm-as.exe isl.out.ll
- lld.exe -flavor link isl.out.bc /entry:main /debug  /opt:lldlto=0 /force

then disassemble it.

(Note that /force is only here for testcase purposes, it fails in a full
project without /force too)

Code:

; ModuleID = 'isl.out'
source_filename = "Island"
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
target triple = "i686-pc-windows-msvc"

module asm ".globl _tls_array\0D"
module asm "_tls_array = 44\0D"
module asm ".globl __tls_array\0D"
module asm "__tls_array = 44"

@_tls_index = global i32 0


@fCurrent = thread_local global i8* null

define i8* @GetCurrent() #0 {
  br label %1

; <label>:1:                                      ; preds = %0
  %2 = load i8*, i8** @fCurrent
  ret i8* %2
}

declare void @DoSomething(i8*)

define void @main() {
  %1 =  call i8* @GetCurrent()
  call void @DoSomething(i8* %1)
  ret void
}

attributes #0 = { "no-frame-pointer-elim"="true"
"no-frame-pointer-elim-non-leaf" }</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>