IMPALA-11110: Switch debug builds to use -Og

GCC's -Og applies optimizations that are compatible with
being debuggable. It is similar to -O1 and results
in a modest speed-up. This modifies the default debug
build to use -Og, so it is now more akin to a fastdebug
mode.

Even though -Og is intended to preserve debuggability,
optimization always impacts debuggability and -Og is
no exception. To enable the old behavior, this adds
a DEBUG_NOOPT build mode that retains the old
non-optimized behavior. Using the -debug_noopt flag
with buildall.sh enables this behavior.

Change-Id: Ie06c149c8181c90572b8668bd01dfd26c0a5971e
Reviewed-on: http://gerrit.cloudera.org:8080/18200
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Reviewed-by: Laszlo Gaal (Cloudera) <laszlo.gaal@cloudera.com>
Reviewed-by: Csaba Ringhofer <csringhofer@cloudera.com>
This commit is contained in:
Joe McDonnell
2020-11-24 10:42:59 -08:00
parent 1739edf2d9
commit a5a9b1e3f9
2 changed files with 28 additions and 5 deletions

View File

@@ -96,7 +96,8 @@ SET(CXX_CLANG_FLAGS "${CXX_CLANG_FLAGS} -DCALLONCEHACK")
# -gdwarf-4: Set the appropriate DWARF version. Later versions of DWARF have better
# support for newer C++ language features and better compression, but require newer
# versions of GDB. DWARF 4 requires GDB 7.0 or above.
SET(CXX_GCC_FLAGS "-g -Wno-unused-local-typedefs -gdwarf-4")
# -Wno-maybe-unitialized: Do not warn for variables that might be uninitialized
SET(CXX_GCC_FLAGS "-g -Wno-unused-local-typedefs -gdwarf-4 -Wno-maybe-uninitialized")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
# We need to add additional arguments for GCC 7+. We go down this branch if building
# with a non-GCC compiler of version 7+, but in that case CXX_GCC_FLAGS is not used,
@@ -109,15 +110,23 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
endif()
# compiler flags for different build types (run 'cmake -DCMAKE_BUILD_TYPE=<type> .')
# For CMAKE_BUILD_TYPE=Debug
# For CMAKE_BUILD_TYPE=DEBUG_NOOPT
# -ggdb: Enable gdb debugging
# For CMAKE_BUILD_TYPE=Debug
# (Same as CMAKE_BUILD_TYPE=DEBUG_NOOPT) +
# -Og: Enable basic optimizations
# For CMAKE_BUILD_TYPE=Release
# -O3: Enable all compiler optimizations
# -DNDEBUG: Turn off dchecks/asserts/debug only code.
SET(CXX_FLAGS_DEBUG "${CXX_GCC_FLAGS} -ggdb")
SET(CXX_FLAGS_DEBUG_NOOPT "${CXX_GCC_FLAGS} -ggdb")
# -Werror: compile warnings should be errors when using the toolchain compiler.
# Enabled for DEBUG, ASAN, TSAN and UBSAN builds which are built pre-commit.
SET(CXX_FLAGS_DEBUG "${CXX_FLAGS_DEBUG} -Werror")
SET(CXX_FLAGS_DEBUG_NOOPT "${CXX_FLAGS_DEBUG_NOOPT} -Werror")
# The legacy debug mode built without optimizations, as optimizations can interfere with
# debuggability. The DEBUG_NOOPT mode maintains this old behavior, while the default
# Debug mode now applies basic optimizations (-Og) to speed up test runs.
SET(CXX_FLAGS_DEBUG "${CXX_FLAGS_DEBUG_NOOPT} -Og")
SET(CXX_FLAGS_RELEASE "${CXX_GCC_FLAGS} -O3 -DNDEBUG")
SET(CXX_FLAGS_ADDRESS_SANITIZER
"${CXX_CLANG_FLAGS} -Werror -O1 -g -fsanitize=address -fno-omit-frame-pointer -DADDRESS_SANITIZER")
@@ -165,6 +174,8 @@ SET(CXX_FLAGS_TIDY "${CXX_FLAGS_TIDY} -fno-color-diagnostics")
# Set compile flags based on the build type.
if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
SET(CMAKE_CXX_FLAGS ${CXX_FLAGS_DEBUG})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG_NOOPT")
SET(CMAKE_CXX_FLAGS ${CXX_FLAGS_DEBUG_NOOPT})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
SET(CMAKE_CXX_FLAGS ${CXX_FLAGS_RELEASE})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "ADDRESS_SANITIZER")

View File

@@ -75,6 +75,7 @@ BUILD_UBSAN=0
BUILD_UBSAN_FULL=0
BUILD_TSAN=0
BUILD_TSAN_FULL=0
BUILD_DEBUG_NOOPT=0
BUILD_SHARED_LIBS=0
# Export MAKE_CMD so it is visible in scripts that invoke make, e.g. copy-udfs-udas.sh
export MAKE_CMD=make
@@ -148,6 +149,9 @@ do
-full_tsan)
BUILD_TSAN_FULL=1
;;
-debug_noopt)
BUILD_DEBUG_NOOPT=1
;;
-testpairwise)
EXPLORATION_STRATEGY=pairwise
;;
@@ -226,6 +230,10 @@ do
echo "[-full_ubsan] : Undefined behavior sanitizer build, including code generated"\
"by cross-compilation to LLVM IR. Much slower queries than plain -ubsan"\
"[Default: False]"
echo "[-debug_noopt] : Debug build without optimizations applied. The regular"\
"debug build applies basic optimizations, but even these optimizations may"\
"impact debuggability, so this is an option to omit the optimizations."\
"[Default: False]"
echo "[-skiptests] : Skips execution of all tests"
echo "[-notests] : Skips building and execution of all tests"
echo "[-start_minicluster] : Start test cluster including Impala and all"\
@@ -325,6 +333,10 @@ if [[ ${BUILD_TSAN_FULL} -eq 1 ]]; then
CMAKE_BUILD_TYPE_LIST+=(TSAN_FULL)
export TSAN_FULL=1
fi
if [[ ${BUILD_DEBUG_NOOPT} -eq 1 ]]; then
CMAKE_BUILD_TYPE_LIST+=(DEBUG_NOOPT)
export DEBUG_NOOPT=1
fi
if [[ -n "${CMAKE_BUILD_TYPE_LIST:+1}" ]]; then
if [[ ${#CMAKE_BUILD_TYPE_LIST[@]} -gt 1 ]]; then
echo "ERROR: more than one CMake build type defined: ${CMAKE_BUILD_TYPE_LIST[@]}"