clang and intel syntax assembly

Hi,

I'm trying to make clang assemble an assembly file that clang generates, and
some weird issues happen. Here are steps to reproduce it.

- Here is the C code I was using:

#include <stdio.h>
char str = "HELLO WORLD";
int main() {
    printf("%s\n", str);
}

- Compile the code using clang with the following command. An assembly
manifest hello.s will be generated
clang -m32 -S -masm=intel hello.c -O1

- Assemble the asm file using clang:
clang -m32 -mllvm --x86-asm-syntax=intel hello.s

It fails with the following error output:

hello.s:10:2: error: invalid operand for instruction
        mov dword ptr [esp], str
        ^

I think clang should always accept the assembly file it generates. Is this a
bug? What workaround can be applied to make clang happy with the
instruction?

Thanks!

Best,
Fish

- Compile the code using clang with the following command. An assembly
manifest hello.s will be generated
clang -m32 -S -masm=intel hello.c -O1

- Assemble the asm file using clang:
clang -m32 -mllvm --x86-asm-syntax=intel hello.s

It fails with the following error output:

hello.s:10:2: error: invalid operand for instruction
        mov dword ptr [esp], str
        ^

I don't know if its your problem, but be careful of using Intel
syntax. You should prefer AT&T syntax. Also see "Inline assembly
operands don't work with .intel_syntax",
https://llvm.org/bugs/show_bug.cgi?id=24232.

We try to support Clang in a cross-platform library. On Windows we had
to break the compile and error with "Unsupported configuration"
because we have thousands of lines of Intel assembly meant to be
consumed by MS tools (or compatible tools). Clang would be fine if it
stopped pretending to be other compilers and took the code paths
written for it (on Windows Clang defines _MSC_VER and it wanders into
MS code paths).

Jeff

Hi Jeffrey,

Thank you very much for your timely response. Unfortunately, I don't think your answer is helpful for my issue in any way. I believe the behavior that I described in the previous email is a legit bug in Clang, or rather, in llvm-as.

For future reference, we ended up (reluctantly) converting all Intel syntax assembly files to AT&T style, and fed AT&T style assemblies to Clang. Involving an extra conversion and having ugly AT&T style output was sub-optimal, but it worked, and worked well.

Best,
Fish