Files
carbon-lang/bazel/malloc/BUILD
T
Chandler Carruth 284b14981d Fix our default fastbuild Bazel config (#4363)
Causes the default development (`fastbuild`) Bazel build and test to
both use ASan, minimal optimizations, and produce good backtraces with
source locations.

This also fixes all of the non-host configs that were deeply broken for
the latest releases of Bazel going back quite some time.

The intent of our our Bazel toolchain config was for a minimally
optimized, minimal debug info, and ASan + UBSan configuration to be the
`fastbuild`, or the default development build of the project. This
matches its inclusion of asserts, etc.

At some point quite some time ago, all of this stopped working. Bazel no
longer has a `nonhost` feature. This was disabled a long time ago,
briefly argued to be re-enabled, but has persistently been removed.
However, since then the host and non-host features have been separated
including the compilation mode, and so none of that is needed now.
Instead, we can use a much simpler and more principled approach to all
of the feature configuration now which this PR implements.

However, we added TCMalloc _after_ all of the ASan stuff became broken,
and so we never saw that it is fundamentally incompatible with ASan. So
this PR also reworks how TCMalloc is used to only apply to `-c opt`
builds on Linux, and it also explicitly disables it when using
`--config=asan`. I've not found a convenient way to tie the malloc
library choice to a toolchain feature in Bazel, so this relies on the
config being used rather than the feature in isolation.

Last but not least, with this change `fastbuild` creates substantially
larger output and so this change also passes several new flags to reduce
the size costs. One is a general improvement from outlining ASan
instrumentation. The others are in a special feature as they reduce the
error message quality for two of the more expensive UBSan checks in
favor of small generated code size. Keeping these last two separate
allows disabling this locally if needed to debug a failure.
2024-10-07 18:19:49 +00:00

40 lines
1.1 KiB
Python

# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_cc//cc:defs.bzl", "cc_library")
config_setting(
name = "is_linux",
constraint_values = ["@platforms//os:linux"],
)
config_setting(
name = "opt",
values = {"compilation_mode": "opt"},
)
selects.config_setting_group(
name = "linux_opt",
match_all = [
":is_linux",
":opt",
],
)
# A placeholder empty library that can be used as a `malloc` attribute or with
# the `--custom_malloc` bazel flag to have no custom malloc and use the system
# malloc instead.
cc_library(name = "system_malloc")
# A library that enables TCMalloc for optimized builds on Linux. On other
# platforms and configurations, this falls back on the system malloc.
cc_library(
name = "tcmalloc_if_linux_opt",
deps = select({
":linux_opt": ["@tcmalloc//tcmalloc"],
"//conditions:default": [":system_malloc"],
}),
)