From 342b3ddbf199958b962ae706c54792298824ccd0 Mon Sep 17 00:00:00 2001 From: TCMalloc Team Date: Tue, 22 Sep 2026 02:04:30 -0700 Subject: [PATCH] Make the per-CPU RSEQ HWASan gate independent of include order. percpu.h tested ABSL_HAVE_HWADDRESS_SANITIZER before any absl header was included, so TCMALLOC_PERCPU_RSEQ_SUPPORTED_PLATFORM (and hence TCMALLOC_INTERNAL_PERCPU_USE_RSEQ) evaluated to 1 in every TU whose first include is percpu.h (percpu.cc, percpu_test.cc, percpu_rseq_unsupported.cc, and all RSEQ .S files, which never include absl) but to 0 in TUs that include absl first (tcmalloc.cc, cpu_cache.h, percpu_tcmalloc.h). PiperOrigin-RevId: 985836888 --- tcmalloc/internal/percpu.h | 27 +-------------------------- tcmalloc/internal/percpu_test.cc | 9 --------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/tcmalloc/internal/percpu.h b/tcmalloc/internal/percpu.h index 1217b34a1..de6204510 100644 --- a/tcmalloc/internal/percpu.h +++ b/tcmalloc/internal/percpu.h @@ -33,27 +33,11 @@ #define TCMALLOC_CACHED_SLABS_BIT 63 #define TCMALLOC_CACHED_SLABS_MASK (1ul << TCMALLOC_CACHED_SLABS_BIT) -// TCMALLOC_INTERNAL_PERCPU_HWASAN is derived from compiler predefined macros -// rather than ABSL_HAVE_HWADDRESS_SANITIZER, since this header must evaluate -// identically in every translation unit (including the RSEQ assembly sources) -// regardless of whether absl/base/config.h has already been included. -#if defined(__has_feature) -#if __has_feature(hwaddress_sanitizer) -#define TCMALLOC_INTERNAL_PERCPU_HWASAN 1 -#endif -#endif -#if defined(__SANITIZE_HWADDRESS__) -#define TCMALLOC_INTERNAL_PERCPU_HWASAN 1 -#endif -#if !defined(TCMALLOC_INTERNAL_PERCPU_HWASAN) -#define TCMALLOC_INTERNAL_PERCPU_HWASAN 0 -#endif - // TCMALLOC_PERCPU_RSEQ_SUPPORTED_PLATFORM defines whether or not we have an // implementation for the target OS and architecture. // TODO(b/478927694): re-enable for HWASan #if defined(__linux__) && (defined(__x86_64__) || defined(__aarch64__)) && \ - !TCMALLOC_INTERNAL_PERCPU_HWASAN + !defined(ABSL_HAVE_HWADDRESS_SANITIZER) #define TCMALLOC_PERCPU_RSEQ_SUPPORTED_PLATFORM 1 #else #define TCMALLOC_PERCPU_RSEQ_SUPPORTED_PLATFORM 0 @@ -88,15 +72,6 @@ #include "tcmalloc/internal/linux_syscall_support.h" #include "tcmalloc/internal/logging.h" -// The RSEQ gate above is evaluated before any absl header is included; verify -// that it agrees with absl's detection now that absl/base/config.h is visible. -#if defined(ABSL_HAVE_HWADDRESS_SANITIZER) && !TCMALLOC_INTERNAL_PERCPU_HWASAN -#error "HWASan detected by absl but not by the TCMalloc per-CPU RSEQ gate" -#endif -#if !defined(ABSL_HAVE_HWADDRESS_SANITIZER) && TCMALLOC_INTERNAL_PERCPU_HWASAN -#error "HWASan detected by the TCMalloc per-CPU RSEQ gate but not by absl" -#endif - // TCMALLOC_INTERNAL_PERCPU_USE_RSEQ defines whether TCMalloc support for RSEQ // on the target architecture exists. We currently only provide RSEQ for 64-bit // x86, Arm binaries. diff --git a/tcmalloc/internal/percpu_test.cc b/tcmalloc/internal/percpu_test.cc index 9084f7424..559d0501a 100644 --- a/tcmalloc/internal/percpu_test.cc +++ b/tcmalloc/internal/percpu_test.cc @@ -29,15 +29,6 @@ namespace tcmalloc::tcmalloc_internal::subtle::percpu { namespace { -// percpu.h is the first include of this TU, so the RSEQ gate must be -// evaluated without relying on macros provided by later includes. -#if defined(ABSL_HAVE_HWADDRESS_SANITIZER) -static_assert(TCMALLOC_PERCPU_RSEQ_SUPPORTED_PLATFORM == 0, - "RSEQ must be disabled under HWASan"); -static_assert(TCMALLOC_INTERNAL_PERCPU_USE_RSEQ == 0, - "RSEQ must be disabled under HWASan"); -#endif - ABSL_CONST_INIT std::atomic alarms{0}; void sa_alrm(int sig) {