Re: In GCC 10.2, -O2 optimization enables more than docs suggest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/20/21 7:56 AM, Richard Earnshaw via Gcc-help wrote:
On 16/01/2021 20:48, Brent Roman wrote:
Here's an example of a gcc invocation with -O2 followed by disabling all
the -O2 specific optimizations:
...

Sorry, it's not as simple as that.  There are places in the compiler
where the optimization level (O1, O2, O3) is just tested with something like

   if (optimize >= level)

for some level.

R.


Just chiming in with an opinion here. I've had the same problem and came to the same conclusion ("-f" options do not fully replace/override "-O") although I didn't know the compiler source was that explicit about it (thanks for the info).

I realize this is very unlikely to change but find the situation unfortunate. My use-case is with the GNU Arm Embedded Toolchain port of GCC and my https://github.com/thanks4opensource/regbits development system. The latter creates C++ header files with literally thousands of constexpr objects of which only a handful are used in a typical program. If compiled O1 or above, the linker only allocates storage for the objects that are used. At O0 it allocates all of them which makes the resulting binary far too large to fit in a typical embedded processor's memory space. But O0 is very useful for assembly-level debugging in GDB (often required in embedded development) because the generated code is much simpler and easier to correlate with the original C++ source.

I've only had limited success coming up with a set of -f options to add to O0 to eliminate the unused objects but retain the un-optimized binary code. The above explains why, but it would be nice if the -O options really were just a set of -f ones and users could customize to their needs. Without implementing my specific "-O0.5" option. ;)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux