如何在 GCC 中编写 .syntax 统一的 UAL ARMv7 内联汇编? [英] How to write .syntax unified UAL ARMv7 inline assembly in GCC?
问题描述
我想编写统一的程序集来摆脱烦人的 #
在我的文字前面提到的:ARM 汇编中的立即数是否需要散列?
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.
也许这个bug是问题的根本原因: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 很快再次回复了这个问题:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648#c3 并在以下位置提交了补丁:https://github.com/gcc-mirror/gcc/commit/2fd2b9b8484d201b9b84d201b9b84d201b9b84d84d201b9b84d201b9b84d72ad98d201b921d75bd9代码>-masm-syntax-unified.太棒了!
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屋!