dlopennote: update documentation and internal variable names

This commit is contained in:
Anonymous Maarten
2025-10-14 20:23:40 +02:00
committed by Anonymous Maarten
parent 5c03796ac7
commit 6840bbef58
+43 -40
View File
@@ -32,21 +32,23 @@
* this CMake snippet to check for support: * this CMake snippet to check for support:
* *
* ```cmake * ```cmake
* set(CHECK_ELF_DLNOTES_SRC [==[ * include(CheckCSourceCompiles)
* #ifndef __ELF__ * find_package(SDL3 REQUIRED CONFIG COMPONENTS Headers)
* ELF DL notes is only supported on ELF platforms * list(APPEND CMAKE_REQUIRED_LIBRARIES SDL3::Headers)
* #endif * check_c_source_compiles([==[
* __attribute__ ((used,aligned(4),section(".note.dlopen"))) static const struct { * #include <SDL3/SDL_dlopennote.h>
* struct { int a; int b; int c; } hdr; char name[4]; __attribute__((aligned(4))) char json[24]; * SDL_ELF_NOTE_DLOPEN("sdl-video",
* } dlnote = { { 4, 0x407c0c0aU, 16 }, "FDO", "[\\"a\\":{\\"a\\":\\"1\\",\\"b\\":\\"2\\"}]" }; * "Support for video through SDL",
* int main(int argc, char *argv[]) { * SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
* return argc + dlnote.hdr.a; * "libSDL-1.2.so.0", "libSDL-2.0.so.0", "libSDL3.so.0"
* } * );
* ]==]) * int main(int argc, char *argv[]) {
* check_c_source_compiles("${CHECK_ELF_DLNOTES_SRC}" COMPILER_SUPPORTS_ELFNOTES) * return argc + argv[0][1];
* if(NOT COMPILER_SUPPORTS_ELFNOTES) * }
* set(SDL_DISABLE_DLOPEN_NOTES TRUE) * ]==] COMPILER_SUPPORTS_SDL_ELF_NOTE_DLOPEN)
* endif() * if(NOT COMPILER_SUPPORTS_SDL_ELF_NOTE_DLOPEN)
* add_compile_definitions(-DSDL_DISABLE_DLOPEN_NOTE)
* endif()
* ``` * ```
*/ */
@@ -141,33 +143,34 @@
#define SDL_ELF_NOTE_INTERNAL(json, variable_name) \ #define SDL_ELF_NOTE_INTERNAL(json, variable_name) \
SDL_ELF_NOTE_INTERNAL2(json, variable_name) SDL_ELF_NOTE_INTERNAL2(json, variable_name)
#define SDL_SONAME_ARRAY1(N1) "[\"" N1 "\"]" #define SDL_DLNOTE_JSON_ARRAY1(N1) "[\"" N1 "\"]"
#define SDL_SONAME_ARRAY2(N1,N2) "[\"" N1 "\",\"" N2 "\"]" #define SDL_DLNOTE_JSON_ARRAY2(N1,N2) "[\"" N1 "\",\"" N2 "\"]"
#define SDL_SONAME_ARRAY3(N1,N2,N3) "[\"" N1 "\",\"" N2 "\",\"" N3 "\"]" #define SDL_DLNOTE_JSON_ARRAY3(N1,N2,N3) "[\"" N1 "\",\"" N2 "\",\"" N3 "\"]"
#define SDL_SONAME_ARRAY4(N1,N2,N3,N4) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\"]" #define SDL_DLNOTE_JSON_ARRAY4(N1,N2,N3,N4) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\"]"
#define SDL_SONAME_ARRAY5(N1,N2,N3,N4,N5) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\"]" #define SDL_DLNOTE_JSON_ARRAY5(N1,N2,N3,N4,N5) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\"]"
#define SDL_SONAME_ARRAY6(N1,N2,N3,N4,N5,N6) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\"]" #define SDL_DLNOTE_JSON_ARRAY6(N1,N2,N3,N4,N5,N6) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\"]"
#define SDL_SONAME_ARRAY7(N1,N2,N3,N4,N5,N6,N7) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\"]" #define SDL_DLNOTE_JSON_ARRAY7(N1,N2,N3,N4,N5,N6,N7) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\"]"
#define SDL_SONAME_ARRAY8(N1,N2,N3,N4,N5,N6,N7,N8) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\",\"" N8 "\"]" #define SDL_DLNOTE_JSON_ARRAY8(N1,N2,N3,N4,N5,N6,N7,N8) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\",\"" N8 "\"]"
#define SDL_SONAME_ARRAY_GET(N1,N2,N3,N4,N5,N6,N7,N8,NAME,...) NAME #define SDL_DLNOTE_JSON_ARRAY_GET(N1,N2,N3,N4,N5,N6,N7,N8,NAME,...) NAME
#define SDL_SONAME_ARRAY(...) \ #define SDL_DLNOTE_JSON_ARRAY(...) \
SDL_SONAME_ARRAY_GET(__VA_ARGS__, \ SDL_DLNOTE_JSON_ARRAY_GET( \
SDL_SONAME_ARRAY8, \ __VA_ARGS__, \
SDL_SONAME_ARRAY7, \ SDL_DLNOTE_JSON_ARRAY8, \
SDL_SONAME_ARRAY6, \ SDL_DLNOTE_JSON_ARRAY7, \
SDL_SONAME_ARRAY5, \ SDL_DLNOTE_JSON_ARRAY6, \
SDL_SONAME_ARRAY4, \ SDL_DLNOTE_JSON_ARRAY5, \
SDL_SONAME_ARRAY3, \ SDL_DLNOTE_JSON_ARRAY4, \
SDL_SONAME_ARRAY2, \ SDL_DLNOTE_JSON_ARRAY3, \
SDL_SONAME_ARRAY1 \ SDL_DLNOTE_JSON_ARRAY2, \
SDL_DLNOTE_JSON_ARRAY1 \
)(__VA_ARGS__) )(__VA_ARGS__)
/* Create "unique" variable name using __LINE__, /* Create "unique" variable name using __LINE__,
* so creating elf notes on the same line is not supported * so creating multiple elf notes on the same line is not supported
*/ */
#define SDL_ELF_NOTE_JOIN2(A,B) A##B #define SDL_DLNOTE_JOIN2(A,B) A##B
#define SDL_ELF_NOTE_JOIN(A,B) SDL_ELF_NOTE_JOIN2(A,B) #define SDL_DLNOTE_JOIN(A,B) SDL_DLNOTE_JOIN2(A,B)
#define SDL_ELF_NOTE_UNIQUE_NAME SDL_ELF_NOTE_JOIN(s_SDL_dlopen_note_, __LINE__) #define SDL_DLNOTE_UNIQUE_NAME SDL_DLNOTE_JOIN(s_SDL_dlopen_note_, __LINE__)
/** /**
* Note that your application has dynamic shared library dependencies. * Note that your application has dynamic shared library dependencies.
@@ -206,8 +209,8 @@
"[{\"feature\":\"" feature \ "[{\"feature\":\"" feature \
"\",\"description\":\"" description \ "\",\"description\":\"" description \
"\",\"priority\":\"" priority \ "\",\"priority\":\"" priority \
"\",\"soname\":" SDL_SONAME_ARRAY(__VA_ARGS__) "}]", \ "\",\"soname\":" SDL_DLNOTE_JSON_ARRAY(__VA_ARGS__) "}]", \
SDL_ELF_NOTE_UNIQUE_NAME) SDL_DLNOTE_UNIQUE_NAME)
#elif defined(__GNUC__) && __GNUC__ < 3 #elif defined(__GNUC__) && __GNUC__ < 3