gpt4 book ai didi

assembly - 编译时寄存器检查 Thumb-2 代码

转载 作者:行者123 更新时间:2023-12-01 22:21:50 25 4
gpt4 key购买 nike

在 Thumb-2 代码中,不可能在大多数指令中使用寄存器 8-15,而在 ARM 代码中这是可能的。因此,以下程序集给出了运行时非法指令错误:

        .syntax unified
.fpu vfp
.thumb
.text
.globl main
main:
str r12,[sp,#-4] @ r12 is too high, source register is 3 bits wide

但是,即使我使用 -Wall,我也不会在编译时收到警告:

pi@rasppi:~/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]
pi@rasppi:~/ctests$ arm-linux-gnueabihf-gcc -Wall -o high high.o
pi@rasppi:~/ctests$ ./high
Illegal instruction
pi@rasppi:~/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 处有 Thumb 代码,但没有将其注释为 Thumb 符号。因此,链接器不设置符号地址的 lsb,因此在运行时调用以 ARM 状态到达那里,随后在 Thumb 编码上阻塞。要解决这个问题,您需要添加 .thumb_func annotation :

...
.globl main
.thumb_func
main:
...

有了它,当您从该代码的末尾运行到后面的任何代码/数据/未映射页面时,它很可能仍然会因未定义的指令或段错误而崩溃。您需要实际从 main 返回。

您最初的假设是不正确的,因为如果它您怀疑的寄存器使用问题,它甚至不会汇编。 “可用于在编译时检查非法指令的工具” 是汇编器。

关于assembly - 编译时寄存器检查 Thumb-2 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39555845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com