gcc flags for developers (Re: [PATCH] a little optimization of KJS GarbageCollector)

Allan Sandfeld Jensen kde at carewolf.com
Wed Dec 7 14:03:47 GMT 2005

On Friday 02 December 2005 14:07, David Faure wrote:
> Can we change the defaults so that reasonable/useful flags are being used
> then?
> Problem is, I see two possibilities, for developers:
> 1) with debug but with -O0 so that gcc runs fast   (or does -O1 make gcc
> fast enough?) 2) with debug 
-O1 is sometimes faster than -O0, because the result is smaller and therefore 
takes shorter time to write to disk.
We should sometime try and benchmark compiling kdelibs with -O0, -O1, -Os, -O2 
and -O2 -fno-expensive-optimizations

> and with "-O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline" so that
> the code runs faster and so that all warnings can be seen.
> Does this mean it would make sense to have
>  --enable-debug=fast for the first one,  and make --enable-debug select the
> second one?
> or maybe
>  --enable-debug=fast for the first one and --enable-debug=optimized for the
> second one, to keep the current --enable-debug as -O2 -g? Although I don't
> see any point in leaving things unchanged 'for historical reasons' if
> everyone agrees that it's wrong that way.
> Not everyone is a gcc expert, we should select the right flags so that
> developers don't have to care about all this.

It also depends on what you need debug-info for. If you only use backtraces, 
and don't step through the code, you are best served with -g1.

In theory when you use ELF and DWARF2 debug info, -O2 -g should always give 
correct backtrace and step debuging. Unfortunately debug is often slightly 
broken. You could consider it gcc bugs, but fact is that every now and then 
O0 is needed, because new fancy optimizations breaks debugging in small ways. 
The reason O0 does so much better is because of the absolutely insane naive 
way it generates code:
A simple plus operator in O0 is
 Load variable 1 from stack
 Load variable 2 from stack
 Add variables in registers
 Store result on stack

Where that leaves us I don't know. I use O2 -g1 and switches to -O0 -g3 when 
it occasitionally doesn't work.


More information about the kde-core-devel mailing list