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