Skip to contentSkip to conversation

tools: detect appropriate debug optimization level

PATCH In review Doug Goldstein 2 participants 4 messages Mar 13, 2018 – Mar 14, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 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.

---
 tools/Rules.mk | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/Rules.mk +7 -2
index 296b722372..3848bcf1f7 100644
@@ -164,8 +164,13 @@ LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libexten
 SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
 
 ifeq ($(debug),y)
-# Disable optimizations
-CFLAGS += -O0 -fno-omit-frame-pointer
+CFLAGS += -fno-omit-frame-pointer
+# Use optimizations compatible with debugging otherwise disable optimizations
+ifneq ($(call cc-option,$(CC),-Og,n),n)
+CFLAGS += -Og
+else
+CFLAGS += -O0
+endif
 # But allow an override to -O0 in case Python enforces -D_FORTIFY_SOURCE=<n>.
 PY_CFLAGS += $(PY_NOOPT_CFLAGS)
 else
Signature · 7 lines
2.16.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v4 1/1
#1 lore raw
Quoted 6 lines · Doug Goldstein

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.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Doug Goldstein
Quoted 17 lines · Doug Goldstein

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.

---
 tools/Rules.mk | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/Rules.mk +0 -0
index 296b722372..3848bcf1f7 100644
@@ -164,8 +164,13 @@ LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libexten
 SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
 

tools/Rules.mk LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libexten · line 173

Quoted 10 lines
tools/Rules.mk +7 -2
 ifeq ($(debug),y)
-# Disable optimizations
-CFLAGS += -O0 -fno-omit-frame-pointer
+CFLAGS += -fno-omit-frame-pointer
+# Use optimizations compatible with debugging otherwise disable optimizations
+ifneq ($(call cc-option,$(CC),-Og,n),n)
+CFLAGS += -Og
+else
+CFLAGS += -O0
+endif

Sadly the way cc-option is written made the support check always return true. cc-option would grep for -Og in the (error) to tell if it is supported or not, but the error message for -Og doesn't contain "-Og". It is like

cc1: error: argument to '-O' should be a non-negative integer

We need to think of another way to test it, or we just have to live with V1.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 34 lines · Wei Liu
Quoted 17 lines · Doug Goldstein

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.

---
 tools/Rules.mk | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/Rules.mk +0 -0
index 296b722372..3848bcf1f7 100644
@@ -164,8 +164,13 @@ LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libexten
 SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
 

tools/Rules.mk LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libexten · line 173

Quoted 10 lines
tools/Rules.mk +7 -2
 ifeq ($(debug),y)
-# Disable optimizations
-CFLAGS += -O0 -fno-omit-frame-pointer
+CFLAGS += -fno-omit-frame-pointer
+# Use optimizations compatible with debugging otherwise disable optimizations
+ifneq ($(call cc-option,$(CC),-Og,n),n)
+CFLAGS += -Og
+else
+CFLAGS += -O0
+endif

Sadly the way cc-option is written made the support check always return true. cc-option would grep for -Og in the (error) to tell if it is supported or not, but the error message for -Og doesn't contain "-Og". It is like

Quoted 4 lines

cc1: error: argument to '-O' should be a non-negative integer

We need to think of another way to test it, or we just have to live with V1.

Wait, but even v1 is bogus because cc-option-add uses cc-option.

I'm afraid we will need to figure out a new way to detect if the option is supported.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel