|
| 1 | +From f1ad9199eff32dd805bb5b155002bdb6ca69bf01 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Dmitry Stogov < [email protected]> |
| 3 | +Date: Fri, 16 Apr 2021 17:28:54 +0300 |
| 4 | +Subject: [PATCH] Better support for cross-compilation |
| 5 | + |
| 6 | +--- |
| 7 | + Zend/Zend.m4 | 2 + |
| 8 | + build/php.m4 | 24 ++++++++++-- |
| 9 | + configure.ac | 35 ++++++++++++++++- |
| 10 | + ext/opcache/config.m4 | 71 +++++++++++++++++++---------------- |
| 11 | + ext/opcache/jit/Makefile.frag | 2 +- |
| 12 | + ext/standard/config.m4 | 12 +++++- |
| 13 | + 6 files changed, 106 insertions(+), 40 deletions(-) |
| 14 | + |
| 15 | +diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 |
| 16 | +index 081a237012..a2e506412d 100644 |
| 17 | +--- a/Zend/Zend.m4 |
| 18 | ++++ b/Zend/Zend.m4 |
| 19 | +@@ -276,6 +276,8 @@ int main() |
| 20 | + ], [], [ |
| 21 | + dnl Cross compilation needs something here. |
| 22 | + LIBZEND_MM_ALIGN=8 |
| 23 | ++ AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, 8, [ ]) |
| 24 | ++ AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, 3, [ ]) |
| 25 | + ]) |
| 26 | + |
| 27 | + AC_MSG_RESULT(done) |
| 28 | +diff --git a/build/php.m4 b/build/php.m4 |
| 29 | +index 8994e1fe6a..a4469ac0b1 100644 |
| 30 | +--- a/build/php.m4 |
| 31 | ++++ b/build/php.m4 |
| 32 | +@@ -1477,7 +1477,15 @@ int main() { |
| 33 | + ], [ |
| 34 | + cookie_io_functions_use_off64_t=no |
| 35 | + ], [ |
| 36 | +- cookie_io_functions_use_off64_t=no |
| 37 | ++ dnl Cross compilation. |
| 38 | ++ case $host_alias in |
| 39 | ++ *linux*) |
| 40 | ++ cookie_io_functions_use_off64_t=yes |
| 41 | ++ ;; |
| 42 | ++ *) |
| 43 | ++ cookie_io_functions_use_off64_t=no |
| 44 | ++ ;; |
| 45 | ++ esac |
| 46 | + ]) |
| 47 | + |
| 48 | + else |
| 49 | +@@ -1582,7 +1590,10 @@ AC_DEFUN([PHP_CHECK_FUNC_LIB],[ |
| 50 | + if test "$found" = "yes"; then |
| 51 | + ac_libs=$LIBS |
| 52 | + LIBS="$LIBS -l$2" |
| 53 | +- AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return (0); }]])],[found=yes],[found=no],[found=no]) |
| 54 | ++ AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return (0); }]])],[found=yes],[found=no],[ |
| 55 | ++ dnl Cross compilation. |
| 56 | ++ found=yes |
| 57 | ++ ]) |
| 58 | + LIBS=$ac_libs |
| 59 | + fi |
| 60 | + |
| 61 | +@@ -2298,7 +2309,14 @@ int main() |
| 62 | + ],[ |
| 63 | + ac_cv_write_stdout=no |
| 64 | + ],[ |
| 65 | +- ac_cv_write_stdout=no |
| 66 | ++ case $host_alias in |
| 67 | ++ *linux*) |
| 68 | ++ ac_cv_write_stdout=yes |
| 69 | ++ ;; |
| 70 | ++ *) |
| 71 | ++ ac_cv_write_stdout=no |
| 72 | ++ ;; |
| 73 | ++ esac |
| 74 | + ]) |
| 75 | + ]) |
| 76 | + if test "$ac_cv_write_stdout" = "yes"; then |
| 77 | +diff --git a/configure.ac b/configure.ac |
| 78 | +index e626fd7687..b358a666a7 100644 |
| 79 | +--- a/configure.ac |
| 80 | ++++ b/configure.ac |
| 81 | +@@ -133,6 +133,14 @@ AC_PROG_CPP |
| 82 | + AC_USE_SYSTEM_EXTENSIONS |
| 83 | + AC_PROG_LN_S |
| 84 | + |
| 85 | ++if test "$cross_compiling" = yes ; then |
| 86 | ++ AC_MSG_CHECKING(for native build C compiler) |
| 87 | ++ AC_CHECK_PROGS(BUILD_CC, [gcc clang c99 c89 cc cl],none) |
| 88 | ++ AC_MSG_RESULT($BUILD_CC) |
| 89 | ++else |
| 90 | ++ BUILD_CC=$CC |
| 91 | ++fi |
| 92 | ++ |
| 93 | + dnl Support systems with system libraries in e.g. /usr/lib64. |
| 94 | + PHP_ARG_WITH([libdir], |
| 95 | + [for system library directory], |
| 96 | +@@ -645,7 +653,17 @@ int main(void) { |
| 97 | + freeaddrinfo(ai); |
| 98 | + return 0; |
| 99 | + } |
| 100 | +- ]])],[ac_cv_func_getaddrinfo=yes], [ac_cv_func_getaddrinfo=no], [ac_cv_func_getaddrinfo=no])], |
| 101 | ++ ]])],[ac_cv_func_getaddrinfo=yes], [ac_cv_func_getaddrinfo=no], [ |
| 102 | ++ dnl Cross compilation. |
| 103 | ++ case $host_alias in |
| 104 | ++ *linux*) |
| 105 | ++ ac_cv_func_getaddrinfo=yes |
| 106 | ++ ;; |
| 107 | ++ *) |
| 108 | ++ ac_cv_func_getaddrinfo=no |
| 109 | ++ ;; |
| 110 | ++ esac |
| 111 | ++ ])], |
| 112 | + [ac_cv_func_getaddrinfo=no])]) |
| 113 | + if test "$ac_cv_func_getaddrinfo" = yes; then |
| 114 | + AC_DEFINE(HAVE_GETADDRINFO,1,[Define if you have the getaddrinfo function]) |
| 115 | +@@ -674,7 +692,19 @@ int main(void) { |
| 116 | + end: |
| 117 | + return 0; |
| 118 | + } |
| 119 | +- ]])], [ac_cv__asm_goto=yes], [ac_cv__asm_goto=no], [ac_cv__asm_goto=no])]) |
| 120 | ++ ]])], [ac_cv__asm_goto=yes], [ac_cv__asm_goto=no], [ |
| 121 | ++ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ |
| 122 | ++int main(void) { |
| 123 | ++#if defined(__x86_64__) || defined(__i386__) |
| 124 | ++ __asm__ goto("jmp %l0\n" :::: end); |
| 125 | ++#elif defined(__aarch64__) |
| 126 | ++ __asm__ goto("b %l0\n" :::: end); |
| 127 | ++#endif |
| 128 | ++end: |
| 129 | ++ return 0; |
| 130 | ++} |
| 131 | ++ ]])], [ac_cv__asm_goto=yes], [ac_cv__asm_goto=no]) |
| 132 | ++])]) |
| 133 | + |
| 134 | + if test "$ac_cv__asm_goto" = yes; then |
| 135 | + AC_DEFINE(HAVE_ASM_GOTO,1,[Define if asm goto support]) |
| 136 | +@@ -1334,6 +1364,7 @@ PHP_SUBST(sysconfdir) |
| 137 | + |
| 138 | + PHP_SUBST(EXEEXT) |
| 139 | + PHP_SUBST(CC) |
| 140 | ++PHP_SUBST(BUILD_CC) |
| 141 | + PHP_SUBST(CFLAGS) |
| 142 | + PHP_SUBST(CFLAGS_CLEAN) |
| 143 | + PHP_SUBST(CPP) |
| 144 | +diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4 |
| 145 | +index 19514b9b1c..2002eaa9b6 100644 |
| 146 | +--- a/ext/opcache/config.m4 |
| 147 | ++++ b/ext/opcache/config.m4 |
| 148 | +@@ -43,28 +43,26 @@ if test "$PHP_OPCACHE" != "no"; then |
| 149 | + ZEND_JIT_SRC="jit/zend_jit.c jit/zend_jit_vm_helpers.c" |
| 150 | + |
| 151 | + dnl Find out which ABI we are using. |
| 152 | +- AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
| 153 | +- int main(void) { |
| 154 | +- return sizeof(void*) == 4; |
| 155 | +- } |
| 156 | +- ]])],[ |
| 157 | +- ac_cv_32bit_build=no |
| 158 | +- ],[ |
| 159 | +- ac_cv_32bit_build=yes |
| 160 | +- ],[ |
| 161 | +- ac_cv_32bit_build=no |
| 162 | +- ]) |
| 163 | +- |
| 164 | +- if test "$ac_cv_32bit_build" = "no"; then |
| 165 | +- case $host_alias in |
| 166 | +- *x86_64-*-darwin*) |
| 167 | +- DASM_FLAGS="-D X64APPLE=1 -D X64=1" |
| 168 | ++ case $host_alias in |
| 169 | ++ x86_64-*-darwin*) |
| 170 | ++ DASM_FLAGS="-D X64APPLE=1 -D X64=1" |
| 171 | ++ DASM_ARCH="x86" |
| 172 | + ;; |
| 173 | +- *x86_64*) |
| 174 | +- DASM_FLAGS="-D X64=1" |
| 175 | ++ x86_64*) |
| 176 | ++ DASM_FLAGS="-D X64=1" |
| 177 | ++ DASM_ARCH="x86" |
| 178 | + ;; |
| 179 | +- esac |
| 180 | +- fi |
| 181 | ++ i[34567]86*) |
| 182 | ++ DASM_ARCH="x86" |
| 183 | ++ ;; |
| 184 | ++ x86*) |
| 185 | ++ DASM_ARCH="x86" |
| 186 | ++ ;; |
| 187 | ++ aarch64*) |
| 188 | ++ DASM_FLAGS="-D ARM64=1" |
| 189 | ++ DASM_ARCH="arm64" |
| 190 | ++ ;; |
| 191 | ++ esac |
| 192 | + |
| 193 | + if test "$PHP_THREAD_SAFETY" = "yes"; then |
| 194 | + DASM_FLAGS="$DASM_FLAGS -D ZTS=1" |
| 195 | +@@ -173,9 +171,10 @@ int main() { |
| 196 | + } |
| 197 | + return 0; |
| 198 | + } |
| 199 | +-]])],[dnl |
| 200 | ++]])],[have_shm_ipc=yes],[have_shm_ipc=no],[have_shm_ipc=no]) |
| 201 | ++ if test "$have_shm_ipc" = "yes"; then |
| 202 | + AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support]) |
| 203 | +- have_shm_ipc=yes],[have_shm_ipc=no],[have_shm_ipc=no]) |
| 204 | ++ fi |
| 205 | + AC_MSG_RESULT([$have_shm_ipc]) |
| 206 | + |
| 207 | + AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support) |
| 208 | +@@ -225,9 +224,19 @@ int main() { |
| 209 | + } |
| 210 | + return 0; |
| 211 | + } |
| 212 | +-]])],[dnl |
| 213 | ++]])],[have_shm_mmap_anon=yes],[have_shm_mmap_anon=no],[ |
| 214 | ++ case $host_alias in |
| 215 | ++ *linux*) |
| 216 | ++ have_shm_mmap_anon=yes |
| 217 | ++ ;; |
| 218 | ++ *) |
| 219 | ++ have_shm_mmap_anon=no |
| 220 | ++ ;; |
| 221 | ++ esac |
| 222 | ++]) |
| 223 | ++ if test "$have_shm_mmap_anon" = "yes"; then |
| 224 | + AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support]) |
| 225 | +- have_shm_mmap_anon=yes],[have_shm_mmap_anon=no],[have_shm_mmap_anon=no]) |
| 226 | ++ fi |
| 227 | + AC_MSG_RESULT([$have_shm_mmap_anon]) |
| 228 | + |
| 229 | + PHP_CHECK_FUNC_LIB(shm_open, rt, root) |
| 230 | +@@ -295,16 +304,12 @@ int main() { |
| 231 | + } |
| 232 | + return 0; |
| 233 | + } |
| 234 | +-]])],[dnl |
| 235 | ++]])],[have_shm_mmap_posix=yes],[have_shm_mmap_posix=no],[have_shm_mmap_posix=no]) |
| 236 | ++ if test "$have_shm_mmap_posix" = "yes"; then |
| 237 | + AC_DEFINE(HAVE_SHM_MMAP_POSIX, 1, [Define if you have POSIX mmap() SHM support]) |
| 238 | +- AC_MSG_RESULT([yes]) |
| 239 | +- have_shm_mmap_posix=yes |
| 240 | + PHP_CHECK_LIBRARY(rt, shm_unlink, [PHP_ADD_LIBRARY(rt,1,OPCACHE_SHARED_LIBADD)]) |
| 241 | +- ],[ |
| 242 | +- AC_MSG_RESULT([no]) |
| 243 | +- ],[ |
| 244 | +- AC_MSG_RESULT([no]) |
| 245 | +- ]) |
| 246 | ++ fi |
| 247 | ++ AC_MSG_RESULT([$have_shm_mmap_posix]) |
| 248 | + |
| 249 | + PHP_NEW_EXTENSION(opcache, |
| 250 | + ZendAccelerator.c \ |
| 251 | +diff --git a/ext/opcache/jit/Makefile.frag b/ext/opcache/jit/Makefile.frag |
| 252 | +index eac6bb84c3..d44e06a3ad 100644 |
| 253 | +--- a/ext/opcache/jit/Makefile.frag |
| 254 | ++++ b/ext/opcache/jit/Makefile.frag |
| 255 | +@@ -1,6 +1,6 @@ |
| 256 | + |
| 257 | + $(builddir)/minilua: $(srcdir)/jit/dynasm/minilua.c |
| 258 | +- $(CC) $(srcdir)/jit/dynasm/minilua.c -lm -o $@ |
| 259 | ++ $(BUILD_CC) $(srcdir)/jit/dynasm/minilua.c -lm -o $@ |
| 260 | + |
| 261 | + $(builddir)/jit/zend_jit_x86.c: $(srcdir)/jit/zend_jit_x86.dasc $(srcdir)/jit/dynasm/*.lua $(builddir)/minilua |
| 262 | + $(builddir)/minilua $(srcdir)/jit/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ $(srcdir)/jit/zend_jit_x86.dasc |
| 263 | +diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 |
| 264 | +index d04add9629..4b687b3df5 100644 |
| 265 | +--- a/ext/standard/config.m4 |
| 266 | ++++ b/ext/standard/config.m4 |
| 267 | +@@ -295,7 +295,17 @@ if test "$ac_cv_attribute_aligned" = "yes"; then |
| 268 | + AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [whether the compiler supports __attribute__ ((__aligned__))]) |
| 269 | + fi |
| 270 | + |
| 271 | +-AC_FUNC_FNMATCH |
| 272 | ++if test "$cross_compiling" = yes ; then |
| 273 | ++ case $host_alias in |
| 274 | ++ *linux*) |
| 275 | ++ AC_DEFINE([HAVE_FNMATCH], 1, |
| 276 | ++ [Define to 1 if your system has a working POSIX `fnmatch' |
| 277 | ++ function.]) |
| 278 | ++ ;; |
| 279 | ++ esac |
| 280 | ++else |
| 281 | ++ AC_FUNC_FNMATCH |
| 282 | ++fi |
| 283 | + |
| 284 | + dnl |
| 285 | + dnl Check if there is a support means of creating a new process and defining |
| 286 | +-- |
| 287 | +2.37.1 |
| 288 | + |
0 commit comments