How to compile Linux kernel with -O0 flag

Greg KH greg at kroah.com
Sat Aug 13 14:35:34 EDT 2016


On Sat, Aug 13, 2016 at 09:15:16PM +0300, Aleksander Alekseev wrote:
> Hello
> 
> I'm currently exploring different ways of debugging Linux kernel. And I
> noticed that for many variables gdb displays <optimized out>. Also from
> experience of debugging ring3 code I know that sometimes debugger may
> act crazy unless -O0 was used.
> 
> Apparently there is no corresponding option in `make menuconfig`. So
> how do you solve this problem? Just `CFLAGS=-O0 make ...` or somehow
> else? I wonder what is the "right" way of doing it because you know,
> it's a kernel, it can accidentally break something unless you are
> careful :)

The kernel will not run with -O0, sorry, just live with the build
optimization levels that is currently used and you should be fine.

But why do you want to use a debugger on the kernel?  That's not a
normal task unless you are bringing up a new hardware platform.

best of luck,

greg k-h



More information about the Kernelnewbies mailing list