From ab78d3a7f471fdaa44f6b7bc5feece81cd1d2833 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Sat, 22 Aug 2026 17:39:13 -0400 Subject: [PATCH] Give externally-provided symbol declarations default visibility Abseil forward-declares a handful of symbols that are provided by something outside the object being linked: the compiler-based sanitizer runtime supplies the Annotate* race annotations and __tsan_read1, and Bionic supplies __mmap2. None of these have a public header to include, so declaring them locally is the only option, but the declarations inherit whatever visibility is in effect. When a translation unit is compiled with -fvisibility=hidden and abseil is linked into a shared library, those references become hidden undefined symbols and cannot be resolved from the runtime or from libc, so the link fails: ld.lld: error: undefined hidden symbol: AnnotateIgnoreReadsBegin ld.lld: error: undefined hidden symbol: AnnotateIgnoreWritesBegin ld.lld: error: undefined hidden symbol: __tsan_read1 ld.lld: error: undefined hidden symbol: __mmap2 Wrap the declarations in a visibility push/pop so they stay resolvable. Every site is already inside a Bionic or sanitizer guard, so this does not affect platforms where the attribute is unavailable. --- absl/base/dynamic_annotations.h | 6 ++++++ absl/base/internal/direct_mmap.h | 2 ++ absl/synchronization/mutex.cc | 2 ++ 3 files changed, 10 insertions(+) diff --git a/absl/base/dynamic_annotations.h b/absl/base/dynamic_annotations.h index f18b5e0a8fa..1e679a6b139 100644 --- a/absl/base/dynamic_annotations.h +++ b/absl/base/dynamic_annotations.h @@ -202,6 +202,7 @@ // Function prototypes of annotations provided by the compiler-based sanitizer // implementation. +#pragma GCC visibility push(default) ABSL_INTERNAL_BEGIN_EXTERN_C void AnnotateRWLockCreate(const char* file, int line, const volatile void* lock); @@ -221,6 +222,7 @@ void AnnotateBenignRaceSized(const char* file, int line, void AnnotateThreadName(const char* file, int line, const char* name); void AnnotateEnableRaceDetection(const char* file, int line, int enable); ABSL_INTERNAL_END_EXTERN_C +#pragma GCC visibility pop #else // ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 0 @@ -297,12 +299,14 @@ ABSL_INTERNAL_END_EXTERN_C // Function prototypes of annotations provided by the compiler-based sanitizer // implementation. +#pragma GCC visibility push(default) ABSL_INTERNAL_BEGIN_EXTERN_C void AnnotateIgnoreReadsBegin(const char* file, int line) ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE; void AnnotateIgnoreReadsEnd(const char* file, int line) ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE; ABSL_INTERNAL_END_EXTERN_C +#pragma GCC visibility pop #elif defined(ABSL_INTERNAL_ANNOTALYSIS_ENABLED) @@ -353,10 +357,12 @@ ABSL_INTERNAL_STATIC_INLINE void ABSL_INTERNAL_C_SYMBOL( // Function prototypes of annotations provided by the compiler-based sanitizer // implementation. +#pragma GCC visibility push(default) ABSL_INTERNAL_BEGIN_EXTERN_C void AnnotateIgnoreWritesBegin(const char* file, int line); void AnnotateIgnoreWritesEnd(const char* file, int line); ABSL_INTERNAL_END_EXTERN_C +#pragma GCC visibility pop #else diff --git a/absl/base/internal/direct_mmap.h b/absl/base/internal/direct_mmap.h index 1beb2ee4e52..66e35323166 100644 --- a/absl/base/internal/direct_mmap.h +++ b/absl/base/internal/direct_mmap.h @@ -52,7 +52,9 @@ // SYS_mmap and SYS_munmap are not defined in Android. #ifdef __BIONIC__ +#pragma GCC visibility push(default) extern "C" void* __mmap2(void*, size_t, int, int, int, size_t); +#pragma GCC visibility pop #if defined(__NR_mmap) && !defined(SYS_mmap) #define SYS_mmap __NR_mmap #endif diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc index 68782564443..8dcc834ec7e 100644 --- a/absl/synchronization/mutex.cc +++ b/absl/synchronization/mutex.cc @@ -2788,7 +2788,9 @@ void ReleasableMutexLock::Release() { } #ifdef ABSL_HAVE_THREAD_SANITIZER +#pragma GCC visibility push(default) extern "C" void __tsan_read1(void* addr); +#pragma GCC visibility pop #else #define __tsan_read1(addr) // do nothing if TSan not enabled #endif