From c46c34284d4a059050fca105ad65acb4f27bfca6 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 24 Jun 2026 14:04:49 -0500 Subject: [PATCH] [tysan] Guard mallopt() use on SANITIZER_GLIBC instead of SANITIZER_LINUX (#203118) mallopt() is a glibc extension, not provided by other Linux C libraries such as musl, but its declaration and its use in InitializeInterceptors() are gated on SANITIZER_LINUX. Linking the TySan runtime for a musl target therefore fails: ld.lld: error: undefined symbol: mallopt >>> referenced by tysan_interceptors.cpp:215 in >>> __tysan::InitializeInterceptors() in libclang_rt.tysan-hexagon.a --- compiler-rt/lib/tysan/tysan_interceptors.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/tysan/tysan_interceptors.cpp b/compiler-rt/lib/tysan/tysan_interceptors.cpp index a93fcb4c3bcb..095ce0e74bb8 100644 --- a/compiler-rt/lib/tysan/tysan_interceptors.cpp +++ b/compiler-rt/lib/tysan/tysan_interceptors.cpp @@ -22,7 +22,7 @@ #define TYSAN_INTERCEPT___STRDUP 0 #endif -#if SANITIZER_LINUX +#if SANITIZER_GLIBC extern "C" int mallopt(int param, int value); #endif @@ -211,7 +211,7 @@ void InitializeInterceptors() { CHECK_EQ(inited, 0); // Instruct libc malloc to consume less memory. -#if SANITIZER_LINUX +#if SANITIZER_GLIBC mallopt(1, 0); // M_MXFAST mallopt(-3, 32 * 1024); // M_MMAP_THRESHOLD #endif