编译到 ARM 时出现“错误:尝试在纯 Thumb 处理器上使用 ARM 指令"; [英] Compiling to ARM I get "Error: attempt to use an ARM instruction on a Thumb-only processor"

查看:38
本文介绍了编译到 ARM 时出现“错误:尝试在纯 Thumb 处理器上使用 ARM 指令";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令

/usr/bin/arm-linux-gnueabihf-gcc -O3 -DNDEBUG -march=armv7-a -mfloat-abi=hard -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fvisibility-inlines-hidden -fno-function-sections -fno-lto -g -Wno-variadic-macros -Wno-non-virtual-dtor -o testAsm.S.o -c testAsm.S

在以下程序集文件 testAsm.S 上:

On the following assembly file testAsm.S :

    .syntax unified
    .arch armv7
    .fpu vfpv3
    .code 32
    .global _functionPointer
    .p2align 2
    .global _asmFunction
    .type _asmFunction, %function
_asmFunction:
    PUSH {r1-r3,lr}
    VPUSH {d0-d7}
    MOVW r1,#:lower16:_functionPointer
    MOVT r1,#:upper16:_functionPointer
    LDR r2, [r1]
    CMP r2, #0
    BEQ asmFunction_restore
    MOV r1, #0
    BLX r2
asmFunction_restore:
    VPOP {d0-d7}
    POP {r1-r3,pc}

为每条指令产生以下错误

Produces the following error for every instruction

错误:尝试在纯 Thumb 处理器上使用 ARM 指令

Error: attempt to use an ARM instruction on a Thumb-only processor

具体来说,下面是输出:

Specifically, below is the output:

testAsm.S: Assembler messages:
testAsm.S:10: Error: attempt to use an ARM instruction on a Thumb-only processor -- `push {r1-r3,lr}'
testAsm.S:11: Error: attempt to use an ARM instruction on a Thumb-only processor -- `vpush {d0-d7}'
testAsm.S:12: Error: attempt to use an ARM instruction on a Thumb-only processor -- `movw r1,#:lower16:_functionPointer'
testAsm.S:13: Error: attempt to use an ARM instruction on a Thumb-only processor -- `movt r1,#:upper16:_functionPointer'
testAsm.S:14: Error: attempt to use an ARM instruction on a Thumb-only processor -- `ldr r2,[r1]'
testAsm.S:15: Error: attempt to use an ARM instruction on a Thumb-only processor -- `cmp r2,#0'
testAsm.S:16: Error: attempt to use an ARM instruction on a Thumb-only processor -- `beq asmFunction_restore'
testAsm.S:17: Error: attempt to use an ARM instruction on a Thumb-only processor -- `mov r1,#0'
testAsm.S:18: Error: attempt to use an ARM instruction on a Thumb-only processor -- `blx r2'
testAsm.S:20: Error: attempt to use an ARM instruction on a Thumb-only processor -- `vpop {d0-d7}'
testAsm.S:21: Error: attempt to use an ARM instruction on a Thumb-only processor -- `pop {r1-r3,pc}'

我尝试为 ARM 编译.为什么它说 Thumb-only 模式?

I tried to compile for ARM. Why does it say about Thumb-only mode?

显然,将程序集文件从 .arch armv7 更改为 .arch armv7a 可以解决问题.

apparently, changing in the assembly file from .arch armv7 to .arch armv7a fixes the problem.

推荐答案

GNU 的 arch=armv7,可能令人困惑,代表了 ARMv7-A 和 ARMv7-M 的交集(使其具有可疑的效用).因此,将它与 .code 32(相当于 -marm 命令行选项)结合起来,它告诉汇编器汇编成 ARM 编码,而 ARMv7-M 则没有支持,让它无法组装任何东西.

GNU's arch=armv7, perhaps confusingly, represents the intersection of ARMv7-A and ARMv7-M (making it of questionable utility). Thus combining it with .code 32 (equivalent to the -marm command-line option), which tells the assembler to assemble to ARM encodings, which ARMv7-M doesn't support, leaves it with no way to assemble anything.

当然,简单地在指令或选项处停止并引发错误,使其处于不可能的境地对于 GAS 来说是一件太明智的事情,因此它会继续前进并且无法单独组装每条指令..

Of course, simply stopping and raising an error at the directive or option which puts it in an impossible situation would be far too sensible a thing for GAS to do, so instead it keeps going and fails to assemble each instruction individually...

这篇关于编译到 ARM 时出现“错误:尝试在纯 Thumb 处理器上使用 ARM 指令";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆