admin管理员组

文章数量:1188010

I'm working on Forth for aarch64 implemented in mix of C, inline assembler and generated assembler code. When running some unit tests the program is killed on "Illegal instruction". The same code works on standard aarch64 Linux (e.g. Ubuntu on qemu or Amazon linux on AWS) but crashing on Android (not rooted, compiled and running from Termux).

When running in gdb I cannot find any reason of the instruction is illegal. Below is an example of gdb session. Note the memory area around 0x0000007ff6e37020 contains assembler code generated during runtime.

...
../test/Testipf_core.c:968:test_pick_roll:PASS
../test/Testipf_core.c:969:test_parse_word:PASS
../test/Testipf_core.c:970:test_find:PASS

Program received signal SIGILL, Illegal instruction.
0x0000007ff6e37020 in ?? ()
(gdb) disassemble 0x0000007ff6e37010,+64
Dump of assembler code from 0x7ff6e37010 to 0x7ff6e37050:
   0x0000007ff6e37010:  blr     x28
   0x0000007ff6e37014:  mov     x28, #0xa74                     // #2676
   0x0000007ff6e37018:  add     x28, x28, x23
   0x0000007ff6e3701c:  blr     x28
=> 0x0000007ff6e37020:  ldr     x30, [sp], #16
   0x0000007ff6e37024:  ret

(gdb) info registers lr sp x28
lr             0x7ff6e37020        549602947104
sp             0x7fffffe2f0        0x7fffffe2f0
x28            0x300001af14        206158540564
(gdb) disassemble 0x300001af14,40
Dump of assembler code from 0x300001af14 to 0x28:
End of assembler dump.
(gdb) disassemble 0x300001af14,+40
Dump of assembler code from 0x300001af14 to 0x300001af3c:
   0x000000300001af14 <xt_two_star+0>:  mov     x0, x19
   0x000000300001af18 <xt_two_star+4>:  str     x30, [sp, #-16]!
   0x000000300001af1c <xt_two_star+8>:  bl      0x3000016fd4 <c_two_star>
   0x000000300001af20 <xt_two_star+12>: ldr     x30, [sp], #16
   0x000000300001af24 <xt_two_star+16>: mov     x19, x0
   0x000000300001af28 <xt_exit_two_star+0>:     ret
   0x000000300001af2c <nt_two_slash+0>: udf     #36
   0x000000300001af30 <nt_two_slash+4>: .inst   0x002f3202 ; NYI
   0x000000300001af34 <nt_two_slash+8>: adrp    x0, 0x302801a000
   0x000000300001af38 <xt_two_slash+0>: mov     x0, x19
End of assembler dump.
(gdb) x/10xg 0x7fffffe2f0
0x7fffffe2f0:   0x0000003000017a4c      0x000000300001cf0c
0x7fffffe300:   0x0000007ff6e38fb8      0x0000007ff6e37ed0
0x7fffffe310:   0x0000000000014b75      0x000000300001a578
0x7fffffe320:   0x0000007ff70ec000      0x0000007fffffe3c0
0x7fffffe330:   0x000000300004094c      0x0000007ff4ade3d0

(gdb) disassemble 0x0000003000017a40, +20
Dump of assembler code from 0x3000017a40 to 0x3000017a54:
   0x0000003000017a40 <ipf_execute+64>: stp     x14, x15, [sp, #16]
   0x0000003000017a44 <ipf_execute+68>: stp     x18, x29, [sp, #32]
   0x0000003000017a48 <ipf_execute+72>: blr     x8
   0x0000003000017a4c <ipf_execute+76>: ldp     x18, x29, [sp, #32]
   0x0000003000017a50 <ipf_execute+80>: ldp     x14, x15, [sp, #16]`

I would expect program to continue on address 0x0000003000017a4c after ret.

本文标签: assemblyAarch64 assembler (Android) strange illegal instruction behaviourStack Overflow