Link cephes-gtsam against libm#2590
Open
hz2 wants to merge 1 commit into
Open
Conversation
cephes/gamma.c, igam.c, and the other remaining cephes sources call libm functions (e.g. sin) directly, but cephes-gtsam was never linked against libm itself, leaving the symbol to be resolved transitively through whatever else the final binary happens to link against. That can crash the dynamic linker while relinking an IFUNC-resolved symbol (glibc printing "Relink `libcephes-gtsam.so' with `libm.so' for IFUNC symbol `sin'" before segfaulting in _dl_relocate_object) depending on link order in the consuming binary. Same failure mode as https://bugzilla.redhat.com/show_bug.cgi?id=1883501 in an unrelated project. Reproduced consistently when linking a downstream consumer that pulls in enough of libgtsam's symbol surface to shift link order, and confirmed fixed by this change (readelf -d shows a proper NEEDED entry for libm.so.6 afterward). Uses find_library(MATH_LIBRARY m) rather than an explicit -lm so this naturally no-ops on platforms without a separate libm (Windows, and effectively macOS where it's already part of libSystem).
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
cephes-gtsamcalls libm functions directly (e.g.sinincephes/gamma.c)but was never linked against libm itself. It happened to keep working
because the symbol got resolved transitively through whatever else ends up
in the final process, but that's fragile: depending on link order in a
downstream consumer, glibc's dynamic linker can crash while relinking the
IFUNC-resolved
sinsymbol (printsRelinklibcephes-gtsam.so' withlibm.so' for IFUNC symbolsin'right before segfaulting inside_dl_relocate_object`). Same failure mode asRHBZ#1883501 in an
unrelated project (cp2k/libxc).
I hit this building a downstream Rust FFI binding against GTSAM: a build
that pulled in more of libgtsam's symbol surface shifted link order enough
to trigger the crash reliably. Confirmed the missing dependency directly
(
readelf -d libcephes-gtsam.sohad noNEEDEDentry forlibm.so), andconfirmed this fix resolves it.
Fix
find_library(MATH_LIBRARY m)+ conditionaltarget_link_libraries,rather than a bare
-lm, so it naturally no-ops on platforms without aseparate libm (Windows, and effectively macOS where it's already part of
libSystem).Not a duplicate of #2273 (fixed a different issue: duplicate declarations of
libm functions in
cephes.hconflicting under static linking) or #2371(trimmed which cephes source files are built); neither touched linking
cephes-gtsam against libm itself.
Test plan
cmakeconfigure +make cephes-gtsamsucceedsreadelf -don the resultinglibcephes-gtsam.soshows aNEEDEDentry for
libm.so.6(previously absent)runs cleanly, repeated across multiple rebuilds