Re: am i right
From: Jean-David Beyer (jdbeyer_at_exit109.com)
Date: 04/25/04
- Next message: not_at_top-post: "Install GUI doesn't need X-setup pain ?"
- Previous message: Sebastian Hans: "Re: show the size of diffrent folders"
- In reply to: Michael Heiming: "Re: am i right"
- Next in thread: Michael Heiming: "Re: am i right"
- Reply: Michael Heiming: "Re: am i right"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 25 Apr 2004 08:35:21 -0400
Michael Heiming wrote:
>>>1.
>>>I compile my source code using gcc 2.95.3 and I use "-g" option along with
>>>O2 ( optimization flag ). I then "strip" the executable and give it a run.
>>>
>>>2.
>>>And then I compiled same source code _without_ "-g" option and "strip" the
>>>executable (even though not useful) and give it a run.
>>>
>>>I found that performance of the code is better when I dont use "-g".
>>>
>>>How is this possible ?
>>>Does -g hampers the -O2 level of optimations ?
>
> [..]
>
>
>>So the only problem with -g was larger object files, because the symbol
>>table was in them. But the OS did not load the symbol table (only gdb
>>looked at it), so it did not waste RAM with it.
>
>
> From 'man gcc', you get the feeling that albeit gcc can work with
> -g and -O, at the same time, unlike many other C compiler, it
> might return unexpected results.
>
Not the impression I get. What they are referring to is that _gdb_ may
return unexpected results, not that _the program_ will return unexpected
results.
Programmers frequently complained that the optimizer was buggy when it
was not. The rule for optimizers is that _for correct programs_ you will
get the same results whether optimization was used or not. It is silent
on what happens to incorrect programs.
Now there are a lot of incorrect programs out there that seem to work.
And when optimized, they work differently. This is most often because
values of variables were used that never had values assigned to them.
This happens when automatic register allocation is done, for example.
Remember the "register" statement in C for example? It turns out that
programmers almost always put the wrong variables into registers, and
that they do not overload registers. A good optimizer ignores register
statements and puts the "best" variables into registers. Furthermore,
the same register can be used for more than one variable (perhaps
because one variable needed it during one part of a function's execution
and another variable needed it during another part of the function's
execution). Now if someone uses a variable that has no value assigned
and does not optimize, they get the value in .bss memory or something on
the stack. If they optimize it and it gets assigned to a register, they
get whatever was left in the register, which may be different from
before. The programmer then complains about the optimizer when what he
should do is fix his program.
But as far as debugging is concerned, it is gdb that returns surprising
results. Say you put a breakpoint in a function and the function body is
loaded into memory even though it is sometimes expanded inline. Then if
a programmer sets a breakpoint in the function with gdb, it will stop
there only when the function body is executed, and not when the
inline-expanded instance is executed. So it will not stop.
Another case occurs when some code is totally eliminated (based on
live-dead analysis, for example) where the optimizer notices a value is
not used, so it deletes the code that computes its value. If you try to
put a breakpoint on it, gdb will refuse.
I could go on, but I hope I need not.
-- .~. Jean-David Beyer Registered Linux User 85642. /V\ Registered Machine 241939. /( )\ Shrewsbury, New Jersey http://counter.li.org ^^-^^ 08:20:00 up 2 days, 9:02, 4 users, load average: 4.15, 4.13, 4.08
- Next message: not_at_top-post: "Install GUI doesn't need X-setup pain ?"
- Previous message: Sebastian Hans: "Re: show the size of diffrent folders"
- In reply to: Michael Heiming: "Re: am i right"
- Next in thread: Michael Heiming: "Re: am i right"
- Reply: Michael Heiming: "Re: am i right"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|