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