From 2bbcfa5e1a9d3679cbbbb87a9560a89a9cd10553 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Wed, 1 Apr 2026 09:45:53 -0700 Subject: [PATCH] Remove ASan from the default build mode (#7003) Also increases the default optimization to `-Og` which is likely to give faster turn-around time which is what we want to optimize for here. This should also _substantially_ shrink binary sizes, etc. ASan is still available via `--config=asan`, and is added to the CI infrastructure. However, my current thought is to only run it after push rather than in PRs and in the merge queue. --- .bazelrc | 6 +++--- .../cc_toolchain_carbon_project_features.bzl | 3 +-- bazel/cc_toolchains/cc_toolchain_optimization.bzl | 2 +- docs/project/contribution_tools.md | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.bazelrc b/.bazelrc index dc29e30169e1..096b4add3924 100644 --- a/.bazelrc +++ b/.bazelrc @@ -85,12 +85,12 @@ common --define=absl=1 # Enable TCMalloc on Linux in optimized builds. common --custom_malloc=//bazel/malloc:tcmalloc_if_linux_opt -# Configuration for enabling Address Sanitizer. Note that this is enabled by -# default for fastbuild. The config is provided to enable ASan even in -# optimized or other build configurations. Note that ASan and TCMalloc are +# Configuration for enabling Address Sanitizer. Note that ASan and TCMalloc are # incompatible so this explicitly forces the system malloc. common:asan --features=asan common:asan --custom_malloc=@bazel_tools//tools/cpp:malloc +# Also double the test timeouts for ASan to improve their consistency. +test:asan --test_timeout=120,600,1800,-1 # Configuration for enabling LibFuzzer (along with ASan). common:fuzzer --features=fuzzer diff --git a/bazel/cc_toolchains/cc_toolchain_carbon_project_features.bzl b/bazel/cc_toolchains/cc_toolchain_carbon_project_features.bzl index f6ee361afbed..1afbe052c818 100644 --- a/bazel/cc_toolchains/cc_toolchain_carbon_project_features.bzl +++ b/bazel/cc_toolchains/cc_toolchain_carbon_project_features.bzl @@ -27,10 +27,9 @@ carbon_project_fastbuild_feature = feature( enabled = True, requires = [feature_set(["fastbuild"])], implies = [ - "asan", - "asan_min_size", "minimal_optimization_flags", "minimal_debug_info_flags", + "preserve_call_stacks", ], ) diff --git a/bazel/cc_toolchains/cc_toolchain_optimization.bzl b/bazel/cc_toolchains/cc_toolchain_optimization.bzl index c0d83d07af9e..910d71b82d6f 100644 --- a/bazel/cc_toolchains/cc_toolchain_optimization.bzl +++ b/bazel/cc_toolchains/cc_toolchain_optimization.bzl @@ -26,7 +26,7 @@ minimal_optimization_flags = feature( name = "minimal_optimization_flags", flag_sets = [flag_set( actions = codegen_compile_actions, - flag_groups = [flag_group(flags = ["-O1"])], + flag_groups = [flag_group(flags = ["-Og"])], )], ) default_optimization_flags = feature( diff --git a/docs/project/contribution_tools.md b/docs/project/contribution_tools.md index 8bcece9d321d..065b9dbb18a7 100644 --- a/docs/project/contribution_tools.md +++ b/docs/project/contribution_tools.md @@ -24,6 +24,7 @@ contributions. - [Optional tools](#optional-tools) - [Jujutsu (`jj`)](#jujutsu-jj) - [AI assistants](#ai-assistants) + - [Running tests with AddressSanitizer (ASan)](#running-tests-with-addresssanitizer-asan) - [Manually building Clang and LLVM (not recommended)](#manually-building-clang-and-llvm-not-recommended) - [Troubleshooting build issues](#troubleshooting-build-issues) - [`bazel clean`](#bazel-clean) @@ -310,6 +311,20 @@ git show git status ``` +### Running tests with AddressSanitizer (ASan) + +By default, the Bazel build mode for the toolchain does not enable +AddressSanitizer (ASan). If you wish to enable ASan for local testing, you must +pass the `--config=asan` flag explicitly: + +```shell +bazelisk test --config=asan //... +``` + +Note that our Continuous Integration (CI) infrastructure runs a separate +configuration for ASan to ensure test coverage without slowing down the default +test cycle. + ### Manually building Clang and LLVM (not recommended) We primarily test against [apt.llvm.org](https://apt.llvm.org) and Homebrew