@@ -20,97 +20,101 @@ message(
2020 "Checking whether dlsym() requires a leading underscore in symbol names"
2121)
2222
23- if (CMAKE_CROSSCOMPILING_EMULATOR OR NOT CMAKE_CROSSCOMPILING )
24- check_include_file(dlfcn.h HAVE_DLFCN_H)
25-
26- block()
27- if (HAVE_DLFCN_H)
28- set (definitions "-DHAVE_DLFCN_H=1" )
29- endif ()
30-
31- try_run (
32- ZEND_DLSYM_RUN_RESULT
33- ZEND_DLSYM_COMPILE_RESULT
34- SOURCE_FROM_CONTENT src.c [[
35- #ifdef HAVE_DLFCN_H
36- #include <dlfcn.h>
37- #endif
38-
39- #include <stdio.h>
40-
41- #ifdef RTLD_GLOBAL
42- # define LT_DLGLOBAL RTLD_GLOBAL
43- #else
44- # ifdef DL_GLOBAL
45- # define LT_DLGLOBAL DL_GLOBAL
46- # else
47- # define LT_DLGLOBAL 0
48- # endif
49- #endif
50-
51- /* We may need to define LT_DLLAZY_OR_NOW on the command line if we
52- discover that it does not work on some platform. */
53- #ifndef LT_DLLAZY_OR_NOW
54- # ifdef RTLD_LAZY
55- # define LT_DLLAZY_OR_NOW RTLD_LAZY
56- # else
57- # ifdef DL_LAZY
58- # define LT_DLLAZY_OR_NOW DL_LAZY
59- # else
60- # ifdef RTLD_NOW
61- # define LT_DLLAZY_OR_NOW RTLD_NOW
62- # else
63- # ifdef DL_NOW
64- # define LT_DLLAZY_OR_NOW DL_NOW
65- # else
66- # define LT_DLLAZY_OR_NOW 0
67- # endif
68- # endif
69- # endif
70- # endif
71- #endif
72-
73- /* When -fvisibility=hidden is used, assume the code has been annotated
74- correspondingly for the symbols needed. */
75- #if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
76- int fnord(void) __attribute__((visibility("default")));
77- #endif
78-
79- int fnord(void) { return 42; }
80-
81- int main(void)
82- {
83- void *self = dlopen(0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
84- int status = 0;
85-
86- if (self) {
87- if (dlsym(self, "fnord")) {
88- status = 1;
89- } else if (dlsym(self, "_fnord")) {
90- status = 2;
91- } else {
92- puts (dlerror());
93- }
94- /* dlclose(self); */
23+ if (CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
24+ # When cross-compiling without emulator, assume that target platform is recent
25+ # enough so that dlsym doesn't need leading underscores.
26+ set (DLSYM_NEEDS_UNDERSCORE_EXITCODE 0)
27+ endif ()
28+
29+ check_include_file(dlfcn.h HAVE_DLFCN_H)
30+
31+ block()
32+ if (HAVE_DLFCN_H)
33+ set (definitions "-DHAVE_DLFCN_H=1" )
34+ endif ()
35+
36+ try_run (
37+ DLSYM_NEEDS_UNDERSCORE_EXITCODE
38+ DLSYM_NEEDS_UNDERSCORE_COMPILED
39+ SOURCE_FROM_CONTENT src.c [[
40+ #ifdef HAVE_DLFCN_H
41+ # include <dlfcn.h>
42+ #endif
43+
44+ #include <stdio.h>
45+
46+ #ifdef RTLD_GLOBAL
47+ # define LT_DLGLOBAL RTLD_GLOBAL
48+ #else
49+ # ifdef DL_GLOBAL
50+ # define LT_DLGLOBAL DL_GLOBAL
51+ # else
52+ # define LT_DLGLOBAL 0
53+ # endif
54+ #endif
55+
56+ /* We may need to define LT_DLLAZY_OR_NOW on the command line if we
57+ discover that it does not work on some platform. */
58+ #ifndef LT_DLLAZY_OR_NOW
59+ # ifdef RTLD_LAZY
60+ # define LT_DLLAZY_OR_NOW RTLD_LAZY
61+ # else
62+ # ifdef DL_LAZY
63+ # define LT_DLLAZY_OR_NOW DL_LAZY
64+ # else
65+ # ifdef RTLD_NOW
66+ # define LT_DLLAZY_OR_NOW RTLD_NOW
67+ # else
68+ # ifdef DL_NOW
69+ # define LT_DLLAZY_OR_NOW DL_NOW
70+ # else
71+ # define LT_DLLAZY_OR_NOW 0
72+ # endif
73+ # endif
74+ # endif
75+ # endif
76+ #endif
77+
78+ /* When -fvisibility=hidden is used, assume the code has been annotated
79+ correspondingly for the symbols needed. */
80+ #if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
81+ int fnord(void) __attribute__((visibility("default")));
82+ #endif
83+
84+ int fnord(void) { return 42; }
85+
86+ int main(void)
87+ {
88+ void *self = dlopen(0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
89+ int status = 0;
90+
91+ if (self) {
92+ if (dlsym(self, "fnord")) {
93+ status = 1;
94+ } else if (dlsym(self, "_fnord")) {
95+ status = 2;
9596 } else {
96- puts(dlerror());
97+ puts (dlerror());
9798 }
98-
99- return (status);
99+ /* dlclose(self); */
100+ } else {
101+ puts(dlerror());
100102 }
101- ]]
102- COMPILE_DEFINITIONS ${definitions}
103- LINK_LIBRARIES ${CMAKE_DL_LIBS}
104- )
105- endblock()
106-
107- if (ZEND_DLSYM_COMPILE_RESULT AND ZEND_DLSYM_RUN_RESULT EQUAL 2)
108- set (
109- DLSYM_NEEDS_UNDERSCORE 1
110- CACHE INTERNAL
111- "Whether dlsym() requires a leading underscore in symbol names."
112- )
113- endif ()
103+
104+ return status;
105+ }
106+ ]]
107+ COMPILE_DEFINITIONS ${definitions}
108+ LINK_LIBRARIES ${CMAKE_DL_LIBS}
109+ )
110+ endblock()
111+
112+ if (DLSYM_NEEDS_UNDERSCORE_COMPILED AND DLSYM_NEEDS_UNDERSCORE_EXITCODE EQUAL 2)
113+ set (
114+ DLSYM_NEEDS_UNDERSCORE 1
115+ CACHE INTERNAL
116+ "Whether dlsym() requires a leading underscore in symbol names."
117+ )
114118endif ()
115119
116120if (DLSYM_NEEDS_UNDERSCORE)
0 commit comments