3

我正在尝试在 ios 设备上执行 LLVM 位码。我已经使用clang -emit-llvm -S -c ./test.cpp -o .test.ll -target arm64-apple-ios7.1针对 arm64 设备编译了位码文件。启动 LLVM/Clang 版本 3.5 支持 ios arm64 设备。然后我尝试使用 MCJit'ter 调用代码并获得异常: http ://llvm.org/bugs/show_bug.cgi?id=21012

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

PS。位码看起来正确并针对正确的目标:

; 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 版本后的主干)从简单的源代码编译而成:

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

聚苯乙烯。解释器代码几乎是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
4

0 回答 0