编译为ARM我得到"错误:尝试在仅Thumb处理器上使用ARM指令"

时间:2016-09-15 16:06:52

标签: gcc assembly arm thumb

以下命令

TypeError: $.validator.unobtrusive.settings is not a function

在以下程序集文件/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

为每条指令生成以下错误

  

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

具体来说,下面是输出:

    .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}

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

编辑:显然,将程序集文件从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}' 更改为.arch armv7可以解决问题。

1 个答案:

答案 0 :(得分:5)

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

当然,简单地在指令或选项上停止并引发错误会使其处于不可能的情况对于GAS来说是非常明智的事情,所以相反它继续进行并且无法单独汇编每条指令。