[英]How can I compile to assembly with gcc
How do I compile to assembly instead of an executable with gcc. 如何使用gcc编译为程序集而不是可执行文件。 I know there is an -S flag, but where do I use it in the makefile.
我知道有一个-S标志,但是在makefile中我在哪里使用它。 For example, if I use flags -O3 -o exe_name , where should I put the -S flag?
例如,如果我使用标志-O3 -o exe_name ,我应该在哪里放-S标志?
I suggest also using -fverbose-asm
because then the generated assembler has some generated comments which "explains" the code. 我建议也使用
-fverbose-asm
因为生成的汇编器有一些生成的注释,“解释”代码。 For example: 例如:
gcc -S -fverbose-asm -O2 foo.c
would generate in foo.s
(with some comments) the assembler code produced by compiling foo.c
将在
foo.s
生成(带有一些注释)通过编译foo.c
生成的汇编程序代码
And to understand what the GCC optimizations are doing one could even try -fdump-tree-all
(but this produces hundreds of files!). 要了解GCC优化正在做什么,甚至可以尝试
-fdump-tree-all
(但这会产生数百个文件!)。
You can ask GCC to produce the assembly file, instead of an object file (or an executable). 您可以要求GCC生成程序集文件,而不是目标文件(或可执行文件)。
For instance: 例如:
gcc -Wall -c test.c
Will produce an object file from test.c (test.o). 将从test.c(test.o)生成一个目标文件。
gcc -Wall -o test test.c
Will produce an executable file named 'test' from test.c 将从test.c生成一个名为'test'的可执行文件
gcc -Wall -S test.c
Will produce an assembly file from test.c (test.s) 将从test.c(test.s)生成一个程序集文件
Put it pretty much anywhere. 把它放在任何地方。
gcc -O3 -S -o output.asm ...
will store the generated assemby in output.asm
. 将存储在生成assemby
output.asm
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.