Files
Justin T. Gibbs c5c33597bf [asan] Fix asan_new_delete.cpp C++ header resolution under -nostdinc++ (#202816)
The COMPILER_RT_ASAN_ENABLE_EXCEPTIONS gate in asan/CMakeLists.txt
enables -fexceptions on the C++ slice (RTAsan_cxx /
RTAsan_dynamic_cxx — asan_new_delete.cpp) and tries to expose C++
standard headers to that TU (for forthcoming std::bad_alloc support)
by stripping -nostdinc++ from its cflags. The strip works for native
standalone builds but is wrong for cross builds: the host C++ headers
aren't valid for the target.

Split the C++-slice flag handling into two paths inside the existing
EXCEPTIONS gate:

  * In-tree libc++ available (TARGET cxx-headers OR HAVE_LIBCXX):
    keep -nostdinc++, append ${COMPILER_RT_CXX_CFLAGS} (a generator
    expression that expands to "-isystem <prepared cxx-headers dir>"),
    and add cxx-headers to DEPS so the header tree is staged before
    the compile. Mirrors the pattern in orc / fuzzer / memprof /
    tsan / xray.

  * No in-tree libc++ (typical standalone build): drop -nostdinc++
for the C++ slice TU only so the host toolchain supplies C++ headers.

Reject COMPILER_RT_CXX_LIBRARY=none +
COMPILER_RT_ASAN_ENABLE_EXCEPTIONS=ON
at configure time: that combination opts out of any C++ stdlib while
asking for an exception-enabled C++ slice, silently leaking host headers
into a `none`-mode build.

Assisted by: Claude Opus 4.7
2026-06-10 09:54:12 -07:00
..

AddressSanitizer RT
================================
This directory contains sources of the AddressSanitizer (ASan) runtime library.

Directory structure:
README.txt       : This file.
Makefile.mk      : File for make-based build.
CMakeLists.txt   : File for cmake-based build.
asan_*.{cc,h}    : Sources of the asan runtime library.
scripts/*        : Helper scripts.
tests/*          : ASan unit tests.

Also ASan runtime needs the following libraries:
lib/interception/      : Machinery used to intercept function calls.
lib/sanitizer_common/  : Code shared between various sanitizers.

ASan runtime currently also embeds part of LeakSanitizer runtime for
leak detection (lib/lsan/lsan_common.{cc,h}).

ASan runtime can only be built by CMake. You can run ASan tests
from the root of your CMake build tree:

make check-asan

For more instructions see:
https://github.com/google/sanitizers/wiki/AddressSanitizerHowToBuild