How to generate assembly code with clang in Intel syntax?

C++AssemblyX86ClangIntel

C++ Problem Overview


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?

C++ Solutions


Solution 1 - C++

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.

Solution 2 - C++

As of clang r208683 (clang 3.5+), it understands -masm=intel. So if your clang is new enough, you can just use that.

Solution 3 - C++

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJesse GoodView Question on Stackoverflow
Solution 1 - C++dcolesView Answer on Stackoverflow
Solution 2 - C++thakisView Answer on Stackoverflow
Solution 3 - C++Jerry CoffinView Answer on Stackoverflow