[cfe-dev] exc_bad_instruction on arm

Anton Smirnov dev at antonsmirnov.name
Wed Sep 17 00:43:07 PDT 2014


i've changed lli arguments to the next (instead of default):

return llvm_interpret(
    InputFile,
    std::vector<std::string>(),
    false, // ForceInterpreter
    false, // UseMCJIT
    false, // DebugIR
    false, // RemoteMCJIT
    "", // MCJITRemoteProcess
    ' ', // OptLevel
    std::string("thumbv7-apple-ios7.1.0"), // TargetTriple
    std::string("thumb"), // MArch
    std::string("cortex-a8"), // MCPU
    std::vector<std::string>(), // MAttrs
    "main", // EntryFunc
    std::vector<std::string>(), // ExtraModules
    std::string(), // FakeArgv0
    false, // DisableCoreFiles
    false, // NoLazyCompilation
    Reloc::PIC_, // RelocModel
    CodeModel::JITDefault, // CMModel
    true, // GenerateSoftFloatCalls
    FloatABI::Soft, // FloatABIForCalls
    false, // EmitJitDebugInfo
    false, // EmitJitDebugInfoToDisk
    envp // envp
    );

Now i'm having:

*Unhandled instruction encoding format!*
UNREACHABLE executed at
/Users/asmirnov/Documents/dev/src/llvm_34_ios/lib/Target/ARM/ARMCodeEmitter.cpp:547!
0  iCode                    0x01f7e591 llvm::sys::PrintStackTrace(__sFILE*)
+ 44
1  iCode                    0x01f7e807 PrintStackTraceSignalHandler(void*)
+ 26
2  iCode                    0x01f7eb09 SignalHandler(int) + 356
3  libsystem_platform.dylib 0x397e171b _sigtramp + 34
4  libsystem_pthread.dylib  0x397e67b7 pthread_kill + 58
5  iCode                    0x01f7e81f raise + 18
6  iCode                    0x01f7e8b5 abort + 16
7  iCode                    0x01f6d395 llvm::SmallVector<char,
64u>::SmallVector() + 0
8  iCode                    0x01410bd5 (anonymous
namespace)::ARMCodeEmitter::emitInstruction(llvm::MachineInstr const&) +
1652
9  iCode                    0x01410521 (anonymous
namespace)::ARMCodeEmitter::runOnMachineFunction(llvm::MachineFunction&) +
556
10 iCode                    0x016788f5
llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 72
11 iCode                    0x018749ad
llvm::FPPassManager::runOnFunction(llvm::Function&) + 252
12 iCode                    0x018744ab
llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 78
13 iCode                    0x01874455
llvm::legacy::FunctionPassManager::run(llvm::Function&) + 200
14 iCode                    0x01a36d9d
llvm::JIT::jitTheFunction(llvm::Function*, llvm::MutexGuard const&) + 44
15 iCode                    0x01a36c31
llvm::JIT::runJITOnFunctionUnlocked(llvm::Function*, llvm::MutexGuard
const&) + 112
16 iCode                    0x01a36f7f
llvm::JIT::getPointerToFunction(llvm::Function*) + 450
17 iCode                    0x000da28d
llvm_interpret(std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, std::__1::vector<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::allocator<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > > >, bool, bool,
bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, char, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >,
std::__1::allocator<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > > >,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, std::__1::vector<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::allocator<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > > >,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, bool, bool, llvm::Reloc::Model,
llvm::CodeModel::Model, bool, llvm::FloatABI::ABIType, bool, bool, char*) +
4364
18 iCode                    0x000db8c7 llvm_interpret(char const*, char*) +
1346
19 iCode                    0x000dbb83 llvm_interpret(char const*, char*,
char const*) + 134
20 iCode                    0x000b0973 -[ASMainController didClickCompile:]
+ 2446
21 UIKit                    0x30f656a7 <redacted> + 90
22 UIKit                    0x310cc56d <redacted> + 120
23 UIKit                    0x30f656a7 <redacted> + 90
24 UIKit                    0x30f65643 <redacted> + 38
25 UIKit                    0x30f65613 <redacted> + 46
26 UIKit                    0x30f50d5b <redacted> + 374
27 UIKit                    0x30f6505b <redacted> + 594
28 UIKit                    0x30f28521 <redacted> + 5528
29 CoreFoundation           0x2e6c9ff9 <redacted> + 20
30 CoreFoundation           0x2e6c7987 <redacted> + 286
31 CoreFoundation           0x2e6c7cd3 <redacted> + 738
32 CoreFoundation           0x2e632729 CFRunLoopRunSpecific + 524
33 CoreFoundation           0x2e63250b CFRunLoopRunInMode + 106
34 GraphicsServices         0x3355e6d3 GSEventRunModal + 138
35 UIKit                    0x30f93871 UIApplicationMain + 1136
36 iCode                    0x000d0829 main + 116
37 libdyld.dylib            0x396c7ab7 <redacted> + 2
Stack dump:
0. Running pass 'ARM Machine Code Emitter' on function '@main'
0  iCode                    0x01f7e591 llvm::sys::PrintStackTrace(__sFILE*)
+ 44
1  iCode                    0x01f7e807 PrintStackTraceSignalHandler(void*)
+ 26
2  iCode                    0x01f7eb09 SignalHandler(int) + 356
3  libsystem_platform.dylib 0x397e171b _sigtramp + 34
4  libsystem_pthread.dylib  0x397e67b7 pthread_kill + 58
5  iCode                    0x01f7e81f raise + 18
6  iCode                    0x01f7e8b5 abort + 16
7  iCode                    0x01f6d395 llvm::SmallVector<char,
64u>::SmallVector() + 0
8  iCode                    0x01410bd5 (anonymous
namespace)::ARMCodeEmitter::emitInstruction(llvm::MachineInstr const&) +
1652
9  iCode                    0x01410521 (anonymous
namespace)::ARMCodeEmitter::runOnMachineFunction(llvm::MachineFunction&) +
556
10 iCode                    0x016788f5
llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 72
11 iCode                    0x018749ad
llvm::FPPassManager::runOnFunction(llvm::Function&) + 252
12 iCode                    0x018744ab
llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 78
13 iCode                    0x01874455
llvm::legacy::FunctionPassManager::run(llvm::Function&) + 200
14 iCode                    0x01a36d9d
llvm::JIT::jitTheFunction(llvm::Function*, llvm::MutexGuard const&) + 44
15 iCode                    0x01a36c31
llvm::JIT::runJITOnFunctionUnlocked(llvm::Function*, llvm::MutexGuard
const&) + 112
16 iCode                    0x01a36f7f
llvm::JIT::getPointerToFunction(llvm::Function*) + 450
17 iCode                    0x000da28d
llvm_interpret(std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, std::__1::vector<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::allocator<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > > >, bool, bool,
bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, char, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >,
std::__1::allocator<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > > >,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, std::__1::vector<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
std::__1::allocator<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > > >,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, bool, bool, llvm::Reloc::Model,
llvm::CodeModel::Model, bool, llvm::FloatABI::ABIType, bool, bool, char*) +
4364
18 iCode                    0x000db8c7 llvm_interpret(char const*, char*) +
1346
19 iCode                    0x000dbb83 llvm_interpret(char const*, char*,
char const*) + 134

this seems to be different arguments between compile and interpret or
bitcode was generated incorrectly?

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

> 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/3236ddf3/attachment.html>


More information about the cfe-dev mailing list