[codex] Build libc++ with ASan enabled#666
Open
dzbarsky wants to merge 8 commits into
Open
Conversation
fdc5662 to
3182dc3
Compare
3182dc3 to
7783d90
Compare
Preserve //config:asan for libcxx.static and libcxx.shared while runtime transitions reset every other sanitizer. Generate _LIBCPP_INSTRUMENTED_WITH_ASAN from //config:asan_enabled so out-of-line std::string functions update ASan container poison state. Stop linking sanitizer_common_symbolizer_internal and @llvm-project//llvm:Symbolize into sanitizer runtimes. LLVM upstream disables the internal symbolizer by default; the Bazel target exported ordinary std::__1 definitions from uninstrumented LLVM objects, which could replace the annotated libc++ definitions. Use the hermetic external llvm-symbolizer in asan_output_test instead. Add asan_libcxx_container_overflow_test with -fno-exceptions to cover the external reproducer's short-to-long std::string transition.
7783d90 to
2ef08b8
Compare
Match build_symbolizer.sh by compiling private libc++ and libc++abi archives with LLVM bitcode, then internalize all definitions except the seven sanitizer symbolizer APIs.\n\nLink the object into Linux sanitizer runtimes so internal symbolization cannot replace ASan-annotated libc++ definitions with ordinary std::__1 definitions.
Select libc++ headers while building LLVM Symbolize and the private libc++ even when the caller platform selects libstdc++. Add the libc++ header paths before the C header paths in the stage1_hosted toolchain.\n\nPropagate target_compatible_with through exec_test so the Linux-only ASan container-overflow test is skipped on Windows.
helly25
approved these changes
Jul 4, 2026
… programs, (#671) but not when building the runtimes themselves, as those are already included so adding them again collides in the sandbox
helly25
approved these changes
Jul 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Author: zbarsky-bot
Summary
libcxx.staticandlibcxx.sharednow preserve//config:asanwhile runtime transitions reset every other sanitizer. The generated libc++__config_sitedefines_LIBCPP_INSTRUMENTED_WITH_ASANfrom//config:asan_enabled, so out-of-linestd::stringfunctions update ASan container poison state.asan_libcxx_container_overflow_testcovers the-fno-exceptionsshort-to-longstd::stringtransition from thebazel-playgroundexternal-include-paths reproducer.On Linux,
sanitizer_common_symbolizer_internal_objectreplaces the previoussanitizer_common_symbolizer_internaland@llvm-project//llvm:Symbolizelinkage.cc_internal_symbolizer_objectmatchescompiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.shwhenCOMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER=ON: it builds private libc++ and libc++abi archives in the__InternalSymbolizernamespace, builds LLVM with Zlib enabled and Zstd and threads disabled, combines the bitcode, and internalizes every definition except the seven sanitizer symbolizer APIs.//config:internal_symbolizerselects libc++ headers for LLVM Symbolize even when the caller platform selects libstdc++.sanitizer_common_symbolizer_internal_objectis enabled on Bazel 9, whereexternal_include_pathskeeps the private libc++ headers before the C library headers. On Bazel 8, sanitizer runtimes omitsanitizer_common_symbolizer_internal_object,asan_output_testuses@llvm//tools:llvm-symbolizer, andasan_libcxx_container_overflow_testis incompatible. The private namespace prevents internal symbolizer definitions from replacing ASan-annotatedstd::__1definitions.asan_output_testverifies an internally symbolizedmainframe on Linux and retains the external@llvm//tools:llvm-symbolizeron macOS.Validation
asan_output_testwith externalllvm-symbolizerllvm-nmreports exactly the seven sanitizer symbolizer APIs as global definitions and no symbol outside upstreamglobal_symbols.txtbuildifier -mode=checkon every tracked Starlark and BUILD file, andgit diff --check