简体   繁体   English

如何在 GCC 中编写 .syntax 统一的 UAL ARMv7 内联汇编?

[英]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?我想编写统一的程序集以消除我的文字前面的讨厌# ,如在: ARM 程序集中的立即值需要散列吗?

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:编译后在 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.然后它起作用了,但我必须为每个不切实际的__asm__这样做。

UI also found that without -marm , then it does use unified assembly, but it generates thumb code, which I don't want. UI 还发现如果没有-marm ,那么它确实使用了统一程序集,但是它生成了我不想要的拇指代码。

Maybe this bug is the root cause of the problem: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648也许这个错误是问题的根本原因: https : //gcc.gnu.org/bugzilla/show_bug.cgi?id=88648

Tested in arm-linux-gnueabi-gcc 5.4.0, Ubuntu 18.04.在 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 .开发人员很快再次回复了这个问题: https ://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648#c3 并在以下位置提交了补丁: https : //github.com/gcc-mirror/gcc/ commit/2fd2b9b8425f9fc4ad98d48a0ca41b921dd75bd9 (8.2.0 后)修复-masm-syntax-unified Awesome!惊人的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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