如何在gcc中禁用编译器优化? [英] How to disable compiler optimizations in gcc?

查看:2286
本文介绍了如何在gcc中禁用编译器优化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习汇编语言。我已经搜索并找到了如何反汇编 .c 文件,但我认为它会生成一些优化版本的程序。是否有任何方法可以看到与我的C文件相对应的确切汇编代码。

解决方案

gcc选项 -O 启用不同级别的优化。使用 -O0 来禁用它们并使用 -S 输出程序集。 -O3 是最高级别的优化。



从gcc 4.8开始,优化级别 -Og 可用。它使优化不会干扰调试,并且是标准编辑 - 编译 - 调试周期的推荐默认设置。



要将程序集的方言更改为intel或att use -masm = intel -masm = att



您也可以使用 -fname 手动启用某些优化。 查看 gcc手册更多。


I am trying to learn assembly language. I have searched and found how to disassemble a .c file but I think it produces some optimized version of the program. Is there any way so that I can see the exact assembly code which corresponds to my C file.

解决方案

The gcc option -O enables different levels of optimization. Use -O0 to disable them and use -S to output assembly. -O3 is the highest level of optimization.

Starting with gcc 4.8 the optimization level -Og is available. It enables optimizations that do not interfere with debugging and is the recommended default for the standard edit-compile-debug cycle.

To change the dialect of the assembly to either intel or att use -masm=intel or -masm=att.

You can also enable certain optimizations manually with -fname.

Have a look at the gcc manual for much more.

这篇关于如何在gcc中禁用编译器优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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