[LLVMdev] JIT problem with thread local global variable

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

        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
<> size
<>) *{*** *#if*
<>) &&
<>) &&
<>)   TLSOffset
<> -= size
<>;   *return*
TLSOffset <>;
*#else*   llvm_unreachable
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