Skip to content

Commit 18ac608

Browse files
Abseil Teamcopybara-github
authored andcommitted
Export Mutex::Dtor from shared libraries in NDEBUG mode
When Abseil is built as a shared library (`ABSL_BUILD_DLL`) with `NDEBUG` defined, `Mutex::Dtor()` is currently fully inlined and no symbol is emitted. Downstream clients building against this shared library without `NDEBUG` defined (e.g., a debug build of an application linking against a system-provided release Abseil DLL) will expect a `Mutex::Dtor()` symbol to exist, ensuring ABI compatibility. Currently, this leads to undefined reference linker errors. This patch aligns `Mutex::Dtor()` with the existing logic for `Mutex::~Mutex()`: it disables inlining in the header when `ABSL_BUILD_DLL` is active and ensures an empty definition is provided in the source file for these builds. PiperOrigin-RevId: 828160210 Change-Id: I5ed1fd6757d631e80d6f084d20bfe8e25f6ef253
1 parent 6d94b2c commit 18ac608

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

absl/synchronization/mutex.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,8 @@ static unsigned TsanFlags(Mutex::MuHow how) {
745745
Mutex::~Mutex() { Dtor(); }
746746
#endif
747747

748-
#if !defined(NDEBUG) || defined(ABSL_HAVE_THREAD_SANITIZER)
748+
#if !defined(NDEBUG) || defined(ABSL_HAVE_THREAD_SANITIZER) || \
749+
defined(ABSL_BUILD_DLL)
749750
void Mutex::Dtor() {
750751
if (kDebugMode) {
751752
this->ForgetDeadlockInfo();

absl/synchronization/mutex.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,12 +1139,13 @@ ABSL_ATTRIBUTE_ALWAYS_INLINE
11391139
inline Mutex::~Mutex() { Dtor(); }
11401140
#endif
11411141

1142-
#if defined(NDEBUG) && !defined(ABSL_HAVE_THREAD_SANITIZER)
1143-
// Use default (empty) destructor in release build for performance reasons.
1144-
// We need to mark both Dtor and ~Mutex as always inline for inconsistent
1145-
// builds that use both NDEBUG and !NDEBUG with dynamic libraries. In these
1146-
// cases we want the empty functions to dissolve entirely rather than being
1147-
// exported from dynamic libraries and potentially override the non-empty ones.
1142+
#if defined(NDEBUG) && !defined(ABSL_HAVE_THREAD_SANITIZER) && \
1143+
!defined(ABSL_BUILD_DLL)
1144+
// Under NDEBUG and without TSAN, Dtor is normally fully inlined for
1145+
// performance. However, when building Abseil as a shared library
1146+
// (ABSL_BUILD_DLL), we must provide an out-of-line definition. This ensures the
1147+
// Mutex::Dtor symbol is exported from the DLL, maintaining ABI compatibility
1148+
// with clients that might be built in debug mode and thus expect the symbol.
11481149
ABSL_ATTRIBUTE_ALWAYS_INLINE
11491150
inline void Mutex::Dtor() {}
11501151
#endif

0 commit comments

Comments
 (0)