kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* optimization in kernel compile
@ 2013-03-22  5:41 ishare
  2013-03-22 13:55 ` Valdis.Kletnieks at vt.edu
  0 siblings, 1 reply; 6+ messages in thread
From: ishare @ 2013-03-22  5:41 UTC (permalink / raw)
  To: kernelnewbies


  Is it  needed or must to compile fs and driver with -O2 option when compiling kernel ?

  thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* optimization in kernel compile
  2013-03-22  5:41 optimization in kernel compile ishare
@ 2013-03-22 13:55 ` Valdis.Kletnieks at vt.edu
  2013-03-22 14:32   ` ishare
  0 siblings, 1 reply; 6+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2013-03-22 13:55 UTC (permalink / raw)
  To: kernelnewbies

On Fri, 22 Mar 2013 13:41:25 +0800, ishare said:
>   Is it  needed or must to compile fs and driver with -O2 option when compiling kernel ?

It's not strictly mandatory to use -O2 (for a while, -Os was the default). There
are a few places that for correctness, you *cannot* use -O0. For instance, a
few places where we use builtin_return_address() inside an inline (-O0
won't inline so builtin_return_address() ends up returning a pointer to
a function when we want the function's parent).

Since gdb and friends are able to deal with -O2 compiled code just fine,
there's really no reason *not* to optimize the kernel.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130322/b33ab2fe/attachment.bin 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* optimization in kernel compile
  2013-03-22 13:55 ` Valdis.Kletnieks at vt.edu
@ 2013-03-22 14:32   ` ishare
  2013-03-22 14:52     ` Valdis.Kletnieks at vt.edu
  0 siblings, 1 reply; 6+ messages in thread
From: ishare @ 2013-03-22 14:32 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Mar 22, 2013 at 09:55:53AM -0400, Valdis.Kletnieks at vt.edu wrote:
> On Fri, 22 Mar 2013 13:41:25 +0800, ishare said:
> >   Is it  needed or must to compile fs and driver with -O2 option when compiling kernel ?
> 
> It's not strictly mandatory to use -O2 (for a while, -Os was the default). There
> are a few places that for correctness, you *cannot* use -O0. For instance, a
> few places where we use builtin_return_address() inside an inline (-O0
> won't inline so builtin_return_address() ends up returning a pointer to
> a function when we want the function's parent).
 
  So it will cause an error ?
> 
> Since gdb and friends are able to deal with -O2 compiled code just fine,
> there's really no reason *not* to optimize the kernel.

  the debug information will be stripped  by  -O2 ,for example ,you can not touch 
  the value of  some varibles at stack , and debugging will not run line by line,
  instead , the source jump in unexpectable order .

  

  

^ permalink raw reply	[flat|nested] 6+ messages in thread

* optimization in kernel compile
  2013-03-22 14:32   ` ishare
@ 2013-03-22 14:52     ` Valdis.Kletnieks at vt.edu
  2013-03-22 21:16       ` Valdis.Kletnieks at vt.edu
  0 siblings, 1 reply; 6+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2013-03-22 14:52 UTC (permalink / raw)
  To: kernelnewbies

On Fri, 22 Mar 2013 22:32:40 +0800, ishare said:

> > are a few places that for correctness, you *cannot* use -O0. For instance,
a
> > few places where we use builtin_return_address() inside an inline (-O0
> > won't inline so builtin_return_address() ends up returning a pointer to
> > a function when we want the function's parent).
>
>   So it will cause an error ?

Yes, there are places where failing to optimize causes errors.

Consider this code:

static inline foo (return builtin_return_address());

int bar ( x = foo());

If you don't optimize, x ends up with a pointer into bar.  If it
gets inlined because you're optimizing, x ends up pointing to bar's caller.
This breaks stuff like the function tracer.

> > Since gdb and friends are able to deal with -O2 compiled code just fine,
> > there's really no reason *not* to optimize the kernel.
>
>   the debug information will be stripped  by  -O2 ,for example ,you can not touch

No debug information is stripped by -O2.  Debug information isn't emitted if
you don't compile with -g.  At one time, long ago (quite possibly literally
"before you were born" for some of the younger readers on the list), gcc was
unable to generate -g output if the optimizer was invoked.  But that was
last century (gcc 2.95 era).

>   the value of  some varibles at stack , and debugging will not run line by line,
>   instead , the source jump in unexpectable order .

I'm probably going to piss a bunch of people off by saying this, but:

If your C skills aren't up to debugging code that's been compiled with
-O2, maybe you shouldn't be poking around inside the kernel.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130322/ac48344c/attachment-0001.bin 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* optimization in kernel compile
  2013-03-22 14:52     ` Valdis.Kletnieks at vt.edu
@ 2013-03-22 21:16       ` Valdis.Kletnieks at vt.edu
  2013-03-24  3:09         ` ishare
  0 siblings, 1 reply; 6+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2013-03-22 21:16 UTC (permalink / raw)
  To: kernelnewbies

On Fri, 22 Mar 2013 10:52:56 -0400, Valdis.Kletnieks at vt.edu said:

> No debug information is stripped by -O2.  Debug information isn't emitted if
> you don't compile with -g.  At one time, long ago (quite possibly literally
> "before you were born" for some of the younger readers on the list), gcc was
> unable to generate -g output if the optimizer was invoked.  But that was
> last century (gcc 2.95 era).

GCC 4.8 was officially released today (since I sent the previous note).

>From the release notes:

"A new general optimization level, -Og, has been introduced. It addresses the
need for fast compilation and a superior debugging experience while providing a
reasonable level of runtime performance. Overall experience for development
should be better than the default optimization level -O0."

The current Linus tree does build with 4.8.  I do *not* know if earlier
releases build correctly (or how far back), nor if -Og is sufficient
optimization to allow correct kernel functioning.  But it's something to
look at.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130322/4fbf18c9/attachment.bin 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* optimization in kernel compile
  2013-03-22 21:16       ` Valdis.Kletnieks at vt.edu
@ 2013-03-24  3:09         ` ishare
  0 siblings, 0 replies; 6+ messages in thread
From: ishare @ 2013-03-24  3:09 UTC (permalink / raw)
  To: kernelnewbies


  If I use -O2, then during debuging , a print command will get : value is optimized out !

  Is there mothod to get rid of this ?

  thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-03-24  3:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-22  5:41 optimization in kernel compile ishare
2013-03-22 13:55 ` Valdis.Kletnieks at vt.edu
2013-03-22 14:32   ` ishare
2013-03-22 14:52     ` Valdis.Kletnieks at vt.edu
2013-03-22 21:16       ` Valdis.Kletnieks at vt.edu
2013-03-24  3:09         ` ishare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).