Skip to content

Commit b327c8c

Browse files
committed
Record dynamic dependencies in .note.dlopen elf section
The data can be used with `dlopen-notes`. The raw date can be viewed with `objdump -j .note.dlopen -s libSDL3.so.0`
1 parent 6c61a94 commit b327c8c

26 files changed

+408
-90
lines changed

CMakeLists.txt

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

323+
dep_option(SDL_DLOPEN_NOTES "Record dlopen dependencies in .note.dlopen section" TRUE UNIX_SYS OFF)
323324
set_option(SDL_LIBC "Use the system C library" ${SDL_LIBC_DEFAULT})
324325
set_option(SDL_SYSTEM_ICONV "Use iconv() from system-installed libraries" ${SDL_SYSTEM_ICONV_DEFAULT})
325326
set_option(SDL_LIBICONV "Prefer iconv() from libiconv, if available, over libc version" OFF)
@@ -1559,6 +1560,25 @@ elseif(EMSCRIPTEN)
15591560
CheckLibUnwind()
15601561

15611562
elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
1563+
1564+
if(SDL_DLOPEN_NOTES)
1565+
set(CHECK_ELF_DLNOTES_SRC [==[
1566+
#ifndef __ELF__
1567+
ELF DL notes is only supported on ELF platforms
1568+
#endif
1569+
__attribute__ ((used,aligned(4),section(".note.dlopen"))) static const struct {
1570+
struct { int a; int b; int c; } hdr; char name[4]; __attribute__((aligned(4))) char json[24];
1571+
} dlnote = { { 4, 0x407c0c0aU, 16 }, "FDO", "[\\"a\\":{\\"a\\":\\"1\\",\\"b\\":\\"2\\"}]" };
1572+
int main(int argc, char *argv[]) {
1573+
return argc + dlnote.hdr.a;
1574+
}
1575+
]==])
1576+
check_c_source_compiles("${CHECK_ELF_DLNOTES_SRC}" COMPILER_SUPPORTS_ELFNOTES)
1577+
if(COMPILER_SUPPORTS_ELFNOTES)
1578+
set(HAVE_DLOPEN_NOTES TRUE)
1579+
endif()
1580+
endif()
1581+
15621582
if(SDL_AUDIO)
15631583
if(NETBSD)
15641584
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
@@ -231,6 +231,8 @@
231231
#cmakedefine HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR 1
232232
#cmakedefine HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP 1
233233

234+
#cmakedefine HAVE_DLOPEN_NOTES 1
235+
234236
/* SDL internal assertion support */
235237
#cmakedefine SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED 1
236238
#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(elfnote_aaudio,
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;
@@ -308,8 +315,8 @@ static bool BuildAAudioStream(SDL_AudioDevice *device)
308315
ctx.AAudioStreamBuilder_setFormat(builder, format);
309316
ctx.AAudioStreamBuilder_setSampleRate(builder, device->spec.freq);
310317
ctx.AAudioStreamBuilder_setChannelCount(builder, device->spec.channels);
311-
312-
// If no specific buffer size has been requested, the device will pick the optimal
318+
319+
// If no specific buffer size has been requested, the device will pick the optimal
313320
if(SDL_GetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES)) {
314321
ctx.AAudioStreamBuilder_setBufferCapacityInFrames(builder, 2 * device->sample_frames); // AAudio requires that the buffer capacity is at least
315322
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(elfnote_alsa,
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(elfnote_libjack,
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(elfnote_pipewire,
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(elfnote_pulseaudio,
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(elfnote_pipewire,
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)