How compatible are the various gcc -O flags?
On Freitag 06 November 2009, email@example.com wrote:
> How compatible are the various gcc optimization flags? Are they
> internal to a single program, do they affect library calls? Can some
> packages be made with one flag and still work with other packages made
> with other flags?
> Let me make up some completely fake examples. Suppose -Ox unrolls
> loops. I can't see how any other code could ever notice, so it would
> be perfectly fine to mix and match packages which have and don't have
> this optimization.
> Suppose -Oz changes the order of passing parameters on the stack
> because someone found a 0.3% speedup if the first parameter was first
> instead of last (or vice versa). Quite obviously this would be fatal
> for a -Oz package to call a non-Oz package. But suppose this
> optimization was only done inside static functions which were not
> visible to outside callers -- then it would be ok to mix.
> What brings this up is having changed CFLAGS to -O3 some time ago, I
> know not why. I found it by accident when a glib emerge made hald
> stop working which prevented X from running. Suppose I want to change
> this to -Os, or -O2, or -O1, or any of the other optimization flags,
> like -fomit-frame-pointer. What flags are incompatible with others?
> My gut feeling is that there aren't any such flags, otherwise how
> could you ever recompile anything except as cross platform? But then,
> maybe certain packages are set to filter certain flags, maybe gcc and
> the tool chain do this to isolate themselves from dangerous flags.
the O levels are compatible. Almost all flags are, except mrec-parm or what it
was called. man gcc can answer that for you.