Fellow developers,<br><br>I'm parallelizing loops to be called by pthread. The thread body that I pass to pthread_create looks like<br><br>define i8* @loop1({ i32*, i32* }* nest %parent_frame, i8* %arg) parent_frame is pointer to shared variables in original function<br>
<br>0x00007f0de11c41f0: mov (%r10),%rax<br>0x00007f0de11c41f3: cmpl $0x63,(%rax)<br>0x00007f0de11c41f6: jg 0x7f0de11c420c<br>0x00007f0de11c41fc: mov 0x8(%r10),%rax<br>0x00007f0de11c4200: incl (%rax)<br>
0x00007f0de11c4202: mov (%r10),%rax<br>0x00007f0de11c4205: incl (%rax)<br>0x00007f0de11c4207: jmpq 0x7f0de11c41f0<br>0x00007f0de11c420c: xor %rax,%rax<br>0x00007f0de11c420f: retq<br><br>I use init_trampoline to generate code that sets up the static link:<br>
<br>0x00007fffee982316: mov $0x7f48e1a08fb0,%r11<br>0x00007fffee982320: mov $0x7fffee982330,%r10 the static link<br>0x00007fffee98232a: rex.WB jmpq *%r11<br><br>The program crashes in loop1 on the 2nd instruction. r10, which contained the static link was different from the value set by the trampoline.<br>
<br>Upon closer inspection, it looks like the trampoline first jumps to a stub that compiles loop1:<br><br>0x00007f48e1a08fb0: mov $0x5c61c0,%r10 <br>0x00007f48e1a08fba: callq *%r10 <br>
0x00007f48e1a08fbd: int $0x0<br><br>But that clobbers r10 which loop1 needs. According to the x86-64 ABI, r10 isn't preserved across functions, but here it needs to be. Is there anyway<br>to force LLVM to do that? I tried telling lli to compile the entire program (-no-lazy) so that the stub won't be generated, but gives the error:<br>
<br>LLVM JIT requested to do lazy compilation of function '_Z41__static_initialization_and_destruction_0ii' when lazy compiles are disabled!<br><br>Any ideas?<br><br>Note, I had to compile lli with -z execstack in order for trampolines on the stack to work.<br>