简体   繁体   中英

How to write .syntax unified UAL ARMv7 inline assembly in GCC?

I want to write unified assembly to get rid of pesky # in front of my literals as mentioned at: Is the hash required for immediate values in ARM assembly?

This is a minimal non-unified code with # :

#include <assert.h>
#include <inttypes.h>

int main(void) {
    uint32_t io = 0;
    __asm__ (
        "add %0, %0, #1;"
        : "+r" (io)
        :
        :
    );
    assert(io == 1);
}

which compiles and later runs fine under QEMU:

arm-linux-gnueabihf-gcc -c -ggdb3 -march=armv7-a -pedantic -std=c99 -Wall -Wextra \
  -fno-pie -no-pie -marm -o 'tmp.o' 'tmp.c'

If I try to remove the # , then the code fails with:

/tmp/user/20321/ccoBzpSK.s: Assembler messages:
/tmp/user/20321/ccoBzpSK.s:51: Error: shift expression expected -- `add r3,r3,1'

as expected, since non-unified seems to be the default.

How to make that work?

I found the promising option:

gcc -masm-syntax-unified

but adding it did not help.

If I write instead:

".syntax unified; add %0, %0, #1;"

then it works, but I would have to do that for every __asm__ which is not practical.

UI also found that without -marm , then it does use unified assembly, but it generates thumb code, which I don't want.

Maybe this bug is the root cause of the problem: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648

Tested in arm-linux-gnueabi-gcc 5.4.0, Ubuntu 18.04.

Devs replied again soon to the issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648#c3 and a patch was committed at: https://github.com/gcc-mirror/gcc/commit/2fd2b9b8425f9fc4ad98d48a0ca41b921dd75bd9 (post 8.2.0) fixing -masm-syntax-unified . Awesome!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM