Skip to content

Commit c8fe877

Browse files
committed
Improve cross-compiling
- Use cross-compiling emulator checks where needed - Refactor dlsym underscore check - Refactor remaining checks This now leaves only the ext/standard crypt checks left to fix.
1 parent 6651967 commit c8fe877

File tree

8 files changed

+221
-194
lines changed

8 files changed

+221
-194
lines changed

cmake/Zend/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,10 @@ endif()
456456

457457
if(PHPSystem_EXECUTABLE)
458458
set(PHP_EXECUTABLE ${PHPSystem_EXECUTABLE})
459-
elseif(NOT CMAKE_CROSSCOMPILING)
459+
elseif(
460+
NOT CMAKE_CROSSCOMPILING
461+
OR (CMAKE_CROSSCOMPILING AND CMAKE_CROSSCOMPILING_EMULATOR)
462+
)
460463
set(PHP_EXECUTABLE "$<TARGET_FILE:php_cli>")
461464
endif()
462465

cmake/cmake/Requirements.cmake

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ endif()
2525
# Check whether the system uses EBCDIC (not ASCII) as its native character set.
2626
################################################################################
2727
message(CHECK_START "Checking system character set")
28-
if(NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)
29-
cmake_push_check_state(RESET)
30-
set(CMAKE_REQUIRED_QUIET TRUE)
31-
check_source_runs(C [[
32-
int main(void) {
33-
return (unsigned char)'A' != (unsigned char)0xC1;
34-
}
35-
]] _php_is_ebcdic)
36-
cmake_pop_check_state()
37-
38-
if(_php_is_ebcdic)
39-
message(CHECK_FAIL "EBCDIC")
40-
message(FATAL_ERROR "PHP does not support EBCDIC targets")
41-
else()
42-
message(CHECK_PASS "ASCII")
43-
endif()
28+
if(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
29+
# EBCDIC targets are obsolete, assume that target uses ASCII when
30+
# cross-compiling without emulator.
31+
set(PHP_IS_EBCDIC_EXITCODE 1)
32+
endif()
33+
34+
cmake_push_check_state(RESET)
35+
set(CMAKE_REQUIRED_QUIET TRUE)
36+
check_source_runs(C [[
37+
int main(void) { return (unsigned char)'A' != (unsigned char)0xC1; }
38+
]] PHP_IS_EBCDIC)
39+
cmake_pop_check_state()
40+
41+
if(PHP_IS_EBCDIC)
42+
message(CHECK_FAIL "EBCDIC")
43+
message(FATAL_ERROR "PHP does not support EBCDIC targets")
4444
else()
45-
message(CHECK_FAIL "unknown, assuming ASCII (cross-compiling)")
45+
message(CHECK_PASS "ASCII")
4646
endif()
4747

4848
################################################################################

cmake/cmake/modules/PHP/CheckByteOrder.cmake

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,37 @@ if(CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN")
1818
elseif(CMAKE_C_BYTE_ORDER STREQUAL "LITTLE_ENDIAN")
1919
message(CHECK_PASS "little-endian")
2020
else()
21-
if(NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)
22-
check_source_runs(C [[
23-
int main(void)
24-
{
25-
short one = 1;
26-
char *cp = (char *)&one;
27-
28-
if (*cp == 0) {
29-
return 0;
30-
}
31-
32-
return 1;
33-
}
34-
]] WORDS_BIGENDIAN)
21+
if(
22+
NOT DEFINED WORDS_BIGENDIAN_EXITCODE
23+
AND CMAKE_CROSSCOMPILING
24+
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
25+
)
26+
message(
27+
NOTICE
28+
"Byte ordering could not be detected, assuming the target system is "
29+
"little-endian. Set 'WORDS_BIGENDIAN_EXITCODE' to '0' if targeting a "
30+
"big-endian system."
31+
)
32+
set(WORDS_BIGENDIAN_EXITCODE 1)
3533
endif()
3634

35+
check_source_runs(C [[
36+
int main(void)
37+
{
38+
short one = 1;
39+
char *cp = (char *)&one;
40+
41+
if (*cp == 0) {
42+
return 0;
43+
}
44+
45+
return 1;
46+
}
47+
]] WORDS_BIGENDIAN)
48+
3749
if(WORDS_BIGENDIAN)
3850
message(CHECK_PASS "big-endian")
39-
elseif(DEFINED WORDS_BIGENDIAN)
40-
message(CHECK_PASS "little-endian")
4151
else()
42-
message(CHECK_FAIL "unknown (cross-compiling)")
43-
message(
44-
WARNING
45-
"Byte ordering could not be detected, assuming system is little-endian. "
46-
"Set 'WORDS_BIGENDIAN' to 'ON' if targeting a big-endian system."
47-
)
52+
message(CHECK_PASS "little-endian")
4853
endif()
4954
endif()

cmake/cmake/modules/Zend/CheckDlsym.cmake

Lines changed: 92 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)
114118
endif()
115119

116120
if(DLSYM_NEEDS_UNDERSCORE)

0 commit comments

Comments
 (0)