LLVM可以在ios上执行bitcode(arm64)吗?

时间:2014-09-22 11:17:33

标签: ios arm clang llvm arm64

我试图在ios设备上执行LLVM bitcode。 我使用针对arm64设备的clang -emit-llvm -S -c ./test.cpp -o .test.ll -target arm64-apple-ios7.1编译了bitcode文件。启动LLVM / Clang版本3.5支持ios arm64设备。然后我尝试使用MCJit&t以及获取异常来调用代码: http://llvm.org/bugs/show_bug.cgi?id=21012

是ios OS /设备限制还是LLVM / Clang错误? 我正在使用ios 7.1在iPad Air上进行测试。

PS。 Bitcode看起来正确并且有针对性地纠正目标:

; ModuleID = './test.cpp'
target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple0ios7.1"

@.str = private unnamed_addr constant [12 x i8] c"hello world\00", align 1

; Function Attrs: nounwind
define i32 @main(i32 %argc, i8** %argv) #0 {
entry:
  %retval = alloca i32, align 4
  %argc.addr = alloca i32, align 4
  %argv.addr = alloca i8**, align 8
  %c = alloca i8*, align 8
  %a = alloca i32, align 4
  %b = alloca i32, align 4
  store i32 0, i32* %retval
  store i32 %argc, i32* %argc.addr, align 4
  store i8** %argv, i8*** %argv.addr, align 8
  store i8* getelementptr inbounds ([12 x i8]* @.str, i32 0, i32 0), i8** %c, align 8
  store i32 1, i32* %a, align 4
  %0 = load i32* %a, align 4
  %add = add nsw i32 %0, 6
  store i32 %add, i32* %b, align 4
  ret i32 3
}

attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.ident = !{!0}

!0 = metadata !{metadata !"clang version 3.6.0 (trunk 218116) (llvm/trunk 218115)"}

它是由LLVM / Clang(3.5版本后的trunk)从简单的源代码编译的:

int main(int argc, const char **argv) {
    const char *c = "hello world";
    int a = 1;
    int b = a + 6;
    return 3;
}

PPS。解释器代码几乎是lli工具代码,带有下一个参数:

return llvm_interpret(
    InputFile,
    std::vector<std::string>(), // argv
    false, // ForceInterpreter
    true, // UseMCJIT
    false, // DebugIR
    false, // RemoteMCJIT
    "", // ChildExecPath
    ' ', // OptLevel
    std::string(/*"arm64-apple-ios7.1"*/), // TargetTriple
    std::string(/*"arm64"*/), // MArch
    std::string("generic"), // MCPU
    std::vector<std::string>(), // MAttrs
    "main", // EntryFunc
    std::vector<std::string>(), // ExtraModules
    std::vector<std::string>(), // ExtraObjects
    std::vector<std::string>(), // ExtraArchives
    false, // EnableCacheManager
    std::string(), // ObjectCacheDir
    std::string(), // FakeArgv0
    false, // DisableCoreFiles
    false, // NoLazyCompilation
    Reloc::Static, // RelocModel (default is Reloc::PIC_)
    CodeModel::JITDefault, // CMModel (default is CodeModel::JITDefault)
    false, // GenerateSoftFloatCalls
    FloatABI::Default, // FloatABIForCalls
    false, // EmitJitDebugInfo
    false  // EmitJitDebugInfoToDisk
    );

例外:

rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
                                 (char **)GVTOP(ArgValues[1])));

0x4a18000:  .long  0xd10083ff                ; unknown opcode
0x4a18004:  stmdbhs r3, {r5, r6, r7, r8, r9, r10, r11, r12, sp, lr}
0x4a18008:  .long  0xf9000be1                ; unknown opcode
0x4a1800c:  andls  r0, r0, r8
0x4a18010:  .long  0xf9401908                ; unknown opcode
0x4a18014:  andlo  r0, r0, #0xa4000003
0x4a18018:  andlo  r0, r0, #0x3a800
0x4a1801c:  andlo  r0, r0, #0x3800000

0 个答案:

没有答案