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.