<div dir="ltr">hi.<div><br></div><div>i'm trying to compile (seems to be sucessfully) and execute code on arm (ios apple ipad air) and i'm having <b>exc_bad_instruction (code=exc_arm_undefined, subcode=0x8458b00)</b> exception.</div><div><br></div><div>source code:</div><div><br></div><div><font face="courier new, monospace">int main(int count, const char **args) {</font></div><div><font face="courier new, monospace"> const char *c = "hello world";</font></div><div><font face="courier new, monospace"> return 1 + 5;</font></div><div><font face="courier new, monospace">}</font></div><div><br></div><div>generate bit-code cmd:</div><div><br></div><div><div>const char *cmd[] = {</div><div> "clang",</div><div> "-cc1",</div><div> "-triple",</div><div> "arm-apple-macosx10.10.0", //"thumbv7-apple-ios7.1.0", //"arm-apple-macosx10.10.0", // "i386-apple-macosx10.10.0",</div><div> "-emit-llvm",</div><div> "-disable-free",</div><div> "-main-file-name",</div><div> [cppShortFile UTF8String],</div><div> "-mrelocation-model",</div><div> "pic",</div><div> "-pic-level",</div><div> "2",</div><div> "-mdisable-fp-elim",</div><div> "-masm-verbose",</div><div> "-target-cpu",</div><div> "cortex-a8", //"yonah",</div><div> "-target-linker-version",</div><div> "236.3",</div><div> "-v",</div><div> "-coverage-file",</div><div> [llFile UTF8String], //"/private/var/mobile/Applications/175ECA7F-3175-4AC9-971C-85272F5492C4/tmp/hw.ll"</div><div> "-resource-dir",</div><div> [[[ASPathHolder sharedHolder] tempFolder] UTF8String],</div><div> "-stdlib=libc++",</div><div> "-fdeprecated-macro",</div><div> "-fdebug-compilation-dir",</div><div> [[[ASPathHolder sharedHolder] tempFolder] UTF8String],</div><div> "-ferror-limit",</div><div> "19",</div><div> "-fmessage-length",</div><div> "0",</div><div> //"-I",</div><div> // [[[[ASPathHolder sharedHolder] includeFolder] stringByAppendingString:@"/libc"] UTF8String], // libc include folder</div><div> //"-I",</div><div> // [[[[ASPathHolder sharedHolder] includeFolder] stringByAppendingString:@"/libcxx"] UTF8String], // libc++ include folder</div><div> "-stack-protector",</div><div> "1",</div><div> "-mstackrealign",</div><div> //"-fblocks", // Apple "blocks" extensions</div><div> //"-fobjc-runtime=macosx-fragile-10.10.0", // object-c runtime</div><div> //"-fobjc-subscripting-legacy-runtime",</div><div> "-fencode-extended-block-signature",</div><div> "-fcxx-exceptions",</div><div> "-fexceptions",</div><div> "-fdiagnostics-show-option",</div><div> "-vectorize-slp",</div><div> "-target-feature",</div><div> "+soft-float-abi",</div><div> "-target-abi",</div><div> "apcs-gnu",</div><div> "-mfloat-abi",</div><div> "soft",</div><div> "-o",</div><div> [llFile UTF8String], // /private/var/mobile/Applications/175ECA7F-3175-4AC9-971C-85272F5492C4/tmp/hw.ll</div><div> "-x",</div><div> "c++",</div><div> [cppFile UTF8String] //"/private/var/mobile/Applications/175ECA7F-3175-4AC9-971C-85272F5492C4/tmp/hw.cpp"</div><div> };</div></div><div><br></div><div>i'm not sure i'm using correct triple, target cpu and target features but i used xcodes ones (when targeting ios device).</div><div><br></div><div>compilation was successfull and i'm having .ll file:</div><div><div><font face="courier new, monospace">; ModuleID = '/var/mobile/Applications/53D60D11-DF93-4129-AD97-B96424D165B5/Documents/projects/calc/calc.cpp'</font></div><div><font face="courier new, monospace">target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32"</font></div><div><font face="courier new, monospace">target triple = "thumbv7-apple-ios7.1.0"</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">@.str = private unnamed_addr constant [12 x i8] c"hello world\00", align 1</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">; Function Attrs: nounwind ssp</font></div><div><font face="courier new, monospace">define i32 @main(i32 %count, i8** %args) #0 {</font></div><div><font face="courier new, monospace">entry:</font></div><div><font face="courier new, monospace"> %retval = alloca i32, align 4</font></div><div><font face="courier new, monospace"> %count.addr = alloca i32, align 4</font></div><div><font face="courier new, monospace"> %args.addr = alloca i8**, align 4</font></div><div><font face="courier new, monospace"> %c = alloca i8*, align 4</font></div><div><font face="courier new, monospace"> store i32 0, i32* %retval</font></div><div><font face="courier new, monospace"> store i32 %count, i32* %count.addr, align 4</font></div><div><font face="courier new, monospace"> store i8** %args, i8*** %args.addr, align 4</font></div><div><font face="courier new, monospace"> store i8* getelementptr inbounds ([12 x i8]* @.str, i32 0, i32 0), i8** %c, align 4</font></div><div><font face="courier new, monospace"> ret i32 6</font></div><div><font face="courier new, monospace">}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">attributes #0 = { nounwind ssp "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" }</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">!llvm.ident = !{!0}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">!0 = metadata !{metadata !"clang version 3.4 (tags/RELEASE_34/final 212412)"}</font></div></div><div><br></div><div>is it correct or can you see obvious errors?</div><div><br></div><div>then i'm trying to interpret .ll file.</div><div>i've copied lli tool source code and launching it from my ios app (created static lib instead of executable) with default arguments (like triple and cpu and so on - this can probably be wrong!).</div><div><br></div><div>Then i'm having exception in ExecutionEngine.cpp in line:</div><div>
<p class=""><font face="courier new, monospace"><span class="">return</span> runFunction(Fn, GVArgs).IntVal.getZExtValue();</font></p><p class=""><b>exc_bad_instruction (code=exc_arm_undefined, subcode=0x8458b00)</b></p><p class="">Any thoughts? What does this subcode mean?</p><p class="">Any help is highly appreciated.</p><p class="">Regards, Anton.</p></div></div>