All of lore.kernel.org
 help / color / mirror / Atom feed
* Is it possible to turn off the gcc optimization when compiling kernel?
@ 2016-03-20  6:46 Hao Lee
  2016-03-21  9:51 ` Nicholas Mc Guire
  0 siblings, 1 reply; 5+ messages in thread
From: Hao Lee @ 2016-03-20  6:46 UTC (permalink / raw)
  To: kernelnewbies

Hi,
When I am debugging the linux kernel, I find that the execution
sequence of some code is very strange. I think I need to turn off gcc
optimization by  changing "-O2" to "-O0". But I encounter many errors.
So, I want to know is it possible to turn off the gcc optimization or
how can I compile some functions without optimization.
Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Is it possible to turn off the gcc optimization when compiling kernel?
  2016-03-20  6:46 Is it possible to turn off the gcc optimization when compiling kernel? Hao Lee
@ 2016-03-21  9:51 ` Nicholas Mc Guire
  2016-03-22 11:24   ` Hao Lee
  0 siblings, 1 reply; 5+ messages in thread
From: Nicholas Mc Guire @ 2016-03-21  9:51 UTC (permalink / raw)
  To: kernelnewbies

On Sun, Mar 20, 2016 at 02:46:41PM +0800, Hao Lee wrote:
> Hi,
> When I am debugging the linux kernel, I find that the execution
> sequence of some code is very strange. I think I need to turn off gcc
> optimization by  changing "-O2" to "-O0". But I encounter many errors.
> So, I want to know is it possible to turn off the gcc optimization or
> how can I compile some functions without optimization.

You can not turn it off in all functions as some need particluar 
optimization flags to comile at all, but you can pass 
individual CFLAGS per file via the Makefile

CFLAGS_target.o = -O0 or -flags-to-use

aswell as remove specific CFLAGS with

CFLAGS_REMOVE_target.o = -flags-to-remove

but if you want to debug the kernel it is most likely not
a good idea to try and disable optimization as the code you then
are debugging might not have that much to do with the final code
once optimization is on again. So simply generate the .lst file
of the target you are trying to debug e.g. for kernel/sched/core.c:

make kernel/sched/core.lst

and then use that .lst file to understand the output of gdb you
are inspecting.

thx!
hofrat

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Is it possible to turn off the gcc optimization when compiling kernel?
  2016-03-21  9:51 ` Nicholas Mc Guire
@ 2016-03-22 11:24   ` Hao Lee
  2016-03-22 11:35     ` Nicholas Mc Guire
  0 siblings, 1 reply; 5+ messages in thread
From: Hao Lee @ 2016-03-22 11:24 UTC (permalink / raw)
  To: kernelnewbies

On Mon, Mar 21, 2016 at 5:51 PM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> You can not turn it off in all functions as some need particluar
> optimization flags to comile at all, but you can pass
> individual CFLAGS per file via the Makefile
>
> CFLAGS_target.o = -O0 or -flags-to-use
>
> aswell as remove specific CFLAGS with
>
> CFLAGS_REMOVE_target.o = -flags-to-remove
>
> but if you want to debug the kernel it is most likely not
> a good idea to try and disable optimization as the code you then
> are debugging might not have that much to do with the final code
> once optimization is on again. So simply generate the .lst file
> of the target you are trying to debug e.g. for kernel/sched/core.c:
>
> make kernel/sched/core.lst
>
> and then use that .lst file to understand the output of gdb you
> are inspecting.

Thanks for your reply!
Besides,I also find that use "gcc -c -Q -O1 --help=optimizers" can
print the exact set of optimizations.

regards,
Hao Lee

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Is it possible to turn off the gcc optimization when compiling kernel?
  2016-03-22 11:24   ` Hao Lee
@ 2016-03-22 11:35     ` Nicholas Mc Guire
  2016-03-22 11:46       ` Hao Lee
  0 siblings, 1 reply; 5+ messages in thread
From: Nicholas Mc Guire @ 2016-03-22 11:35 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Mar 22, 2016 at 07:24:38PM +0800, Hao Lee wrote:
> On Mon, Mar 21, 2016 at 5:51 PM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> > You can not turn it off in all functions as some need particluar
> > optimization flags to comile at all, but you can pass
> > individual CFLAGS per file via the Makefile
> >
> > CFLAGS_target.o = -O0 or -flags-to-use
> >
> > aswell as remove specific CFLAGS with
> >
> > CFLAGS_REMOVE_target.o = -flags-to-remove
> >
> > but if you want to debug the kernel it is most likely not
> > a good idea to try and disable optimization as the code you then
> > are debugging might not have that much to do with the final code
> > once optimization is on again. So simply generate the .lst file
> > of the target you are trying to debug e.g. for kernel/sched/core.c:
> >
> > make kernel/sched/core.lst
> >
> > and then use that .lst file to understand the output of gdb you
> > are inspecting.
> 
> Thanks for your reply!
> Besides,I also find that use "gcc -c -Q -O1 --help=optimizers" can
> print the exact set of optimizations.
>
yes - but for any given code you will find that many of those
options actually have no effect for the particular code blob.
The set of flags effectively impacting the generated object
file is generally much smaller than the ones reported by
gcc -c -Q -O1 --help=optimizers.

thx!
hofrat 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Is it possible to turn off the gcc optimization when compiling kernel?
  2016-03-22 11:35     ` Nicholas Mc Guire
@ 2016-03-22 11:46       ` Hao Lee
  0 siblings, 0 replies; 5+ messages in thread
From: Hao Lee @ 2016-03-22 11:46 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Mar 22, 2016 at 7:35 PM, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> yes - but for any given code you will find that many of those
> options actually have no effect for the particular code blob.
> The set of flags effectively impacting the generated object
> file is generally much smaller than the ones reported by
> gcc -c -Q -O1 --help=optimizers.
>
> thx!
> hofrat

yeah,only several options take effect.
Because "-O0" will break the link progress,I just want use "-O1" and
some other options to approximate the effects of "-O0".

regards,
Hao Lee

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-03-22 11:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-20  6:46 Is it possible to turn off the gcc optimization when compiling kernel? Hao Lee
2016-03-21  9:51 ` Nicholas Mc Guire
2016-03-22 11:24   ` Hao Lee
2016-03-22 11:35     ` Nicholas Mc Guire
2016-03-22 11:46       ` Hao Lee

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.