All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Keith A. Prickett" <keithp@marvell.com>
To: Adrian Bunk <bunk@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Building Kernel with -O0
Date: Tue, 09 Sep 2008 10:10:40 -0700	[thread overview]
Message-ID: <1220980240.17292.15.camel@CV-LAB2> (raw)
In-Reply-To: <20080909160452.GB30160@cs181140183.pp.htv.fi>

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.  



  reply	other threads:[~2008-09-09 17:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-04 17:50 Building Kernel with -O0 Keith A. Prickett
2008-09-09 16:04 ` Adrian Bunk
2008-09-09 17:10   ` Keith A. Prickett [this message]
2008-09-09 18:55     ` linux-os (Dick Johnson)
2008-09-09 19:24     ` Andi Kleen
2008-09-09 19:43       ` Adrian Bunk
2008-09-09 20:05         ` Andi Kleen
2008-09-09 22:24   ` David Howells
2008-09-25 13:31     ` Adrian Bunk
2008-09-25 13:51       ` David Howells
     [not found] <fa.NLANnOwj/8iuI5QjLt63gFrBDJA@ifi.uio.no>
2008-09-04 23:40 ` Robert Hancock
     [not found] <b8rB2-6BM-1@gated-at.bofh.it>
     [not found] ` <badXc-7gl-21@gated-at.bofh.it>
     [not found]   ` <baf2M-bE-7@gated-at.bofh.it>
     [not found]     ` <bagBJ-20J-7@gated-at.bofh.it>
2008-09-10 11:52       ` Bodo Eggert
2008-09-12  5:21         ` emin ak
2008-09-12 13:23           ` linux-os (Dick Johnson)
2008-09-12 14:45             ` linux-os (Dick Johnson)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1220980240.17292.15.camel@CV-LAB2 \
    --to=keithp@marvell.com \
    --cc=bunk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.