[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
This commit is contained in:
Brian Cain 2026-06-24 14:04:49 -05:00 committed by GitHub
parent 5528a0e984
commit c46c34284d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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