[LLVMdev] JIT problem with thread local global variable

Duncan Sands baldrick at free.fr
Mon Sep 24 09:50:20 PDT 2012


Hi,

>          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

try passing -use-mcjit to lli.  The old JIT implementation didn't support thread
local variables, while the new implementation (turned on by -use-mcjit) does.

Ciao, Duncan.

>
>
> @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
>
>
>
>
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list