From mboxrd@z Thu Jan 1 00:00:00 1970 From: der.herr@hofr.at (Nicholas Mc Guire) Date: Mon, 21 Mar 2016 09:51:51 +0000 Subject: Is it possible to turn off the gcc optimization when compiling kernel? In-Reply-To: References: Message-ID: <20160321095151.GB7516@osadl.at> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org 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