On 8/23/06, Michael Hennebry <[EMAIL PROTECTED]> wrote:
Perhaps I misunderstood the preceeding.
I'd taken it to mean that recompiling any package with gentoo tools
would result in -Os being replaced by  -O2 .

Sorry if I wasn't clear.  I'm only referring to the build of gcc itself here.

To try and clarify, when you set CFLAGS in make.conf, you are really
telling portage what you would /like/ to use to build programs.  They
are, in effect, just the default settings.

A particular ebuild is allowed to remove, replace, or even add its own
flags as the maintainer of that package sees fit.  There are many
packages that do this, and gcc is one of them.

What would break with -Os that wouldn't break with -O2?
I was under the impression that both flags only allowed
changes that didn't affect the output.

No, the output *is* allowed to change based on -Os, -O2, or -O3.  This
is the entire point of optimizations, after all.  What is *not*
allowed to change is the ABI.

For example, glibc contains a very freqeuntly used function called
"printf".  Any program that wants to call printf needs to pass it
arguments to tell it what to print.  The method of passing those
arguments and the return value (such as the order of the arguments,
their alignment in memory, how the stack is managed, etc) is known as
an ABI (application binary interface).  And the ABI is not allowed to
change based on CFLAGS, or a program compiled with -O3 could have
trouble calling printf in a glibc compiled with -Os.

Now, the actual implementation of printf...how many processor
registers it uses, the order of the instructions within the function,
whether loops are expanded, how it calculates floating point numbers
(not really applicable to printf..but bear with me) etc...those things
are allowed to be changed by CFLAGS.

So when we talk about optimizations breaking code, we are talking
about the implementation of functions.  With unsafe flags, the
compiler can make bad choices in some cases like trying to use the
result of a calculation before the calculation is made, dereferencing
a memory address before the correct address is actually known, etc.

HTH,
-Richard
--
[email protected] mailing list

Reply via email to