[compiler-rt][rtsan] Fix build failures when building against in-tree libc++ (#175638)

When building compiler-rt against an in-tree libc++, intermittent build
failures could occur: some rtsan sources referenced c++ stdlib includes
(i.e. `#include <new>`), but there was no CMake dependency enforcing
that the libc++ headers were copied into place before the rtsan sources
were built.

https://github.com/llvm/llvm-project/issues/127764#issue-2862550745
proposed adding the dependency on the `cxx-headers` target to resolve
the issue. But my understanding is that compiler-rt sanitizer runtimes
aren't expected to bring in C++ stdlib includes in the first place --
`SANITIZER_COMMON_CFLAGS`, used by the other sanitizer runtimes,
contains `-nostdinc++`.

Rtsan only included `<new>` to get support for placement new.
`sanitizer_common/sanitizer_placement_new.h` can provide this without
the need for C++ stdlib headers.

Move from `COMPILER_RT_COMMON_CFLAGS`/`COMPILER_RT_CXX_CFLAGS` to
`SANITIZER_COMMON_CFLAGS`, and from `COMPILER_RT_COMMON_LINK_FLAGS` to
`SANITIZER_COMMON_LINK_FLAGS` to be consistent with the other
sanitizers.

Fixes #127764.
This commit is contained in:
Nick Hutchinson 2026-01-14 19:18:30 +00:00 committed by GitHub
parent bf4645b0b4
commit 46de320038
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 6 deletions

View File

@ -28,10 +28,9 @@ set(RTSAN_HEADERS
set(RTSAN_DEPS)
set(RTSAN_CFLAGS
${COMPILER_RT_COMMON_CFLAGS}
${COMPILER_RT_CXX_CFLAGS}
${SANITIZER_COMMON_CFLAGS}
-DSANITIZER_COMMON_NO_REDEFINE_BUILTINS)
set(RTSAN_LINK_FLAGS ${COMPILER_RT_COMMON_LINK_FLAGS})
set(RTSAN_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
set(RTSAN_DYNAMIC_LIBS
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_CXX_ABI_LIBRARIES}

View File

@ -12,8 +12,8 @@
#include "rtsan/rtsan.h"
#include "sanitizer_common/sanitizer_allocator_internal.h"
#include "sanitizer_common/sanitizer_placement_new.h"
#include <new>
#include <pthread.h>
using namespace __sanitizer;

View File

@ -16,11 +16,10 @@
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_internal_defs.h"
#include "sanitizer_common/sanitizer_placement_new.h"
#include "sanitizer_common/sanitizer_suppressions.h"
#include "sanitizer_common/sanitizer_symbolizer.h"
#include <new>
using namespace __sanitizer;
using namespace __rtsan;