Is it needed or must to compile fs and driver with -O2 option when compiling kernel ? thanks!
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.
On Fri, Mar 22, 2013 at 09:55:53AM -0400, Valdis.Kletnieks@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 .
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.
On Fri, 22 Mar 2013 10:52:56 -0400, Valdis.Kletnieks@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.
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.
participants (2)
-
ishare -
Valdis.Kletnieks@vt.edu