[cfe-dev] exc_bad_instruction on arm

Anton Smirnov dev at antonsmirnov.name
Tue Sep 16 22:58:16 PDT 2014


correction: triple for compilation was "thumbv7-apple-ios7.1.0" - see
compiled .ll code

2014-09-17 11:56 GMT+06:00 Anton Smirnov <dev at antonsmirnov.name>:

> hi.
>
> i'm trying to compile (seems to be sucessfully) and execute code on arm
> (ios apple ipad air) and i'm having *exc_bad_instruction
> (code=exc_arm_undefined, subcode=0x8458b00)* exception.
>
> source code:
>
> int main(int count, const char **args) {
>   const char *c = "hello world";
>   return 1 + 5;
> }
>
> generate bit-code cmd:
>
> const char *cmd[] = {
>         "clang",
>         "-cc1",
>         "-triple",
>             "arm-apple-macosx10.10.0", //"thumbv7-apple-ios7.1.0",
> //"arm-apple-macosx10.10.0", // "i386-apple-macosx10.10.0",
>         "-emit-llvm",
>         "-disable-free",
>         "-main-file-name",
>             [cppShortFile UTF8String],
>         "-mrelocation-model",
>             "pic",
>         "-pic-level",
>             "2",
>         "-mdisable-fp-elim",
>         "-masm-verbose",
>         "-target-cpu",
>             "cortex-a8", //"yonah",
>         "-target-linker-version",
>             "236.3",
>         "-v",
>         "-coverage-file",
>             [llFile UTF8String],
> //"/private/var/mobile/Applications/175ECA7F-3175-4AC9-971C-85272F5492C4/tmp/hw.ll"
>         "-resource-dir",
>             [[[ASPathHolder sharedHolder] tempFolder] UTF8String],
>         "-stdlib=libc++",
>         "-fdeprecated-macro",
>         "-fdebug-compilation-dir",
>             [[[ASPathHolder sharedHolder] tempFolder] UTF8String],
>         "-ferror-limit",
>             "19",
>         "-fmessage-length",
>             "0",
>         //"-I",
>         //    [[[[ASPathHolder sharedHolder] includeFolder]
> stringByAppendingString:@"/libc"] UTF8String], // libc include folder
>         //"-I",
>         //    [[[[ASPathHolder sharedHolder] includeFolder]
> stringByAppendingString:@"/libcxx"] UTF8String], // libc++ include folder
>         "-stack-protector",
>             "1",
>         "-mstackrealign",
>         //"-fblocks", // Apple "blocks" extensions
>         //"-fobjc-runtime=macosx-fragile-10.10.0", // object-c runtime
>         //"-fobjc-subscripting-legacy-runtime",
>         "-fencode-extended-block-signature",
>         "-fcxx-exceptions",
>         "-fexceptions",
>         "-fdiagnostics-show-option",
>         "-vectorize-slp",
>         "-target-feature",
>             "+soft-float-abi",
>         "-target-abi",
>             "apcs-gnu",
>         "-mfloat-abi",
>             "soft",
>         "-o",
>             [llFile UTF8String], //
> /private/var/mobile/Applications/175ECA7F-3175-4AC9-971C-85272F5492C4/tmp/hw.ll
>         "-x",
>         "c++",
>             [cppFile UTF8String]
> //"/private/var/mobile/Applications/175ECA7F-3175-4AC9-971C-85272F5492C4/tmp/hw.cpp"
>     };
>
> i'm not sure i'm using correct triple, target cpu and target features but
> i used xcodes ones (when targeting ios device).
>
> compilation was successfull and i'm having .ll file:
> ; ModuleID =
> '/var/mobile/Applications/53D60D11-DF93-4129-AD97-B96424D165B5/Documents/projects/calc/calc.cpp'
> 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"
> target triple = "thumbv7-apple-ios7.1.0"
>
> @.str = private unnamed_addr constant [12 x i8] c"hello world\00", align 1
>
> ; Function Attrs: nounwind ssp
> define i32 @main(i32 %count, i8** %args) #0 {
> entry:
>   %retval = alloca i32, align 4
>   %count.addr = alloca i32, align 4
>   %args.addr = alloca i8**, align 4
>   %c = alloca i8*, align 4
>   store i32 0, i32* %retval
>   store i32 %count, i32* %count.addr, align 4
>   store i8** %args, i8*** %args.addr, align 4
>   store i8* getelementptr inbounds ([12 x i8]* @.str, i32 0, i32 0), i8**
> %c, align 4
>   ret i32 6
> }
>
> 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" }
>
> !llvm.ident = !{!0}
>
> !0 = metadata !{metadata !"clang version 3.4 (tags/RELEASE_34/final
> 212412)"}
>
> is it correct or can you see obvious errors?
>
> then i'm trying to interpret .ll file.
> 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!).
>
> Then i'm having exception in ExecutionEngine.cpp in line:
>
> return runFunction(Fn, GVArgs).IntVal.getZExtValue();
>
> *exc_bad_instruction (code=exc_arm_undefined, subcode=0x8458b00)*
>
> Any thoughts? What does this subcode mean?
>
> Any help is highly appreciated.
>
> Regards, Anton.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140917/d1156398/attachment.html>


More information about the cfe-dev mailing list