Hello,<br>        I am trying to use LLVM JIT to emit the following codes and execute both functions in my program, but<br><br>I get segmentation fault, the problem seems to originate from "thread_local" global variable.<br>
<br>my LLVM library is 3.1 and platform is x86 32bit , OS : Ubuntu 10.04<br><br><br>@0 = internal <span style="color:rgb(255,0,0)">thread_local</span> global i32 522, align 4<br><br>define void @setValue(i32 %v) {<br>  %1 = alloca i32, align 4<br>
  store i32 %v, i32* %1, align 4<br>  %2 = load i32* %1, align 4<br>  store i32 %2, i32* @0, align 4<br>  ret void<br>}<br><br>define i32 @getValue() {<br>  %1 = load i32* @0, align 4<br>  ret i32 %1<br>}<br><br><br><br><br>
I am wondering if LLVM JIT is able to emit machine codes with thread_local memory because in <br><br>lib/Target/X86/X86JITInfo.cpp, the following function is responsible for allocating thread memory for global variable.<br>
<br>It does not return an address, but an index.<br><br><br><pre><a id="L571" name="L571"><strong class="reserved">char</strong>* </a><a href="http://140.113.166.39/llvm-3.1.src/HTML/S/8340.html#L442" title="Defined at 442 in lib/Target/X86/X86JITInfo.cpp.">X86JITInfo</a>::<a href="http://140.113.166.39/llvm-3.1.src/HTML/R/13517.html" title="Multiple refered from 3 places.">allocateThreadLocalMemory</a>(<a href="http://140.113.166.39/llvm-3.1.src/HTML/D/21902.html" title="Multiple defined in 3 places.">size_t</a> <a href="http://140.113.166.39/llvm-3.1.src/HTML/Y/37476.html" title="Multiple used in 43 places.">size</a>) <em class="brace">{</em>
<em class="comment"><em class="position"></em></em>
<a id="L572" name="L572"> <em class="sharp">#if</em> <strong class="reserved">defined</strong>(</a><a href="http://140.113.166.39/llvm-3.1.src/HTML/Y/27302.html" title="Multiple used in 5 places.">X86_32_JIT</a>) && !<strong class="reserved">defined</strong>(<a href="http://140.113.166.39/llvm-3.1.src/HTML/Y/27623.html" title="Multiple used in 20 places.">__APPLE__</a>) && !<strong class="reserved">defined</strong>(<a href="http://140.113.166.39/llvm-3.1.src/HTML/Y/27566.html" title="Multiple used in 82 places.">_MSC_VER</a>)
<a id="L573" name="L573">   </a><a href="http://140.113.166.39/llvm-3.1.src/HTML/Y/23295.html" title="Multiple used in 4 places.">TLSOffset</a> -= <a href="http://140.113.166.39/llvm-3.1.src/HTML/D/21901.html" title="Multiple defined in 4 places.">size</a>;
<a id="L574" name="L574">   <strong class="reserved">return</strong> </a><a href="http://140.113.166.39/llvm-3.1.src/HTML/Y/23295.html" title="Multiple used in 4 places.">TLSOffset</a>;
<a id="L575" name="L575"> <em class="sharp">#else</em>
</a><a id="L576" name="L576">   </a><a href="http://140.113.166.39/llvm-3.1.src/HTML/D/20353.html" title="Multiple defined in 3 places.">llvm_unreachable</a>("Cannot allocate thread local storage on this arch!");
<a id="L577" name="L577"> <em class="sharp">#endif<br>}</em> </a><a id="L578" name="L578"><br><em class="brace"></em> <br><br>Consequently, if we set LLVM global variable G to be thread local, and use<br><br>jit to call getOrEmitGlobalVariable(G), we get an index, not address.<br>
<br>So what if we want to change the value in G, how can we do this.<br><br><br>Have A Nice Day<br>Chia Lun Liu<br></a></pre><h2 class="header"></h2><br><br><br><br>