如何在Intel语法中生成带有clang的汇编代码?

时间:2022-11-23 10:04:25

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?

正如这个问题所示,使用g++,我可以使用g++ -S -masm=intel test.cpp。同样,在clang的帮助下,我可以做clang++ -S测试。但是-masm=intel不支持clang(编译期间未使用的警告参数:-masm=intel)。如何使用clang获得intel语法?

3 个解决方案

#1


90  

This should get clang to emit assembly code with Intel syntax:

这会让clang发出带有Intel语法的汇编代码:

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.

您可以使用-mllvm 从clang命令行传入llvm选项。遗憾的是,这个选项似乎没有很好的文档说明,因此我只能通过浏览llvm邮件列表找到它。


As noted below by @thakis, this is no longer needed in newer versions of Clang (3.5+) as it now support the -masm=intel syntax.

正如@thakis在下面指出的,在Clang(3.5+)的新版本中不再需要这一点,因为它现在支持-masm=intel语法。

#2


28  

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

在clang r208683 (clang 3.5+)中,它理解-masm=intel。如果你的clang足够新,你可以用它。

#3


16  

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.

假设您可以让Clang发出正常的LLVM字节码,然后您可以使用llc编译到汇编语言,并使用它的——x86- asn -语法=intel选项来获得intel语法的结果。

#1


90  

This should get clang to emit assembly code with Intel syntax:

这会让clang发出带有Intel语法的汇编代码:

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.

您可以使用-mllvm 从clang命令行传入llvm选项。遗憾的是,这个选项似乎没有很好的文档说明,因此我只能通过浏览llvm邮件列表找到它。


As noted below by @thakis, this is no longer needed in newer versions of Clang (3.5+) as it now support the -masm=intel syntax.

正如@thakis在下面指出的,在Clang(3.5+)的新版本中不再需要这一点,因为它现在支持-masm=intel语法。

#2


28  

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

在clang r208683 (clang 3.5+)中,它理解-masm=intel。如果你的clang足够新,你可以用它。

#3


16  

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.

假设您可以让Clang发出正常的LLVM字节码,然后您可以使用llc编译到汇编语言,并使用它的——x86- asn -语法=intel选项来获得intel语法的结果。