在Thumb-2代碼中,不可能在大多數指令中使用寄存器8-15,但這在ARM代碼中是可行的。因此,下面的組件提供了一個運行時非法指令錯誤:編譯時寄存器檢查Thumb-2代碼
.syntax unified
.fpu vfp
.thumb
.text
.globl main
main:
str r12,[sp,#-4] @ r12 is too high, source register is 3 bits wide
但是,我沒有得到在編譯時警告,即使我用-Wall
:
[email protected]:~/ctests$ arm-linux-gnueabihf-as -Wall -o high.o high.s
ARM GAS high.s page 1
1 .syntax unified
2 .fpu vfp
3 .thumb
4 .text
5 .globl main
6 main:
7 0000 4DF804CC str r12,[sp,#-4]
[email protected]:~/ctests$ arm-linux-gnueabihf-gcc -Wall -o high high.o
[email protected]:~/ctests$ ./high
Illegal instruction
[email protected]:~/ctests$ file high
high: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=c9d90a7d6386bf97a18f9da87a7b2ce422402659, not stripped
是否有任何工具,可以用於在編譯時檢查非法指令?
謝謝!當我在'main'的末尾添加'bx lr'時,它會起作用。 – Keelan