Re: Building Kernel with -O0

From: Adrian Bunk
Date: Tue Sep 09 2008 - 15:44:59 EST


On Tue, Sep 09, 2008 at 09:24:58PM +0200, Andi Kleen wrote:
> "Keith A. Prickett" <keithp@xxxxxxxxxxx> writes:
> >
> > 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"?
>
> Traditionally it was not allowed because -O0 didn't inline and
> the kernel relied on inlining in some cases. But with always_inline
> that is obsolete -- all functions that rely on inlining should be
> marked __always_inline.
>
> I think a few more cases crept in where it was common to write
> build time asserts as
>
> if (some condition the compiler evaluates at runtime)
^^^^^^^
buildtime

> __error_condition_xyz_is_false();
>
> and this obviously relies on the optimizer to build. But these
> are all slowly moving over the BUILD_BUG_ON() which also doesn't
> rely on the optimizer, so it's also obsolete.
>...

The reason why it works for Keith at all seems to be that even with -O0
gcc already does this kind of optimizations.

Check e.g. the assembler generated for the following
(userspace) program with -O0:

<-- snip -->

int foobar;

int main()
{
if (1) return 0;

foobar = 12345;

return 42;
}

<-- snip -->

> Hope this helps,
>
> -Andi

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

--
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/