[asan] Enable exceptions for asan_new_delete.cpp translation unit (#200719)
Groundwork for #196388.
Preparation for a follow-up change that lets the throwing operator new
wrappers in asan_new_delete.cpp throw std::bad_alloc on OOM. To support
that, asan_new_delete.cpp must be compiled with -fexceptions and must be
able to include <new> (i.e. without -nostdinc++). The rest of the ASan
runtime stays compiled with -fno-exceptions and -nostdinc++.
NOTE: Comments in CMakeLists.txt are written assuming the follow-on
changes to use exceptions land, thus avoiding the need to update
this file again.
Build-system changes:
* Define ASAN_CXX_CFLAGS as ASAN_CFLAGS minus -fno-exceptions and
-nostdinc++ plus -fexceptions. Define ASAN_DYNAMIC_CXX_CFLAGS likewise
relative to ASAN_DYNAMIC_CFLAGS. RTTI stays disabled; libstdc++ /
libc++abi supply the bad_alloc typeinfo.
* Static build: switch RTAsan_cxx (which already contains only
${ASAN_CXX_SOURCES} = asan_new_delete.cpp) from ASAN_CFLAGS to
ASAN_CXX_CFLAGS. RTAsan (the C slice) is unchanged.
* Dynamic build: split the previous single RTAsan_dynamic object library
into two — RTAsan_dynamic keeps ${ASAN_SOURCES} (no change in flags) and
a new RTAsan_dynamic_cxx carries ${ASAN_CXX_SOURCES} with
ASAN_DYNAMIC_CXX_CFLAGS. Both shared clang_rt.asan link rules pull in
RTAsan_dynamic_cxx alongside RTAsan_dynamic so the linked .so retains
the same set of object files; only the compile flags for
asan_new_delete.cpp change.
NFC at runtime — the asan_new_delete.cpp source as of this commit does
not yet use exceptions or include <new>, so the new flags are inert. The
follow-up commit makes use of them.
Assisted by: Claude Opus 4.7