Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 146 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to disable compiler optimizations in gcc?

#1
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.
Reply

#2
You can disable optimizations if you pass -O0 with the gcc command-line.

E.g. to turn a .C file into a .S file call:


gcc -O0 -S test.c
Reply

#3
For gcc you want to omit any **-O1 -O2** or **-O3** options passed to the compiler or if you already have them you can append the **-O0** option to turn it off again. It might also help you to add **-g** for debug so that you can see the c source and disassembled machine code in your debugger.

See also:

[To see links please register here]

Reply

#4
To test without copy elision and see you copy/move constructors/operators in action add "-fno-elide-constructors".

Even with no optimizations (-O0 ), GCC and Clang will still do copy elision, which has the effect of skipping copy/move constructors in some cases. See [this question][1] for the details about copy elision.

However, in Clang 3.4 it does trigger a bug (an invalid temporary object without calling constructor), which is fixed in 3.5.


[1]:

[To see links please register here]

Reply

#5
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][1] for much more.

[1]:

[To see links please register here]

Reply

#6
Long time ago, but still needed.

info -

[To see links please register here]

list - gcc -Q --help=optimizers test.c | grep enabled
disable as many as you like with:
gcc **-fno-web** -Q --help=optimizers test.c | grep enabled
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through