From e6e7bd8d832c8714b79e9cfb3ba24a38c0b075b4 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Sat, 12 Jun 2021 20:46:08 +0100 Subject: [PATCH] Compile the debug build with -Og -ggdb -gz if supported. Check the C++ compiler for -Og via configure and use it if available. Per the GCC manual: -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. It is a better choice than -O0 for producing debuggable code because some compiler passes that collect debug information are disabled at -O0. The debug exe is painfully slow on large designs, hopefully this is an improvement. Similarly, check for and use -gz to compress the debug info as it is huge otherwise. This should help with distribution and caching on CI. Also checks for -ggdb via configure for compatibility. --- configure.ac | 10 ++++++++++ src/Makefile_obj.in | 9 +++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 9973fe8fe..90bce2208 100644 --- a/configure.ac +++ b/configure.ac @@ -322,6 +322,16 @@ _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_PARSER,-Wno-parentheses-equality) _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_PARSER,-Wno-unused) AC_SUBST(CFG_CXXFLAGS_PARSER) +# Flags for compiling the debug version of Verilator (in addition to above CFG_CXXFLAGS_SRC) +_MY_CXX_CHECK_OPT(CFG_CXXFLAGS_DEBUG,-Og) +_MY_CXX_CHECK_OPT(CFG_CXXFLAGS_DEBUG,-ggdb) +_MY_CXX_CHECK_OPT(CFG_CXXFLAGS_DEBUG,-gz) +AC_SUBST(CFG_CXXFLAGS_DEBUG) + +# Flags for linking the debug version of Verilator (in addition to above CFG_LDFLAGS_SRC) +_MY_LDLIBS_CHECK_OPT(CFG_LDFLAGS_DEBUG,-gz) +AC_SUBST(CFG_LDFLAGS_DEBUG) + # Flags for Verilated makefile # For example, -Wno-div-by-zero isn't in 4.1.2 # Random code often does / 0. Unfortunately VL_DIV_I(0,0) will warn diff --git a/src/Makefile_obj.in b/src/Makefile_obj.in index fcd977e14..5fc473131 100644 --- a/src/Makefile_obj.in +++ b/src/Makefile_obj.in @@ -77,13 +77,11 @@ TGT = ../../verilator_bin$(EXEEXT) ################# ifeq ($(VL_DEBUG),) # Optimize -COPT = -O2 +CPPFLAGS += -O2 else # Debug -COPT = -ggdb -DVL_DEBUG -D_GLIBCXX_DEBUG -# Debug & Profile: -#LDFLAGS += -pg -g -#COPT = -ggdb -pg -g +CPPFLAGS += @CFG_CXXFLAGS_DEBUG@ -DVL_DEBUG -D_GLIBCXX_DEBUG +LDFLAGS += @CFG_LDFLAGS_DEBUG@ endif ################# @@ -96,7 +94,6 @@ LIBS = $(CFG_LIBS) -lm CPPFLAGS += -MMD CPPFLAGS += -I. -I$(bldsrc) -I$(srcdir) -I$(incdir) -I../../include #CPPFLAGS += -DVL_LEAK_CHECKS # If running valgrind or other hunting tool -CPPFLAGS += $(COPT) CPPFLAGS += -MP # Only works on recent GCC versions ifeq ($(CFG_WITH_CCWARN),yes) # Local... Else don't burden users CPPFLAGS += -W -Wall $(CFG_CXXFLAGS_WEXTRA) $(CFG_CXXFLAGS_SRC) -Werror