failing to get the same binary with -masm=intel/-masm =att even with -Wa,-Os

Zdenek Sojka via Gcc-help <[email protected]> Tue, 26 May 2026 19:52:16 +0200 (CEST)
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
Hello,

when searching for codegen difference between -masm=3Dintel/-masm=3Datt (w=
hich 
often indicates a miscompilation), I am using -Wa,-Os in order to get 
"normalised" asm output - otherwise there are too many differences due to =

different instruction encoding.

However there are cases when even -Wa,-Os does not help:

$ cat testcase.c
_Complex a;
_Complex int b;
void c() { a =3D *(_Complex char *)__builtin_memset(&a, 1, 2) / b; }

$ for ASM in att intel; do x86_64-pc-linux-gnu-gcc -O2 testcase.c -Wa,-Os =
-o
$ASM.o -save-temps -masm=3D$ASM -c && objdump -Mintel -S $ASM.o > $ASM.S; =
done
; diff -u att.S intel.S
...
-=C2=A0 33:=C2=A0 42 8d 04 05 ff ff ff=C2=A0=C2=A0=C2=A0 lea=C2=A0=C2=A0=
=C2=A0 eax,[r8*1-0x1]
...
+=C2=A0 33:=C2=A0 41 8d 40 ff=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 lea=C2=A0=C2=A0=C2=A0 eax,[r8-0x1]
...
-=C2=A0 6b:=C2=A0 8d 04 05 01 00 00 00=C2=A0=C2=A0=C2=A0 lea=C2=A0=C2=A0=
=C2=A0 eax,[rax*1+0x1]
...
+=C2=A0 6b:=C2=A0 8d 40 01=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 lea=C2=A0=C2=A0=C2=A0 eax,[rax+=
0x1]
...

With -masm=3Datt, there is:
...
=C2=A0=C2=A0=C2=A0 leal=C2=A0=C2=A0=C2=A0 -1(,%r8), %eax
...
=C2=A0=C2=A0=C2=A0 leal=C2=A0=C2=A0=C2=A0 1(,%rax), %eax
...

which then GNU AS encodes with the SIB byte, making it longer, even at -Os=


Is this:
1) gcc issue
2) binutils/as issue
3) my issue
?

Thank you,
Zdenek