Link Threads::Threads in tests that use threads directly#2112
Open
jnooree wants to merge 1 commit into
Open
Conversation
These tests reference pthread symbols (via std::thread or thread-local storage) but relied on transitive linkage through the gtest shared library to pull in libpthread. That is fragile and breaks when building the monolithic shared library (ABSL_BUILD_MONOLITHIC_SHARED_LIBS) on platforms where libpthread is a separate DSO (glibc < 2.34): the monolithic DLL links Threads::Threads privately, so a test whose only non-gtest dependency is the DLL (e.g. lifetime_test) fails to link with an undefined reference to pthread_join. Depend on Threads::Threads explicitly, matching low_level_alloc_test and thread_identity_test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Link
Threads::Threadsin tests that use threads directly.Problem
Building Abseil as a monolithic shared library (
-DABSL_BUILD_MONOLITHIC_SHARED_LIBS=ONwith-DBUILD_SHARED_LIBS=ON) with tests enabled fails to link on platforms wherelibpthreadis a separate DSO (glibc < 2.34):Root cause
In monolithic-DLL mode,
absl_cc_testcollapses every in-DLLabsl::dependency down to the singleabseil_dlltarget.abseil_dlllinksThreads::Threadsprivately (CMake/AbseilDll.cmake), so-lpthreadis not propagated to the test executables.lifetime_testlinks no GoogleTest target (it has its ownmain), so its entire link line is justlibabseil_dll.so. It usesstd::threaddirectly → unresolvedpthread_join→ hard link failure.GTest::gtest's imported target happens to drag-lpthreadonto their link line. That is a fragile, incidental transitive dependency — exactly what breaks under the monolithic DLL once a test stops pulling GoogleTest.Fix
Every test that references pthread symbols now depends on
Threads::Threadsexplicitly, matching the existing convention already used bylow_level_alloc_testandthread_identity_test.Notes
quay.io/pypa/manylinux_2_28_x86_64(glibc 2.28) container with-Wl,--as-needed -lpthreadappended at the end of every test link line. The binaries that retainedlibpthread, minus the two that already declaredThreads::Threads, are exactly the 47 targets fixed here.config_test,errno_saver_test, severallog_*— pull pthread via thread-local storagepthread_getspecific/pthread_setspecificrather thanstd::thread. They still genuinely needlibpthreadon old glibc, so they are included.base,malloc_internal,synchronization) carrylinkopts = ["-pthread"], and Bazel propagates librarylinkoptstransitively throughdepsto test binaries.