<div dir="ltr">Hi all,<div><br></div><div style>I'm trying to extend the Dalvik VM to load some LLVM assembly from the SD card, JIT it, and execute it. I'm using AOSP 4.0.4, a Galaxy Nexus, and the version of LLVM that comes in the external project of AOSP (LLVM 2.8, I believe?) </div>
<div style><br></div><div style>I have the following LLVM assembly:</div><div style><br></div><div style><div>target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32"</div>
<div>target triple = "armv7--"</div><div><br></div><div>@runtime_val = global i32 7, align 4 </div><div><br></div><div>define i32 @method() {</div><div>entry:</div><div><span class="" style="white-space:pre">  </span>%ret = load i32* @runtime_val, align 4</div>
<div><span class="" style="white-space:pre">    </span>ret i32 %ret</div><div>}</div><div><br></div><div style>When I use getPointerToFunction() after loading this assembly with ParseAssemblyFile(), I get the following stderr output, and then a segfault:</div>
<div style><br></div><div style><div>UNREACHABLE executed!</div><div>Stack dump:</div><div>0.<span class="" style="white-space:pre">    </span>Running pass 'ARM Machine Code Emitter' on function '@method'</div>
<div><br></div><div style>And here's the GDB backtrace:</div><div><br></div><div>#0  __libc_android_abort () at bionic/libc/unistd/abort.c:82<br></div><div><div>#1  0x40e35600 in llvm::llvm_unreachable_internal (msg=0x0, file=<optimized out>, line=<optimized out>) at external/llvm/lib/Support/ErrorHandling.cpp:98</div>
<div>#2  0x409d34ac in (anonymous namespace)::ARMCodeEmitter::getMovi32Value (this=<optimized out>, MI=<optimized out>, MO=<optimized out>, Reloc=8)</div><div>    at external/llvm/lib/Target/ARM/ARMCodeEmitter.cpp:439</div>
<div>#3  0x409e237c in (anonymous namespace)::ARMCodeEmitter::emitDataProcessingInstruction (this=0x1a7a338, MI=..., ImplicitRd=0, ImplicitRn=0)</div><div>    at external/llvm/lib/Target/ARM/ARMCodeEmitter.cpp:1036</div><div>
#4  0x409e2ba0 in (anonymous namespace)::ARMCodeEmitter::emitInstruction (this=0x1a7a338, MI=...) at external/llvm/lib/Target/ARM/ARMCodeEmitter.cpp:555</div><div>#5  0x409e2e68 in (anonymous namespace)::ARMCodeEmitter::runOnMachineFunction (this=0x1a7a338, MF=...)</div>
<div>    at external/llvm/lib/Target/ARM/ARMCodeEmitter.cpp:399</div><div>#6  0x40bb6f10 in llvm::MachineFunctionPass::runOnFunction (this=0x1a7a338, F=<optimized out>) at external/llvm/lib/CodeGen/MachineFunctionPass.cpp:33</div>
<div>#7  0x40dfc234 in llvm::FPPassManager::runOnFunction (this=0x1a65100, F=...) at external/llvm/lib/VMCore/PassManager.cpp:1498</div></div><div style><div>#8  0x40dfc34c in llvm::FunctionPassManagerImpl::run (this=0x1a2ea50, F=...) at external/llvm/lib/VMCore/PassManager.cpp:1449</div>
<div>#9  0x40dfc5a4 in llvm::FunctionPassManager::run (this=0x1a6c608, F=...) at external/llvm/lib/VMCore/PassManager.cpp:1379</div><div>#10 0x409aa988 in llvm::JIT::jitTheFunction (this=0x1a6c550, F=0x1, locked=...) at external/llvm/lib/ExecutionEngine/JIT/JIT.cpp:645</div>
<div>#11 0x409aa9ac in llvm::JIT::runJITOnFunctionUnlocked (this=0xdeadbaad, F=0x1, locked=...) at external/llvm/lib/ExecutionEngine/JIT/JIT.cpp:624</div><div>#12 0x409aac50 in llvm::JIT::getPointerToFunction (this=0x1a6c550, F=0x1a6aef8) at external/llvm/lib/ExecutionEngine/JIT/JIT.cpp:681</div>
<div style><..snip..></div></div><div><br></div><div style>Is there something obviously wrong with the way I'm declaring this global variable and then reading its value, that would lead to this segfault?</div><div style>
<br></div><div style>Cheers,</div><div style>Stephen</div></div></div></div>