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