Compiling to ARM I get “Error: attempt to use an ARM instruction on a Thumb-only processor”

∥☆過路亽.° 提交于 2019-12-24 09:49:12

问题


The following command

/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

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

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

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

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


回答1:


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.

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



来源:https://stackoverflow.com/questions/39515677/compiling-to-arm-i-get-error-attempt-to-use-an-arm-instruction-on-a-thumb-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!