Skip to content

Conversation

madebr
Copy link
Contributor

@madebr madebr commented Oct 14, 2025

I removed the cmake comment in the documentation since I feel CMake does not belong in the public headers.

Projects can make sure their toolchain supports SDL_ELF_NOTE_DLOPEN through this fragment:

find_package(SDL3 REQUIRED COMPONENTS Headers)
set(CMAKE_REQUIRED_LIBRARIES SDL3::Headers)
check_c_source_compiles([==[
    #include <SDL3/SDL_dlopennote.h>
    SDL_ELF_NOTE_DLOPEN("sdl-video",
        "Support for video through SDL",
        SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
        "libSDL-1.2.so.0", "libSDL-2.0.so.0", "libSDL3.so.0"
    );
    int main(int argc, char *argv[]) {
      return argc + argv[0][1];
    }
  ]==] COMPILER_SUPPORTS_SDL_ELF_NOTE_DLOPEN)

We document how to disable the macro. CMake/meson developers should know what do do with that.

Here's how to test without using the SDL3 headers:

include(CheckCSourceCompiles)
check_c_source_compiles([==[
    #ifndef __ELF__
      ELF DL notes are only supported on ELF platforms
    #endif
    #define ARR1(N1) "[\"" N1 "\"]"
    #define ARR2(N1, N2) "[\"" N1 "\",\"" N2 "\"]"
    #define ARR_GET(N1,N2,NAME,...) NAME
    #define ARR(...) ARR_GET(__VA_ARGS__, ARR2, ARR1)(__VA_ARGS__)
    #define JOIN2(A,B) A##B
    #define JOIN(A,B) JOIN2(A,B)
    #define UNIQ JOIN(s_global, __LINE__)
    #define DLNOTE_INT2(JSON,VARNAME) \\
      __attribute__ ((used,aligned(4),section(".note.dlopen"))) static const struct { \\
        struct { int a; int b; } v; __attribute__((aligned(4))) char dlopen_json[sizeof(JSON)]; \\
      } VARNAME = { { 4, 0x407c0c0aU }, JSON }
    #define DLNOTE_INT(JSON,VARNAME) DLNOTE_INT2(JSON,VARNAME)
    #define DLNOTE(P,...) DLNOTE_INT("[" P "," ARR(__VA_ARGS__) "]", UNIQ)
    DLNOTE("required", "liba.so.0");
    DLNOTE("recommended", "libb.so.0", "libb.so.1");
    int main(int argc, char *argv[]) {
      return argc + argv[0][1];
    }
  ]==] COMPILER_SUPPORTS_ELFNOTES)

Description

Existing Issue(s)

Closes #14214

@madebr madebr changed the title Dlnotes suggestions Don['t define SDL_ELF_NOTE_DLOPEN when compiler does not support variadic macro's Oct 14, 2025
@madebr madebr changed the title Don['t define SDL_ELF_NOTE_DLOPEN when compiler does not support variadic macro's Don't define SDL_ELF_NOTE_DLOPEN when compiler does not support variadic macro's Oct 14, 2025
"\",\"description\":\"" description \
"\",\"priority\":\"" priority \
"\",\"soname\":" SDL_SONAME_ARRAY(__VA_ARGS__) "}]", \
"\",\"soname\":" SDL_ELF_JSON_ARRAY(__VA_ARGS__) "}]", \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"\",\"soname\":" SDL_ELF_JSON_ARRAY(__VA_ARGS__) "}]", \
"\",\"soname\":" SDL_DLNOTE_JSON_ARRAY(__VA_ARGS__) "}]", \

@slouken
Copy link
Collaborator

slouken commented Oct 14, 2025

Projects can make sure their toolchain supports SDL_ELF_NOTE_DLOPEN through this fragment:

This needs to be documented somewhere...

@madebr madebr force-pushed the dlnotes-suggestions branch from 7cdb1fc to 12f8efa Compare October 14, 2025 18:56
@madebr madebr force-pushed the dlnotes-suggestions branch from 12f8efa to 5e65ffc Compare October 14, 2025 19:04
@madebr
Copy link
Contributor Author

madebr commented Oct 14, 2025

This needs to be documented somewhere...

I reinstated it, but the test is simply trying to use the SDL macro and sets the macro if the test failed.

@slouken
Copy link
Collaborator

slouken commented Oct 14, 2025

This needs to be documented somewhere...

I reinstated it, but the test is simply trying to use the SDL macro and sets the macro if the test failed.

It doesn't have to be in the header, it can be in a README, it just needs to be referenced here. Feel free to put the real test in the README. Maybe we need README-dlnotes.md? :)

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.

SDL_ELF_NOTE_DLOPEN cannot be used with a toolchain not supporting variadic macros

2 participants