你如何从GCC C / C ++源代码汇编输出? [英] How do you get assembler output from C/C++ source in gcc?

查看:442
本文介绍了你如何从GCC C / C ++源代码汇编输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎样才能做到这一点?

如果我要分析的东西是如何得到编译,我怎么会得到发射装配code?

If I want to analyze how something is getting compiled, how would I get the emitted assembly code?

推荐答案

使用 -S 选项的gcc(或g ++)。

Use the -S option to gcc (or g++).

gcc -S helloworld.c

这将运行preprocessor(CPP)超过helloworld.c,执行初始编译,然后停止汇编程序运行之前。

This will run the preprocessor (cpp) over helloworld.c, perform the initial compilation and then stop before the assembler is run.

在默认情况下这将输出文件 helloworld.s 。输出文件仍然可以使用 -o 选项来设置。

By default this will output a file helloworld.s. The output file can be still be set by using the -o option.

gcc -S -o my_asm_output.s helloworld.c

当然,如果你有原始的源这仅适用。
如果你只有生成的对象文件另一种方法是 objdump的,通过设置使用 - 拆卸选项(或 -d 的缩写形式)。

Of course this only works if you have the original source. An alternative if you only have the resultant object file is to use objdump, by setting the --disassemble option (or -d for the abbreviated form).

objdump -S --disassemble helloworld > helloworld.dump

如果调试选项的目标文件( -g 在编译时)启用,该文件并没有被剥夺,此选项最有效。

This option works best if debugging option is enabled for the object file (-g at compilation time) and the file hasn't been stripped.

运行文件的HelloWorld 会给你一些迹象显示细节,您将使用objdump的得到的水平。

Running file helloworld will give you some indication as to the level of detail that you will get by using objdump.

这篇关于你如何从GCC C / C ++源代码汇编输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆