As this question shows, with g++, I can do g++ -S -masm=intel test.cpp
.
Also, with clang, I can do clang++ -S test.cpp
, but -masm=intel
is not supported by clang (warning argument unused during compilation: -masm=intel
). How do I get intel syntax with clang?
Asked
Active
Viewed 5.2k times
70
![](../../users/profiles/-1.webp)
Community
- 1
- 1
![](../../users/profiles/906773.webp)
Jesse Good
- 46,179
- 14
- 109
- 158
-
@JerryCoffin: Thanks, I generated a `.bc` file with clang and then sucessfully output the Intel assembly with `llc`. Mind making that an answer? – Jesse Good Jun 12 '12 at 03:39
-
Oh, I guess that's not a problem. – Jerry Coffin Jun 12 '12 at 03:45
3 Answers
116
As noted below by @thakis, newer versions of Clang (3.5+) accept the -masm=intel
argument.
For older versions, this should get clang to emit assembly code with Intel syntax:
clang++ -S -mllvm --x86-asm-syntax=intel test.cpp
You can use -mllvm <arg>
to pass in llvm options from the clang command line. Sadly this option doesn't appear to be well documented, and thus I only found it by browsing through the llvm mailing lists.
![](../../users/profiles/242814.webp)
Brennan Vincent
- 9,595
- 9
- 28
- 50
![](../../users/profiles/1172350.webp)
dcoles
- 2,848
- 1
- 21
- 21
-
3http://llvm.org/bugs/show_bug.cgi?id=17465 requests support for -masm=intel and beyond. – Trass3r Oct 22 '13 at 15:30
-
@dcoles Not working for clang 3.7. I executed `$clang -S -mllvm --x86-asm-syntax=intel file.c`. Am I doint something wrong here? It's not giving any error and silently exiting. – Saumya Suhagiya Aug 06 '15 at 16:28
-
1@saumya-suhagiya I've just confirmed that this still works with clang 3.8.0-svn244195-1~exp1. The command shown above will generate a file called `test.s`. You change this output location to a custom location using the `-o
` option. – dcoles Aug 06 '15 at 16:58 -
1@dcoles Hi, perhaps a not so smart question. Is it possible to compile and link the assembly code with `nasm`? – Alexander Cska Jan 29 '16 at 21:55
-
1@AlexanderCska I'm not sure this is possible without some manual fixup. While the syntax for NASM is similar to Intel's, there is some incompatibilities between them. – dcoles Feb 02 '16 at 23:20
46
As of clang r208683 (clang 3.5+), it understands -masm=intel
. So if your clang is new enough, you can just use that.
![](../../users/profiles/551986.webp)
thakis
- 4,306
- 27
- 31
-
It seems to me that the code generated by `-masm=intel` cannot be compiled by `clang` again? I am running clang 3.8. – Yai0Phah Jun 12 '19 at 11:56
17
Presuming you can have Clang emit normal LLVM byte codes, you can then use llc to compile to assembly language, and use its --x86-asm-syntax=intel
option to get the result in Intel syntax.
![](../../users/profiles/596781.webp)
Kerrek SB
- 428,875
- 83
- 813
- 1,025
![](../../users/profiles/179910.webp)
Jerry Coffin
- 437,173
- 71
- 570
- 1,035
-
Thanks again. I also found out `llc` by default turns optimizations on (-02) while gcc and clang use no optimizations (-O0) by default (it took me forever to figure out why the assembly output was different). – Jesse Good Jun 12 '12 at 04:18