Skip to content

Commit 0a6b807

Browse files
authored
Record dynamic dependencies in .note.dlopen elf section
1 parent 152ba82 commit 0a6b807

26 files changed

+435
-36
lines changed

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ dep_option(SDL_ARMNEON "Use NEON assembly routines" ON "SDL_ASSEMBLY
302302
dep_option(SDL_LSX "Use LSX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_LOONGARCH64" OFF)
303303
dep_option(SDL_LASX "Use LASX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_LOONGARCH64" OFF)
304304

305+
dep_option(SDL_DLOPEN_NOTES "Record dlopen dependencies in .note.dlopen section" TRUE UNIX_SYS OFF)
305306
set_option(SDL_LIBC "Use the system C library" ${SDL_LIBC_DEFAULT})
306307
set_option(SDL_SYSTEM_ICONV "Use iconv() from system-installed libraries" ${SDL_SYSTEM_ICONV_DEFAULT})
307308
set_option(SDL_LIBICONV "Prefer iconv() from libiconv, if available, over libc version" OFF)
@@ -1712,6 +1713,25 @@ elseif(EMSCRIPTEN)
17121713
CheckLibUnwind()
17131714

17141715
elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
1716+
1717+
if(SDL_DLOPEN_NOTES)
1718+
set(CHECK_ELF_DLNOTES_SRC [==[
1719+
#ifndef __ELF__
1720+
ELF DL notes is only supported on ELF platforms
1721+
#endif
1722+
__attribute__ ((used,aligned(4),section(".note.dlopen"))) static const struct {
1723+
struct { int a; int b; int c; } hdr; char name[4]; __attribute__((aligned(4))) char json[24];
1724+
} dlnote = { { 4, 0x407c0c0aU, 16 }, "FDO", "[\\"a\\":{\\"a\\":\\"1\\",\\"b\\":\\"2\\"}]" };
1725+
int main(int argc, char *argv[]) {
1726+
return argc + dlnote.hdr.a;
1727+
}
1728+
]==])
1729+
check_c_source_compiles("${CHECK_ELF_DLNOTES_SRC}" COMPILER_SUPPORTS_ELFNOTES)
1730+
if(COMPILER_SUPPORTS_ELFNOTES)
1731+
set(HAVE_DLOPEN_NOTES TRUE)
1732+
endif()
1733+
endif()
1734+
17151735
if(SDL_AUDIO)
17161736
if(NETBSD)
17171737
set(SDL_AUDIO_DRIVER_NETBSD 1)

docs/README-linux.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Ubuntu 22.04+ can also add `libpipewire-0.3-dev libwayland-dev libdecor-0-dev li
2626
Fedora 35, all available features enabled:
2727

2828
sudo yum install gcc git-core make cmake \
29-
alsa-lib-devel pulseaudio-libs-devel nas-devel pipewire-devel \
29+
alsa-lib-devel pulseaudio-libs-devel pipewire-devel \
3030
libX11-devel libXext-devel libXrandr-devel libXcursor-devel libXfixes-devel \
3131
libXi-devel libXScrnSaver-devel dbus-devel ibus-devel \
3232
systemd-devel mesa-libGL-devel libxkbcommon-devel mesa-libGLES-devel \

include/build_config/SDL_build_config.h.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@
235235
#cmakedefine HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR 1
236236
#cmakedefine HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP 1
237237

238+
#cmakedefine HAVE_DLOPEN_NOTES 1
239+
238240
/* SDL internal assertion support */
239241
#cmakedefine SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED 1
240242
#ifdef SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED

src/SDL_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "SDL_build_config.h"
6464

6565
#include "dynapi/SDL_dynapi.h"
66+
#include "dynapi/SDL_dynapi_dlopennote.h"
6667

6768
#if SDL_DYNAMIC_API
6869
#include "dynapi/SDL_dynapi_overrides.h"

src/audio/aaudio/SDL_aaudio.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ struct SDL_PrivateAudioData
5353

5454
#define LIB_AAUDIO_SO "libaaudio.so"
5555

56+
SDL_ELF_NOTE_DLOPEN(
57+
"audio-aaudio",
58+
"Support for audio through AAudio",
59+
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
60+
LIB_AAUDIO_SO
61+
);
62+
5663
typedef struct AAUDIO_Data
5764
{
5865
SDL_SharedObject *handle;
@@ -313,8 +320,8 @@ static bool BuildAAudioStream(SDL_AudioDevice *device)
313320
ctx.AAudioStreamBuilder_setFormat(builder, format);
314321
ctx.AAudioStreamBuilder_setSampleRate(builder, device->spec.freq);
315322
ctx.AAudioStreamBuilder_setChannelCount(builder, device->spec.channels);
316-
317-
// If no specific buffer size has been requested, the device will pick the optimal
323+
324+
// If no specific buffer size has been requested, the device will pick the optimal
318325
if(SDL_GetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES)) {
319326
ctx.AAudioStreamBuilder_setBufferCapacityInFrames(builder, 2 * device->sample_frames); // AAudio requires that the buffer capacity is at least
320327
ctx.AAudioStreamBuilder_setFramesPerDataCallback(builder, device->sample_frames); // twice the size of the data callback buffer size

src/audio/alsa/SDL_alsa_audio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ static bool load_alsa_syms(void)
207207

208208
#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
209209

210+
SDL_ELF_NOTE_DLOPEN(
211+
"audio-libalsa",
212+
"Support for audio through libalsa",
213+
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
214+
SDL_AUDIO_DRIVER_ALSA_DYNAMIC
215+
);
216+
210217
static void UnloadALSALibrary(void)
211218
{
212219
if (alsa_handle) {

src/audio/jack/SDL_jackaudio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ static bool load_jack_syms(void);
5050

5151
#ifdef SDL_AUDIO_DRIVER_JACK_DYNAMIC
5252

53+
SDL_ELF_NOTE_DLOPEN(
54+
"audio-libjack",
55+
"Support for audio through libjack",
56+
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
57+
SDL_AUDIO_DRIVER_JACK_DYNAMIC
58+
);
59+
5360
static const char *jack_library = SDL_AUDIO_DRIVER_JACK_DYNAMIC;
5461
static SDL_SharedObject *jack_handle = NULL;
5562

src/audio/pipewire/SDL_pipewire.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ static int (*PIPEWIRE_pw_properties_setf)(struct pw_properties *, const char *,
9393

9494
#ifdef SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC
9595

96+
SDL_ELF_NOTE_DLOPEN(
97+
"audio-libpipewire",
98+
"Support for audio through libpipewire",
99+
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
100+
SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC
101+
);
102+
96103
static const char *pipewire_library = SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC;
97104
static SDL_SharedObject *pipewire_handle = NULL;
98105

src/audio/pulseaudio/SDL_pulseaudio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ static bool load_pulseaudio_syms(void);
133133

134134
#ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
135135

136+
SDL_ELF_NOTE_DLOPEN(
137+
"audio-libpulseaudio",
138+
"Support for audio through libpulseaudio",
139+
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
140+
SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
141+
);
142+
136143
static const char *pulseaudio_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC;
137144
static SDL_SharedObject *pulseaudio_handle = NULL;
138145

src/audio/sndio/SDL_sndioaudio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ static bool load_sndio_syms(void)
108108

109109
#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
110110

111+
SDL_ELF_NOTE_DLOPEN(
112+
"audio-libsndio",
113+
"Support for audio through libsndio",
114+
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
115+
SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
116+
);
117+
111118
static void UnloadSNDIOLibrary(void)
112119
{
113120
if (sndio_handle) {

0 commit comments

Comments
 (0)