[llvm-dev] lld/win32 creates pic code for threadlocal
Carlo Kok via llvm-dev
llvm-dev at lists.llvm.org
Tue Aug 1 10:15:52 PDT 2017
(Forward as I sent it to the wrong list)
Hi,
With latest llvm/lld on Win32 (link flavor) I get an odd PC rel get:
I get:
_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. Am I missing
something obvious, or is this a bug? it doesn't happen with llc.
Steps:
- llvm-as.exe isl.out.ll
- lld.exe -flavor link isl.out.bc /entry:main /debug /opt:lldlto=0
/force
then disassemble it.
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" }
--
Carlo Kok
RemObjects Software
More information about the llvm-dev
mailing list