assembly syntax

Hi clangers,

I'm not sure but looks like the default syntax used by clang when it
outputs assembly is AT&T. Is that right?

For this simple program:

$ cat add.c
int add(int a, int b) {
  return a + b;
}

$ clang -S add.c
$ cat add.s
.globl add
add:
        pushq %rbp
        movq %rsp, %rbp
        movl %edi, -4(%rbp)
        movl %esi, -8(%rbp)
        movl -4(%rbp), %esi
        addl -8(%rbp), %esi
        movl %esi, %eax
        popq %rbp
        retq

But yasm does not seem to like that syntax. What is the default syntax
used by yasm? Sorry for the ignorance here, I swear I tried to find
this info in my preferred search engine.

$ cp add.s add.asm
$ yasm -f elf64 add.asm -o add.o
add.asm:1: warning: no non-local label before `.globl'
add.asm:2: error: unexpected `:' after instruction
add.asm:3: error: instruction expected after label
add.asm:4: error: unexpected `%' after instruction
add.asm:5: error: instruction expected after label
add.asm:6: error: instruction expected after label
add.asm:7: error: instruction expected after label
add.asm:8: error: instruction expected after label
add.asm:9: error: instruction expected after label
add.asm:10: error: instruction expected after label

If I pass -p gas it works:

$ yasm -f elf64 -p gas add.asm -o add_def.o
# works!

How can I change the syntax used by clang, so yasm accepts it without
having to pass -p gas?

$ uname -p
x86_64

Linux Ubuntu 12.04 in case someone wants to ask.

How can I change the syntax used by clang, so yasm accepts it without
having to pass -p gas?

No way. yasm uses nasm syntax by default.

Not to hi-jack this thread, but if anyone was ever interested to take on adding yasm/nasm syntax parsing to MC. PathScale may be willing to sponsor this work. The author of yasm is unavailable to help, but we do have a some code which isn't public that may be of help to anyone interested in doing this.

(ping me offlist please)

So the solution seems to be use 'as'.

This worked for me:

$ clang -S -O0 -masm=intel add.c -o add-intel.s
$ cat add-intel.s
.globl add
add:
push rbp
mov rbp, rsp
mov dword ptr [rbp - 4], edi
mov dword ptr [rbp - 8], esi
mov esi, dword ptr [rbp - 4]
add esi, dword ptr [rbp - 8]
mov eax, esi
pop rbp
ret

$ as -mnaked-reg -msyntax=intel add-intel.s -o add_def.o

Simpler, this also worked:

$ clang -S -O0 add.c -o add-att.s
$ cat add-att.s
.globl add
add:
pushq %rbp
movq %rsp, %rbp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl -4(%rbp), %esi
addl -8(%rbp), %esi
movl %esi, %eax
popq %rbp
retq
$ as add-att.s -o add_def.o

The assembly support in LLVM is all oriented around gas-compatibility. We have some support for Intel syntax assembly, but even in that area, we can only parse gas style directives.