From bc658e6923654e913bb4590f146d5b54cc41ae25 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 18 Sep 2021 03:57:17 -0700 Subject: [PATCH] Cleanup debug flags and enable libc++ debugging on Linux. (#835) The big change here is to enable libc++'s debug mode outside of `opt` builds on Linux where it seems to work well with the Homebrew installed toolchain. I'm restricting it to Linux as the system libc++ install on x86 macOS doesn't seem to work. This is based on and subsumes #811. This also tidies up how `-NDEBUG` is set to include non-codegen compile actions, and consolidates some optimization flags in a single location. This part has no functionality change, but would likely invalidate caches so bundled here where both a) I noticed and b) we already had a cache invalidation. --- .../clang_cc_toolchain_config.bzl | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/bazel/cc_toolchains/clang_cc_toolchain_config.bzl b/bazel/cc_toolchains/clang_cc_toolchain_config.bzl index a9670d6b23dd..a7f7d96fb3e0 100644 --- a/bazel/cc_toolchains/clang_cc_toolchain_config.bzl +++ b/bazel/cc_toolchains/clang_cc_toolchain_config.bzl @@ -169,13 +169,11 @@ def _impl(ctx): flag_groups = ([ flag_group( flags = [ - "-DNDEBUG", "-ffunction-sections", "-fdata-sections", ], ), ]), - with_features = [with_feature_set(features = ["opt"])], ), flag_set( actions = codegen_compile_actions, @@ -284,12 +282,20 @@ def _impl(ctx): name = "default_optimization_flags", enabled = True, requires = [feature_set(["opt"])], - flag_sets = [flag_set( - actions = codegen_compile_actions, - flag_groups = [flag_group(flags = [ - "-O3", - ])], - )], + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [flag_group(flags = [ + "-DNDEBUG", + ])], + ), + flag_set( + actions = codegen_compile_actions, + flag_groups = [flag_group(flags = [ + "-O3", + ])], + ), + ], ) # Handle different levels and forms of debug info emission with individual @@ -518,6 +524,17 @@ def _impl(ctx): ), ]), ), + flag_set( + actions = all_compile_actions, + flag_groups = [flag_group(flags = [ + # Enable libc++'s debug features. + "-D_LIBCXX_DEBUG=1", + ])], + with_features = [ + with_feature_set(features = ["dbg"]), + with_feature_set(features = ["fastbuild"]), + ], + ), ], )