1PHP_ARG_ENABLE([opcache], 2 [whether to enable Zend OPcache support], 3 [AS_HELP_STRING([--disable-opcache], 4 [Disable Zend OPcache support])], 5 [yes]) 6 7PHP_ARG_ENABLE([huge-code-pages], 8 [whether to enable copying PHP CODE pages into HUGE PAGES], 9 [AS_HELP_STRING([--disable-huge-code-pages], 10 [Disable copying PHP CODE pages into HUGE PAGES])], 11 [yes], 12 [no]) 13 14PHP_ARG_ENABLE([opcache-jit], 15 [whether to enable JIT], 16 [AS_HELP_STRING([--disable-opcache-jit], 17 [Disable JIT])], 18 [yes], 19 [no]) 20 21PHP_ARG_WITH([capstone],, 22 [AS_HELP_STRING([--with-capstone], 23 [support opcache JIT disassembly through capstone])], 24 [no], 25 [no]) 26 27if test "$PHP_OPCACHE" != "no"; then 28 29 dnl Always build as shared extension 30 ext_shared=yes 31 32 if test "$PHP_HUGE_CODE_PAGES" = "yes"; then 33 AC_DEFINE(HAVE_HUGE_CODE_PAGES, 1, [Define to enable copying PHP CODE pages into HUGE PAGES (experimental)]) 34 fi 35 36 if test "$PHP_OPCACHE_JIT" = "yes"; then 37 case $host_cpu in 38 i[[34567]]86*|x86*|aarch64|amd64) 39 ;; 40 *) 41 AC_MSG_WARN([JIT not supported by host architecture]) 42 PHP_OPCACHE_JIT=no 43 ;; 44 esac 45 if test "$host_vendor" = "apple" && test "$host_cpu" = "aarch64" && test "$PHP_THREAD_SAFETY" = "yes"; then 46 AC_MSG_WARN([JIT not supported on Apple Silicon with ZTS]) 47 PHP_OPCACHE_JIT=no 48 fi 49 fi 50 51 if test "$PHP_OPCACHE_JIT" = "yes"; then 52 AC_DEFINE(HAVE_JIT, 1, [Define to enable JIT]) 53 ZEND_JIT_SRC="jit/zend_jit.c jit/zend_jit_gdb.c jit/zend_jit_vm_helpers.c" 54 55 dnl Find out which ABI we are using. 56 case $host_alias in 57 x86_64-*-darwin*) 58 DASM_FLAGS="-D X64APPLE=1 -D X64=1" 59 DASM_ARCH="x86" 60 ;; 61 *x86_64*|amd64-*-freebsd*) 62 IR_TARGET=IR_TARGET_X64 63 DASM_FLAGS="-D X64=1" 64 DASM_ARCH="x86" 65 ;; 66 i[[34567]]86*) 67 DASM_ARCH="x86" 68 ;; 69 x86*) 70 DASM_ARCH="x86" 71 ;; 72 aarch64*) 73 DASM_FLAGS="-D ARM64=1" 74 DASM_ARCH="arm64" 75 ;; 76 esac 77 78 if test "$PHP_THREAD_SAFETY" = "yes"; then 79 DASM_FLAGS="$DASM_FLAGS -D ZTS=1" 80 fi 81 82 AS_IF([test x"$with_capstone" = "xyes"],[ 83 PKG_CHECK_MODULES([CAPSTONE],[capstone >= 3.0.0],[ 84 AC_DEFINE([HAVE_CAPSTONE], [1], [Capstone is available]) 85 PHP_EVAL_LIBLINE($CAPSTONE_LIBS, OPCACHE_SHARED_LIBADD) 86 PHP_EVAL_INCLINE($CAPSTONE_CFLAGS) 87 ],[ 88 AC_MSG_ERROR([capstone >= 3.0 required but not found]) 89 ]) 90 ]) 91 92 PHP_SUBST(DASM_FLAGS) 93 PHP_SUBST(DASM_ARCH) 94 fi 95 96 AC_CHECK_FUNCS([mprotect memfd_create]) 97 98 AC_MSG_CHECKING(for sysvipc shared memory support) 99 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 100#include <sys/types.h> 101#include <sys/wait.h> 102#include <sys/ipc.h> 103#include <sys/shm.h> 104#include <unistd.h> 105#include <string.h> 106 107int main(void) { 108 pid_t pid; 109 int status; 110 int ipc_id; 111 char *shm; 112 struct shmid_ds shmbuf; 113 114 ipc_id = shmget(IPC_PRIVATE, 4096, (IPC_CREAT | SHM_R | SHM_W)); 115 if (ipc_id == -1) { 116 return 1; 117 } 118 119 shm = shmat(ipc_id, NULL, 0); 120 if (shm == (void *)-1) { 121 shmctl(ipc_id, IPC_RMID, NULL); 122 return 2; 123 } 124 125 if (shmctl(ipc_id, IPC_STAT, &shmbuf) != 0) { 126 shmdt(shm); 127 shmctl(ipc_id, IPC_RMID, NULL); 128 return 3; 129 } 130 131 shmbuf.shm_perm.uid = getuid(); 132 shmbuf.shm_perm.gid = getgid(); 133 shmbuf.shm_perm.mode = 0600; 134 135 if (shmctl(ipc_id, IPC_SET, &shmbuf) != 0) { 136 shmdt(shm); 137 shmctl(ipc_id, IPC_RMID, NULL); 138 return 4; 139 } 140 141 shmctl(ipc_id, IPC_RMID, NULL); 142 143 strcpy(shm, "hello"); 144 145 pid = fork(); 146 if (pid < 0) { 147 return 5; 148 } else if (pid == 0) { 149 strcpy(shm, "bye"); 150 return 6; 151 } 152 if (wait(&status) != pid) { 153 return 7; 154 } 155 if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) { 156 return 8; 157 } 158 if (strcmp(shm, "bye") != 0) { 159 return 9; 160 } 161 return 0; 162} 163]])],[have_shm_ipc=yes],[have_shm_ipc=no],[have_shm_ipc=no]) 164 if test "$have_shm_ipc" = "yes"; then 165 AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support]) 166 fi 167 AC_MSG_RESULT([$have_shm_ipc]) 168 169 AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support) 170 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 171#include <sys/types.h> 172#include <sys/wait.h> 173#include <sys/mman.h> 174#include <unistd.h> 175#include <string.h> 176 177#ifndef MAP_ANON 178# ifdef MAP_ANONYMOUS 179# define MAP_ANON MAP_ANONYMOUS 180# endif 181#endif 182#ifndef MAP_FAILED 183# define MAP_FAILED ((void*)-1) 184#endif 185 186int main(void) { 187 pid_t pid; 188 int status; 189 char *shm; 190 191 shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 192 if (shm == MAP_FAILED) { 193 return 1; 194 } 195 196 strcpy(shm, "hello"); 197 198 pid = fork(); 199 if (pid < 0) { 200 return 5; 201 } else if (pid == 0) { 202 strcpy(shm, "bye"); 203 return 6; 204 } 205 if (wait(&status) != pid) { 206 return 7; 207 } 208 if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) { 209 return 8; 210 } 211 if (strcmp(shm, "bye") != 0) { 212 return 9; 213 } 214 return 0; 215} 216]])],[have_shm_mmap_anon=yes],[have_shm_mmap_anon=no],[ 217 case $host_alias in 218 *linux*) 219 have_shm_mmap_anon=yes 220 ;; 221 *) 222 have_shm_mmap_anon=no 223 ;; 224 esac 225]) 226 if test "$have_shm_mmap_anon" = "yes"; then 227 AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support]) 228 fi 229 AC_MSG_RESULT([$have_shm_mmap_anon]) 230 231 PHP_CHECK_FUNC_LIB(shm_open, rt, root) 232 AC_MSG_CHECKING(for mmap() using shm_open() shared memory support) 233 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 234#include <sys/types.h> 235#include <sys/wait.h> 236#include <sys/mman.h> 237#include <sys/stat.h> 238#include <fcntl.h> 239#include <unistd.h> 240#include <string.h> 241#include <stdlib.h> 242#include <stdio.h> 243 244#ifndef MAP_FAILED 245# define MAP_FAILED ((void*)-1) 246#endif 247 248int main(void) { 249 pid_t pid; 250 int status; 251 int fd; 252 char *shm; 253 char tmpname[4096]; 254 255 sprintf(tmpname,"/opcache.test.shm.%dXXXXXX", getpid()); 256 if (mktemp(tmpname) == NULL) { 257 return 1; 258 } 259 fd = shm_open(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 260 if (fd == -1) { 261 return 2; 262 } 263 if (ftruncate(fd, 4096) < 0) { 264 close(fd); 265 shm_unlink(tmpname); 266 return 3; 267 } 268 269 shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 270 if (shm == MAP_FAILED) { 271 return 4; 272 } 273 shm_unlink(tmpname); 274 close(fd); 275 276 strcpy(shm, "hello"); 277 278 pid = fork(); 279 if (pid < 0) { 280 return 5; 281 } else if (pid == 0) { 282 strcpy(shm, "bye"); 283 return 6; 284 } 285 if (wait(&status) != pid) { 286 return 7; 287 } 288 if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) { 289 return 8; 290 } 291 if (strcmp(shm, "bye") != 0) { 292 return 9; 293 } 294 return 0; 295} 296]])],[have_shm_mmap_posix=yes],[have_shm_mmap_posix=no],[have_shm_mmap_posix=no]) 297 if test "$have_shm_mmap_posix" = "yes"; then 298 AC_DEFINE(HAVE_SHM_MMAP_POSIX, 1, [Define if you have POSIX mmap() SHM support]) 299 PHP_CHECK_LIBRARY(rt, shm_unlink, [PHP_ADD_LIBRARY(rt,1,OPCACHE_SHARED_LIBADD)]) 300 fi 301 AC_MSG_RESULT([$have_shm_mmap_posix]) 302 303 AX_CHECK_COMPILE_FLAG([-Wno-implicit-fallthrough], 304 [PHP_OPCACHE_CFLAGS="$PHP_OPCACHE_CFLAGS -Wno-implicit-fallthrough"],, 305 [-Werror]) 306 307 PHP_NEW_EXTENSION(opcache, 308 ZendAccelerator.c \ 309 zend_accelerator_blacklist.c \ 310 zend_accelerator_debug.c \ 311 zend_accelerator_hash.c \ 312 zend_accelerator_module.c \ 313 zend_persist.c \ 314 zend_persist_calc.c \ 315 zend_file_cache.c \ 316 zend_shared_alloc.c \ 317 zend_accelerator_util_funcs.c \ 318 shared_alloc_shm.c \ 319 shared_alloc_mmap.c \ 320 shared_alloc_posix.c \ 321 $ZEND_JIT_SRC, 322 shared,,"$PHP_OPCACHE_CFLAGS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1",,yes) 323 324 PHP_ADD_EXTENSION_DEP(opcache, pcre) 325 326 if test "$have_shm_ipc" != "yes" && test "$have_shm_mmap_posix" != "yes" && test "$have_shm_mmap_anon" != "yes"; then 327 AC_MSG_ERROR([No supported shared memory caching support was found when configuring opcache. Check config.log for any errors or missing dependencies.]) 328 fi 329 330 if test "$PHP_OPCACHE_JIT" = "yes"; then 331 PHP_ADD_BUILD_DIR([$ext_builddir/jit], 1) 332 PHP_ADD_MAKEFILE_FRAGMENT($ext_srcdir/jit/Makefile.frag) 333 fi 334 PHP_SUBST(OPCACHE_SHARED_LIBADD) 335fi 336