1 |
On 8/23/06, Michael Hennebry <hennebry@×××××××××××××××××.edu> wrote: |
2 |
> Perhaps I misunderstood the preceeding. |
3 |
> I'd taken it to mean that recompiling any package with gentoo tools |
4 |
> would result in -Os being replaced by -O2 . |
5 |
|
6 |
Sorry if I wasn't clear. I'm only referring to the build of gcc itself here. |
7 |
|
8 |
To try and clarify, when you set CFLAGS in make.conf, you are really |
9 |
telling portage what you would /like/ to use to build programs. They |
10 |
are, in effect, just the default settings. |
11 |
|
12 |
A particular ebuild is allowed to remove, replace, or even add its own |
13 |
flags as the maintainer of that package sees fit. There are many |
14 |
packages that do this, and gcc is one of them. |
15 |
|
16 |
> What would break with -Os that wouldn't break with -O2? |
17 |
> I was under the impression that both flags only allowed |
18 |
> changes that didn't affect the output. |
19 |
|
20 |
No, the output *is* allowed to change based on -Os, -O2, or -O3. This |
21 |
is the entire point of optimizations, after all. What is *not* |
22 |
allowed to change is the ABI. |
23 |
|
24 |
For example, glibc contains a very freqeuntly used function called |
25 |
"printf". Any program that wants to call printf needs to pass it |
26 |
arguments to tell it what to print. The method of passing those |
27 |
arguments and the return value (such as the order of the arguments, |
28 |
their alignment in memory, how the stack is managed, etc) is known as |
29 |
an ABI (application binary interface). And the ABI is not allowed to |
30 |
change based on CFLAGS, or a program compiled with -O3 could have |
31 |
trouble calling printf in a glibc compiled with -Os. |
32 |
|
33 |
Now, the actual implementation of printf...how many processor |
34 |
registers it uses, the order of the instructions within the function, |
35 |
whether loops are expanded, how it calculates floating point numbers |
36 |
(not really applicable to printf..but bear with me) etc...those things |
37 |
are allowed to be changed by CFLAGS. |
38 |
|
39 |
So when we talk about optimizations breaking code, we are talking |
40 |
about the implementation of functions. With unsafe flags, the |
41 |
compiler can make bad choices in some cases like trying to use the |
42 |
result of a calculation before the calculation is made, dereferencing |
43 |
a memory address before the correct address is actually known, etc. |
44 |
|
45 |
HTH, |
46 |
-Richard |
47 |
-- |
48 |
gentoo-user@g.o mailing list |