2

I am trying to compile Linux kernel with -O0 flag for debugging (to disable optimization like inline functions support in GCC otherwise I am getting random jumps/holes in stack-frames).

I did some googling and found few related posts but they were not very encouraging for this idea. Some of the said its not possible, others suggested that it may not be very useful. I also saw few patches (for ARM) floating in KGDB mailing list. Now I am little confused. Just wondering if anyone tried compiling latest kernel with -O0 flag.

My Linux version: Linux 3.0.1-rt11-svn9237 #2 PREEMPT RT Fri Dec 21 09:58:42 IST 2012 armv7l GNU/Linux

My GCC version: arm-none-linux-gnueabi-gcc-4.3.3

Satpal Parmar
  • 361
  • 3
  • 12
  • Try `-O1` level, it has inlining disabled. – osgx Jan 24 '13 at 04:30
  • As of gcc 4.8, there is a `-Og` option. It enables all optimizations that do not interfere with debugging. Probably some of the answer will depend on the *architecture*. It is also possible to give options to **individual files** in a kernel Makefile. See [kbuild makefile docs](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/kbuild/makefiles.txt), section 3.7. For example, `ccflags-$(CONFIG_MY_MODULE) = -Og`. – artless noise Dec 09 '13 at 15:42
  • @Satpal, did you find a way to disable -O2 in kernel compile for debug? I met the same issue. Thanks! – Howard Shane Jan 30 '17 at 23:01
  • Possible duplicate of [How to de-optimize the Linux kernel](http://stackoverflow.com/questions/29151235/how-to-de-optimize-the-linux-kernel) , I don't think cross compilation is the main problem. – Ciro Santilli OurBigBook.com Feb 18 '17 at 19:27

0 Answers0