What causes signal 'SIGILL'?
Asked Answered
O

4

115

I'm porting some C++ code to Android using NDK and GCC. The code basically runs. At one point, when debugging in Eclipse, the call

Dabbler::Android::Factory* pFactory = new Dabbler::Android::Factory;

causes this error:

Thread [1] (Suspended: Signal 'SIGILL' received. Description: Illegal instruction.) 
    1 <symbol is not available> 0x812feb44

What does that mean? Has the compiler generated illegal code for some reason? I have a breakpoint in the constructor (which does nothing), and it's not hit. I have already done a full rebuild.

What could I be doing wrong to cause this problem?

Outmaneuver answered 26/10, 2011 at 11:17 Comment(0)
A
57

Make sure that all functions with non-void return type have a return statement.

While some compilers automatically provide a default return value, others will send a SIGILL or SIGTRAP at runtime when trying to leave a function without a return value.

Anele answered 11/7, 2019 at 16:12 Comment(2)
You have no idea to what lengths I went searching for a reason behind SIGILL (QT + Android) just to find a missing return statement in a function (inspired by your reply). Thank you.Crimson
@Crimson What compiler you were using? Thanks!Andradite
K
38

It means the CPU attempted to execute an instruction it didn't understand. This could be caused by corruption I guess, or maybe it's been compiled for the wrong architecture (in which case I would have thought the O/S would refuse to run the executable). Not entirely sure what the root issue is.

Kaden answered 26/10, 2011 at 11:20 Comment(2)
Another cause of execing an invalid instruction is jumping to an address that isn't in the program area.Estuary
Weird, I got this, when I compiled with clang, but it worked fine with gccAshtonashtonunderlyne
E
27

It could be some un-initialized function pointer, in particular if you have corrupted memory (then the bogus vtable of C++ bad pointers to invalid objects might give that).

BTW gdb watchpoints & tracepoints, and also valgrind might be useful (if available) to debug such issues. Or some address sanitizer.

Emancipated answered 26/10, 2011 at 11:31 Comment(1)
For me, I wasn't returning any value from a function that was supposed to return an int. So somewhat related to this answer. No idea how it managed to compile.Poetics
D
6

LeetCode's online compiler and dev environment generates SIGILL errors for mistakes that do not generate the same error in my desktop IDE.

For example, array access with an out-of-bounds index:

["foo", "bar"][2]

LeetCode's compiler shows only the error:

Runtime Error process exited with signal SIGILL

in a local Xcode playground this same code instead results in the error:

error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x18f2ea5d8).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

Only in a full Xcode project compilation and run does it report the actual error:

Thread 1: Fatal error: Index out of range

Downgrade answered 15/12, 2021 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.