Skip to content

cmake: check we're not linking against a static c runtime without dlopen support#15531

Open
madebr wants to merge 12 commits intolibsdl-org:mainfrom
madebr:cmake-check-dlopen
Open

cmake: check we're not linking against a static c runtime without dlopen support#15531
madebr wants to merge 12 commits intolibsdl-org:mainfrom
madebr:cmake-check-dlopen

Conversation

@madebr
Copy link
Copy Markdown
Contributor

@madebr madebr commented May 7, 2026

  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Description

Existing Issue(s)

Fixes #15525

@slouken
Copy link
Copy Markdown
Collaborator

slouken commented May 7, 2026

This seems fine to me, but I think the issue with musl is that dlopen exists, it’s just a stub that returns a failure.

@slouken
Copy link
Copy Markdown
Collaborator

slouken commented May 7, 2026

In this particular case, the OS runtime has decided that dynamic linking is not available, and we don’t know that in advance. The user needs to be aware of this and configure SDL not to do dynamic loading.

@madebr
Copy link
Copy Markdown
Contributor Author

madebr commented May 7, 2026

True, the test correctly fails when using the bfd and gold linker,
but does not fail when using the mold linker.

@madebr
Copy link
Copy Markdown
Contributor Author

madebr commented May 7, 2026

I will squash the extra commits to one after review.
With these extra changes, a SDL3 built without loadso works out-of-the box (albeit with x11 and no wayland).
Such a SDL3 library can be created by configuring with -DHAVE_DLOPEN_IN_LIBC=OFF -DHAVE_DLOPEN_IN_LIBDL=OFF.
Running testsprite with SDL3 from main (without loadso) fails because wayland does not run (I think missing egl/gl support). Only the x11 backend works.

I hacked on the CMake build script until dlopen-notes.py libSDL3.so showed 0 runtime dependencies.

Comment thread cmake/sdlchecks.cmake Outdated
set(SDL_UDEV_DYNAMIC "\"${UDEV_LIB_SONAME}\"")
set(HAVE_LIBUDEV TRUE)
if(NOT HAVE_SDL_LOADSO)
message(WARNING "You must have SDL_LoadObject() support for libudev support")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe we can link with -ludev normally and not dynamically load it. If that's not true, the we should probably fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added this support. I'm going to create a separate pr for this.

Comment thread CMakeLists.txt Outdated

if(SDL_LIBURING)
set(HAVE_LIBURING_H FALSE)
if(SDL_LIBURING AND HAVE_SDL_LOADSO)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same with liburing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same: I will create a separate pr for this.

@madebr madebr force-pushed the cmake-check-dlopen branch from df6d0ba to 1e9aa6a Compare May 7, 2026 18:57
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.

Problem transferring executable from Alpine to Mint

2 participants