Skip to content

Fix CMake linking order for dlopen/dlsym symbols#252

Merged
hecko merged 4 commits intomasterfrom
fix/cmake-link-order-dl
Feb 6, 2026
Merged

Fix CMake linking order for dlopen/dlsym symbols#252
hecko merged 4 commits intomasterfrom
fix/cmake-link-order-dl

Conversation

@hecko
Copy link
Contributor

@hecko hecko commented Feb 6, 2026

Summary

  • Moved CMAKE_DL_LIBS (-ldl) after the static libraries in the link command
  • With --whole-archive, the GNU linker processes libraries in order - symbols must be defined after they are referenced
  • Fixes Debian 11 build failure with undefined references to dlopen, dlclose, dlsym, dlerror

Root Cause

The link command was:

-ldl -Wl,--whole-archive sems_core sems_sip -Wl,--no-whole-archive ...

The linker saw -ldl first but didn't know it was needed yet. When it processed sems_core (which uses dlopen etc.), the symbols were not available.

Fix

-Wl,--whole-archive sems_core sems_sip -Wl,--no-whole-archive -ldl ...

Now -ldl comes after the static libraries that reference it.

Test plan

  • Verify Debian 11 build passes in CI

🤖 Generated with Claude Code

Move CMAKE_DL_LIBS (-ldl) after the static libraries (sems_core,
sems_sip) in the link command. With --whole-archive, the GNU linker
processes libraries in order and needs to see the libraries that
define symbols after the objects that reference them.

This fixes the Debian 11 build failure where linking failed with
undefined references to dlopen, dlclose, dlsym, and dlerror from
libsems_core.a.
Copilot AI review requested due to automatic review settings February 6, 2026 08:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a CMake linking order issue that caused Debian 11 build failures with undefined references to dlopen, dlclose, dlsym, and dlerror symbols. The fix moves CMAKE_DL_LIBS (which contains -ldl, -lm, and -lpthread) to appear after the static libraries in the linker command, ensuring that symbols are defined after they are referenced by the static libraries.

Changes:

  • Moved CMAKE_DL_LIBS placement in target_link_libraries() calls from before to after the sems_core and sems_sip static libraries
  • Applied fix consistently to both macOS (-force_load) and Linux (--whole-archive) build configurations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

marcel added 3 commits February 6, 2026 09:30
Replace `git clone --branch master` with `COPY . /sems` in all
Debian Dockerfiles, matching the pattern already used by the RHEL
Dockerfiles.

The git clone approach meant Debian CI builds always tested master,
never the actual PR branch code. This made it impossible to test
CMake or build system changes before merging.
The CMake migration (6a8e364) removed all Makefiles but left the
bullseye and trixie rules files still calling $(MAKE) -C core/ install
and $(MAKE) -C apps/ install, which fail with "No rule to make target".

Update both to use dh --buildsystem=cmake with proper CMake configure
options, matching the pattern already working in bookworm/rules.
Codec options are set based on each distro's available dev packages.
The getarch and getos compat binaries are no longer built by CMake.
Comment out the compat lines in libsems1-dev.install, matching the
pattern already used in bookworm's .install file.
@hecko hecko merged commit 21af7c2 into master Feb 6, 2026
11 checks passed
@hecko hecko deleted the fix/cmake-link-order-dl branch February 6, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants