[LLVMdev] Global variables on LLVM JIT on ARM (Android)

Stephen Kyle s.kyle at ed.ac.uk
Tue May 28 09:00:11 PDT 2013

Hi all,

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

I have the following LLVM assembly:

target datalayout =
target triple = "armv7--"

@runtime_val = global i32 7, align 4

define i32 @method() {
%ret = load i32* @runtime_val, align 4
ret i32 %ret

When I use getPointerToFunction() after loading this assembly with
ParseAssemblyFile(), I get the following stderr output, and then a segfault:

Stack dump:
0. Running pass 'ARM Machine Code Emitter' on function '@method'

And here's the GDB backtrace:

#0  __libc_android_abort () at bionic/libc/unistd/abort.c:82
#1  0x40e35600 in llvm::llvm_unreachable_internal (msg=0x0, file=<optimized
out>, line=<optimized out>) at
#2  0x409d34ac in (anonymous namespace)::ARMCodeEmitter::getMovi32Value
(this=<optimized out>, MI=<optimized out>, MO=<optimized out>, Reloc=8)
    at external/llvm/lib/Target/ARM/ARMCodeEmitter.cpp:439
#3  0x409e237c in (anonymous
namespace)::ARMCodeEmitter::emitDataProcessingInstruction (this=0x1a7a338,
MI=..., ImplicitRd=0, ImplicitRn=0)
    at external/llvm/lib/Target/ARM/ARMCodeEmitter.cpp:1036
#4  0x409e2ba0 in (anonymous namespace)::ARMCodeEmitter::emitInstruction
(this=0x1a7a338, MI=...) at
#5  0x409e2e68 in (anonymous
namespace)::ARMCodeEmitter::runOnMachineFunction (this=0x1a7a338, MF=...)
    at external/llvm/lib/Target/ARM/ARMCodeEmitter.cpp:399
#6  0x40bb6f10 in llvm::MachineFunctionPass::runOnFunction (this=0x1a7a338,
F=<optimized out>) at external/llvm/lib/CodeGen/MachineFunctionPass.cpp:33
#7  0x40dfc234 in llvm::FPPassManager::runOnFunction (this=0x1a65100,
F=...) at external/llvm/lib/VMCore/PassManager.cpp:1498
#8  0x40dfc34c in llvm::FunctionPassManagerImpl::run (this=0x1a2ea50,
F=...) at external/llvm/lib/VMCore/PassManager.cpp:1449
#9  0x40dfc5a4 in llvm::FunctionPassManager::run (this=0x1a6c608, F=...) at
#10 0x409aa988 in llvm::JIT::jitTheFunction (this=0x1a6c550, F=0x1,
locked=...) at external/llvm/lib/ExecutionEngine/JIT/JIT.cpp:645
#11 0x409aa9ac in llvm::JIT::runJITOnFunctionUnlocked (this=0xdeadbaad,
F=0x1, locked=...) at external/llvm/lib/ExecutionEngine/JIT/JIT.cpp:624
#12 0x409aac50 in llvm::JIT::getPointerToFunction (this=0x1a6c550,
F=0x1a6aef8) at external/llvm/lib/ExecutionEngine/JIT/JIT.cpp:681

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130528/d99d12a0/attachment.html>

More information about the llvm-dev mailing list