SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Unify shared library loading

Open icculus opened this issue 1 year ago • 9 comments

This isn't an ABI issue, or even a 3.2.0 thing, but I remember this every six months, so I'm writing it down:

We have a bunch of code that loads shared libraries: X11, PulseAudio, 20 other things. Several of them roll their own loaders, others have been copy/pasted from one of these.

Some are using SDL_LoadFunction, some use dlsym.

Some use CMake to find a proper SONAME for the library, some just hardcore a library name (that might be more important for extremely scattered things like Xlib than it is for libdbus, though).

It would be nice if we could unify all this into some standard way of loading functions.

icculus avatar Sep 30 '24 16:09 icculus

It might be worth spending a few minutes to see if the reasons we're using dlsym() are reasons to change the public API.

slouken avatar Sep 30 '24 16:09 slouken

(Having not looked) my assumption is that some places are using dlsym because they know they're on Unix and it avoids worrying about someone turning off the SDL_loadso subsystem.

icculus avatar Sep 30 '24 20:09 icculus

You can't turn that off anymore, it's part of the core SDL functionality.

slouken avatar Sep 30 '24 21:09 slouken

Sure, but all that internal loading code hasn't changed since SDL 1.2. :)

Most of the places using dlsym are either Android-specific (but could switch over to SDL_LoadObject), or they are looking at RTLD_DEFAULT instead of a specific library handle. If this is widely supported and we want to offer it in SDL, we can just let SDL_LoadFunction() accept a NULL handle. That wouldn't be an ABI change.

icculus avatar Oct 01 '24 15:10 icculus

(Although we don't actually check for NULL at the moment, so technically the API already works like this on Unix.)

icculus avatar Oct 01 '24 15:10 icculus

BTW, RTLD_DEFAULT need not be defined as NULL, it is implementation defined as far as I recall.

sezero avatar Oct 01 '24 15:10 sezero

Most of the places using dlsym are either Android-specific (but could switch over to SDL_LoadObject), or they are looking at RTLD_DEFAULT instead of a specific library handle. If this is widely supported and we want to offer it in SDL, we can just let SDL_LoadFunction() accept a NULL handle. That wouldn't be an ABI change.

I think that's a good idea.

slouken avatar Oct 01 '24 15:10 slouken

Adding RTLD_DEFAULT support (search all known symbols currently in the process) isn't impossible for Windows, but it isn't trivial. I'd rather not get into it at this point in the milestone if we can avoid it.

icculus avatar Oct 01 '24 16:10 icculus

Sure, that's fine.

slouken avatar Oct 01 '24 16:10 slouken