如何在GCC中编写.syntax统一UAL ARMv7内联汇编? [英] How to write .syntax unified UAL ARMv7 inline assembly in GCC?

查看:211
本文介绍了如何在GCC中编写.syntax统一UAL ARMv7内联汇编?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写统一的程序集,以消除我的文字前面的讨厌的#,如在

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);
}

它可以编译并在QEMU下正常运行:

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.

该如何工作?

我找到了有前途的选择:

I found the promising option:

gcc -masm-syntax-unified

但是添加它没有帮助.

如果我改写:

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

然后它可以工作,但是我必须为每个不实用的__asm__这样做.

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

UI还发现,如果没有-marm,它将使用统一程序集,但是会生成拇指代码,这是我所不希望的.

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

也许此错误是问题的根本原因: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648

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

在arm-linux-gnueabi-gcc 5.4.0,Ubuntu 18.04中进行了测试.

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

推荐答案

Devs很快再次回答了该问题:

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!

这篇关于如何在GCC中编写.syntax统一UAL ARMv7内联汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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