1

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.

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44
  • It's a longshot, but: Sometimes later options in a command line can overwrite earlier options. Where did you put the `-masm-syntax-unified`? Also, if you did add the `.syntax unified` thing, presumably you'd have to put it back when you were done. Seems like you could wrap the string in a macro, but that'd be at least as ugly as using `#1`. – David Wohlferd Jan 08 '19 at 05:10
  • @DavidWohlferd thanks, I should have tried that earlier. Apparently it's an incompatibility with `-marm`, which might be a GCC bug. Updated question. – Ciro Santilli Jan 08 '19 at 12:17

1 Answers1

1

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!

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44