[PATCH 2/2] Add option to use -Og

Sean Anderson sean.anderson at seco.com
Tue Feb 22 18:19:25 CET 2022


This adds support for using -Og when building U-Boot. According to the
gcc man page:

> -Og should be the optimization level of choice for the standard
> edit-compile-debug cycle, offering a reasonable level of optimization
> while maintaining fast compilation and a good debugging experience.

This optimization level is roughly -O1 minus a few additional
optimizations. It provides a noticably better debugging experience, with
many fewer variables <optimized out>.

Signed-off-by: Sean Anderson <sean.anderson at seco.com>
---

 Kconfig  | 6 ++++++
 Makefile | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/Kconfig b/Kconfig
index 8159c596c0..112745440b 100644
--- a/Kconfig
+++ b/Kconfig
@@ -90,6 +90,12 @@ config CC_OPTIMIZE_FOR_SPEED
 	  Enabling this option will pass "-O2" to gcc, resulting in a faster
 	  U-Boot image.
 
+config CC_OPTIMIZE_FOR_DEBUG
+	bool "Optimize for debugging"
+	help
+	  Enabling this option will pass "-Og" to gcc, enabling optimizations
+	  which don't interfere with debugging.
+
 endchoice
 
 config OPTIMIZE_INLINING
diff --git a/Makefile b/Makefile
index 1d3331c69f..7242eafc1e 100644
--- a/Makefile
+++ b/Makefile
@@ -688,6 +688,10 @@ ifdef CONFIG_CC_OPTIMIZE_FOR_SPEED
 KBUILD_CFLAGS	+= -O2
 endif
 
+ifdef CONFIG_CC_OPTIMIZE_FOR_DEBUG
+KBUILD_CFLAGS	+= -Og
+endif
+
 LTO_CFLAGS :=
 LTO_FINAL_LDFLAGS :=
 export LTO_CFLAGS LTO_FINAL_LDFLAGS
-- 
2.25.1



More information about the U-Boot mailing list