SDL_dynapi_dlopennote.h 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef SDL_dynapi_dlopennote_h
  19. #define SDL_dynapi_dlopennote_h
  20. #define SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED "required"
  21. #define SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED "recommended"
  22. #define SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED "suggested"
  23. #if defined(__ELF__) && defined(HAVE_DLOPEN_NOTES)
  24. #define SDL_ELF_NOTE_DLOPEN_VENDOR "FDO"
  25. #define SDL_ELF_NOTE_DLOPEN_TYPE 0x407c0c0aU
  26. #define SDL_ELF_NOTE_INTERNAL2(json, variable_name) \
  27. __attribute__((aligned(4), used, section(".note.dlopen"))) \
  28. static const struct { \
  29. struct { \
  30. Uint32 n_namesz; \
  31. Uint32 n_descsz; \
  32. Uint32 n_type; \
  33. } nhdr; \
  34. char name[4]; \
  35. __attribute__((aligned(4))) char dlopen_json[sizeof(json)]; \
  36. } variable_name = { \
  37. { \
  38. sizeof(SDL_ELF_NOTE_DLOPEN_VENDOR), \
  39. sizeof(json), \
  40. SDL_ELF_NOTE_DLOPEN_TYPE \
  41. }, \
  42. SDL_ELF_NOTE_DLOPEN_VENDOR, \
  43. json \
  44. }
  45. #define SDL_ELF_NOTE_INTERNAL(json, variable_name) \
  46. SDL_ELF_NOTE_INTERNAL2(json, variable_name)
  47. #define SDL_SONAME_ARRAY1(N1) "[\"" N1 "\"]"
  48. #define SDL_SONAME_ARRAY2(N1,N2) "[\"" N1 "\",\"" N2 "\"]"
  49. #define SDL_SONAME_ARRAY3(N1,N2,N3) "[\"" N1 "\",\"" N2 "\",\"" N3 "\"]"
  50. #define SDL_SONAME_ARRAY4(N1,N2,N3,N4) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\"]"
  51. #define SDL_SONAME_ARRAY5(N1,N2,N3,N4,N5) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\"]"
  52. #define SDL_SONAME_ARRAY6(N1,N2,N3,N4,N5,N6) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\"]"
  53. #define SDL_SONAME_ARRAY7(N1,N2,N3,N4,N5,N6,N7) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\"]"
  54. #define SDL_SONAME_ARRAY8(N1,N2,N3,N4,N5,N6,N7,N8) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\",\"" N8 "\"]"
  55. #define SDL_SONAME_ARRAY_GET(N1,N2,N3,N4,N5,N6,N7,N8,NAME,...) NAME
  56. #define SDL_SONAME_ARRAY(...) \
  57. SDL_SONAME_ARRAY_GET(__VA_ARGS__, \
  58. SDL_SONAME_ARRAY8, \
  59. SDL_SONAME_ARRAY7, \
  60. SDL_SONAME_ARRAY6, \
  61. SDL_SONAME_ARRAY5, \
  62. SDL_SONAME_ARRAY4, \
  63. SDL_SONAME_ARRAY3, \
  64. SDL_SONAME_ARRAY2, \
  65. SDL_SONAME_ARRAY1 \
  66. )(__VA_ARGS__)
  67. // Create "unique" variable name using __LINE__,
  68. // so creating elf notes on the same line is not supported
  69. #define SDL_ELF_NOTE_JOIN2(A,B) A##B
  70. #define SDL_ELF_NOTE_JOIN(A,B) SDL_ELF_NOTE_JOIN2(A,B)
  71. #define SDL_ELF_NOTE_UNIQUE_NAME SDL_ELF_NOTE_JOIN(s_dlopen_note_, __LINE__)
  72. #define SDL_ELF_NOTE_DLOPEN(feature, description, priority, ...) \
  73. SDL_ELF_NOTE_INTERNAL( \
  74. "[{\"feature\":\"" feature \
  75. "\",\"description\":\"" description \
  76. "\",\"priority\":\"" priority \
  77. "\",\"soname\":" SDL_SONAME_ARRAY(__VA_ARGS__) "}]", \
  78. SDL_ELF_NOTE_UNIQUE_NAME)
  79. #else
  80. #define SDL_ELF_NOTE_DLOPEN(...)
  81. #endif
  82. #endif