diff mbox

[v2] tools: detect appropriate debug optimization level

Message ID 1461077836-7735-1-git-send-email-cardoe@cardoe.com (mailing list archive)
State New, archived
Headers show

Commit Message

Douglas Goldstein April 19, 2016, 2:57 p.m. UTC
When building debug use -Og as the optimization level if its available,
otherwise retain the use of -O0. -Og has been added by GCC to enable all
optimizations that to not affect debugging while retaining full
debugability.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
---
 tools/Rules.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Ian Jackson April 22, 2016, 4:08 p.m. UTC | #1
Doug Goldstein writes ("[PATCH v2] tools: detect appropriate debug optimization level"):
> When building debug use -Og as the optimization level if its available,
> otherwise retain the use of -O0. -Og has been added by GCC to enable all
> optimizations that to not affect debugging while retaining full
> debugability.
...
> -CFLAGS += -O0 -g3
> +CFLAGS += $(call cc-option,$(CC),-Og,-O0)
> +CFLAGS += -g3

I think CFLAGS is a variable which is expanded late, at each reference
site - a `recursively expanded' variable.

The result is that the call to the compiler to test the -Og flag
(implied by cc-option) will be executed potentially for every C source
code file!

I think you need to use cc-option-add.

Ian.
diff mbox

Patch

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 9ef0b47..4162bd9 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -137,7 +137,8 @@  SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
 
 ifeq ($(debug),y)
 # Disable optimizations and enable debugging information for macros
-CFLAGS += -O0 -g3
+CFLAGS += $(call cc-option,$(CC),-Og,-O0)
+CFLAGS += -g3
 # But allow an override to -O0 in case Python enforces -D_FORTIFY_SOURCE=<n>.
 PY_CFLAGS += $(PY_NOOPT_CFLAGS)
 endif