I am trying to play around with an app for Android and every time I try to call a function (lua_gettop() from the Lua 5.1 library) from the app's address space, it hits me with ILL_ILLOPC.

I made sure to rebase the address and the function is correct as I read the opcodes from the location to make sure I wasn't calling the wrong thing. I tried to call gettop() by using another function that is only designed to call that, and it worked, so I remade gettop() and built it with my current tools and put both libraries in IDA to compare the instructions.

To my surprise they were completely different (which makes me think that is why my trying to call that crashes, it doesn't recognise the instructions??)

Here are the instructions

.text:0172D8F8                 LDRD.W          R1, R0, [R0,#0xC]
.text:0172D8FC                 SUBS            R0, R1, R0
.text:0172D8FE                 ASRS            R0, R0, #4
.text:0172D900                 BX              LR

And my library's version of the function:

.text:000BF614                 LDR             R1, [R0,#0xC]
.text:000BF618                 LDR             R0, [R0,#0x10]
.text:000BF61C                 SUB             R0, R1, R0
.text:000BF620                 MOV             R0, R0,LSR#4
.text:000BF624                 BX              LR

I tried to find out how to make it compile to the same instruction set to no luck, I assume this to be the problem, but I'm ready to be corrected.

1 Answer 1


The difference is that the first set of instructions are THUMB2 instructions whereas your library's version is using ARM instructions.

(The giveaway is in the instruction lengths - mostly 2 sometimes 4 for THUMB/THUMB2 and always 4 for ARM.)

You will need to compile your library to use THUMB code (check your compiler documentation) or deal with the ARM/THUMB state interworking yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.