diff mbox series

[2/2] Add option to use -Og

Message ID 20220222171925.1324520-2-sean.anderson@seco.com
State Accepted
Commit e97650437403c04da274200337de53968da20ab0
Delegated to: Tom Rini
Headers show
Series [1/2] Split CONFIG_CC_OPTIMIZE_FOR_SIZE into two configs | expand

Commit Message

Sean Anderson Feb. 22, 2022, 5:19 p.m. UTC
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@seco.com>
---

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

Comments

Simon Glass March 12, 2022, 2:25 a.m. UTC | #1
On Tue, 22 Feb 2022 at 10:20, Sean Anderson <sean.anderson@seco.com> wrote:
>
> 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@seco.com>
> ---
>
>  Kconfig  | 6 ++++++
>  Makefile | 4 ++++
>  2 files changed, 10 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

But how about an update in doc/ ?

Regards,
Simon
Sean Anderson March 14, 2022, 3:36 p.m. UTC | #2
On 3/11/22 9:25 PM, Simon Glass wrote:
> On Tue, 22 Feb 2022 at 10:20, Sean Anderson <sean.anderson@seco.com> wrote:
>>
>> 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@seco.com>
>> ---
>>
>>  Kconfig  | 6 ++++++
>>  Makefile | 4 ++++
>>  2 files changed, 10 insertions(+)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> But how about an update in doc/ ?

What should be updated? As far as I can tell, optimization level is not
otherwise documented. IMO the Kconfig does a reasonable job of
documentation.

--Sean
Tom Rini March 14, 2022, 3:46 p.m. UTC | #3
On Mon, Mar 14, 2022 at 11:36:54AM -0400, Sean Anderson wrote:
> 
> 
> On 3/11/22 9:25 PM, Simon Glass wrote:
> > On Tue, 22 Feb 2022 at 10:20, Sean Anderson <sean.anderson@seco.com> wrote:
> >>
> >> 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@seco.com>
> >> ---
> >>
> >>  Kconfig  | 6 ++++++
> >>  Makefile | 4 ++++
> >>  2 files changed, 10 insertions(+)
> > 
> > Reviewed-by: Simon Glass <sjg@chromium.org>
> > 
> > But how about an update in doc/ ?
> 
> What should be updated? As far as I can tell, optimization level is not
> otherwise documented. IMO the Kconfig does a reasonable job of
> documentation.

A follow-up to note somewhere under doc/ about this would be good.  I'll
pick up the series for next soon.
Tom Rini March 26, 2022, 2:46 a.m. UTC | #4
On Tue, Feb 22, 2022 at 12:19:25PM -0500, Sean Anderson wrote:

> 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@seco.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/next, thanks!
diff mbox series

Patch

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