[LLVMdev] JIT problem with thread local global variable

劉家倫 bendog0224 at gmail.com
Mon Sep 24 05:44:39 PDT 2012


Hello,
        I am trying to use LLVM JIT to emit the following codes and execute
both functions in my program, but

I get segmentation fault, the problem seems to originate from
"thread_local" global variable.

my LLVM library is 3.1 and platform is x86 32bit , OS : Ubuntu 10.04


@0 = internal thread_local global i32 522, align 4

define void @setValue(i32 %v) {
  %1 = alloca i32, align 4
  store i32 %v, i32* %1, align 4
  %2 = load i32* %1, align 4
  store i32 %2, i32* @0, align 4
  ret void
}

define i32 @getValue() {
  %1 = load i32* @0, align 4
  ret i32 %1
}




I am wondering if LLVM JIT is able to emit machine codes with thread_local
memory because in

lib/Target/X86/X86JITInfo.cpp, the following function is responsible for
allocating thread memory for global variable.

It does not return an address, but an index.


*char** X86JITInfo
<http://140.113.166.39/llvm-3.1.src/HTML/S/8340.html#L442>::allocateThreadLocalMemory
<http://140.113.166.39/llvm-3.1.src/HTML/R/13517.html>(size_t
<http://140.113.166.39/llvm-3.1.src/HTML/D/21902.html> size
<http://140.113.166.39/llvm-3.1.src/HTML/Y/37476.html>) *{*** *#if*
*defined*(X86_32_JIT
<http://140.113.166.39/llvm-3.1.src/HTML/Y/27302.html>) &&
!*defined*(__APPLE__
<http://140.113.166.39/llvm-3.1.src/HTML/Y/27623.html>) &&
!*defined*(_MSC_VER
<http://140.113.166.39/llvm-3.1.src/HTML/Y/27566.html>)   TLSOffset
<http://140.113.166.39/llvm-3.1.src/HTML/Y/23295.html> -= size
<http://140.113.166.39/llvm-3.1.src/HTML/D/21901.html>;   *return*
TLSOffset <http://140.113.166.39/llvm-3.1.src/HTML/Y/23295.html>;
*#else*   llvm_unreachable
<http://140.113.166.39/llvm-3.1.src/HTML/D/20353.html>("Cannot
allocate thread local storage on this arch!"); *#endif
}*
**

Consequently, if we set LLVM global variable G to be thread local, and use

jit to call getOrEmitGlobalVariable(G), we get an index, not address.

So what if we want to change the value in G, how can we do this.


Have A Nice Day
Chia Lun Liu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120924/c8352e10/attachment.html>


More information about the llvm-dev mailing list