Re: Building Kernel with -O0

From: Keith A. Prickett
Date: Tue Sep 09 2008 - 13:11:00 EST


On Tue, 2008-09-09 at 19:04 +0300, Adrian Bunk wrote:
> On Thu, Sep 04, 2008 at 10:50:53AM -0700, Keith A. Prickett wrote:
> >...
> > It seems building with optimization
> > level 0 should be a natural thing for kernel driver developers to do for
> > debugging purposes.
> >
> > In summary: I want to compile with optimizations off and the compile is
> > failing now when I try this. How can this be resolved?
> >...
>
> There are several places in the kernel where we e.g. rely on gcc
> removing dead code, and otherwise the linking of the kernel fails.
>
> Compiling with -O0 never worked, and is not likely to ever work.
I am currently running the kernel compiled with -O0. The final problem
I ran into was some NULL pointer dereference and compiling ONLY files in
the mm directory with -O2 fixed the issue.

To build with -O0 I had to change a few things (for my ARM
architecture):
1. Ensure the __attribute__((always_inline)) was turned off in the
"inline" #define (compiler.h)

2. Fix some inline assembly in kprobes (ARM only) that, due to no
optimization, needed more registers than the compiler had available.
(Similar to this issue:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13850)

3. Implement a fix as described here:
(http://lists.arm.linux.org.uk/lurker/message/20050201.210458.5cc93c10.en.html)

4. Change -O2 to -O0 in the root Makefile

5. Add extra cflags in the mm Makefile so it builds with -O2 only in
that directory.

All of this could, potentially be changed by a configuration parameter
and added into the kernel release. Does someone have a primer on why
this kind of behavior is not desired or "possible"?

Doing this has given me SO much visibility into stack variables data
values while single-stepping the code. I feel that the time invested to
make this work is well worth the return. In the book "Writing Solid
Code" (http://www.amazon.com/Writing-Solid-Code-Microsofts-Programming/dp/1556155514) one technique discussed is: stepping through your code. In order to be able to do this effectively you need optimizations turned off.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/