xref: /PHP-7.3/ext/opcache/config.m4 (revision 92227026)
1dnl config.m4 for extension opcache
2
3PHP_ARG_ENABLE(opcache, whether to enable Zend OPcache support,
4[  --disable-opcache       Disable Zend OPcache support], yes)
5
6PHP_ARG_ENABLE(opcache-file, whether to enable file based caching,
7[  --disable-opcache-file  Disable file based caching], yes, no)
8
9PHP_ARG_ENABLE(huge-code-pages, whether to enable copying PHP CODE pages into HUGE PAGES,
10[  --disable-huge-code-pages
11                          Disable copying PHP CODE pages into HUGE PAGES], yes, no)
12
13if test "$PHP_OPCACHE" != "no"; then
14
15  if test "$PHP_OPCACHE_FILE" = "yes"; then
16    AC_DEFINE(HAVE_OPCACHE_FILE_CACHE, 1, [Define to enable file based caching (experimental)])
17  fi
18
19  if test "$PHP_HUGE_CODE_PAGES" = "yes"; then
20    AC_DEFINE(HAVE_HUGE_CODE_PAGES, 1, [Define to enable copying PHP CODE pages into HUGE PAGES (experimental)])
21  fi
22
23  AC_CHECK_FUNC(mprotect,[
24    AC_DEFINE(HAVE_MPROTECT, 1, [Define if you have mprotect() function])
25  ])
26
27  AC_CHECK_HEADERS([unistd.h sys/uio.h])
28
29  AC_MSG_CHECKING(for sysvipc shared memory support)
30  AC_RUN_IFELSE([AC_LANG_SOURCE([[
31#include <sys/types.h>
32#include <sys/wait.h>
33#include <sys/ipc.h>
34#include <sys/shm.h>
35#include <unistd.h>
36#include <string.h>
37
38int main() {
39  pid_t pid;
40  int status;
41  int ipc_id;
42  char *shm;
43  struct shmid_ds shmbuf;
44
45  ipc_id = shmget(IPC_PRIVATE, 4096, (IPC_CREAT | SHM_R | SHM_W));
46  if (ipc_id == -1) {
47    return 1;
48  }
49
50  shm = shmat(ipc_id, NULL, 0);
51  if (shm == (void *)-1) {
52    shmctl(ipc_id, IPC_RMID, NULL);
53    return 2;
54  }
55
56  if (shmctl(ipc_id, IPC_STAT, &shmbuf) != 0) {
57    shmdt(shm);
58    shmctl(ipc_id, IPC_RMID, NULL);
59    return 3;
60  }
61
62  shmbuf.shm_perm.uid = getuid();
63  shmbuf.shm_perm.gid = getgid();
64  shmbuf.shm_perm.mode = 0600;
65
66  if (shmctl(ipc_id, IPC_SET, &shmbuf) != 0) {
67    shmdt(shm);
68    shmctl(ipc_id, IPC_RMID, NULL);
69    return 4;
70  }
71
72  shmctl(ipc_id, IPC_RMID, NULL);
73
74  strcpy(shm, "hello");
75
76  pid = fork();
77  if (pid < 0) {
78    return 5;
79  } else if (pid == 0) {
80    strcpy(shm, "bye");
81    return 6;
82  }
83  if (wait(&status) != pid) {
84    return 7;
85  }
86  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
87    return 8;
88  }
89  if (strcmp(shm, "bye") != 0) {
90    return 9;
91  }
92  return 0;
93}
94]])],[dnl
95    AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support])
96    msg=yes],[msg=no],[msg=no])
97  AC_MSG_RESULT([$msg])
98
99  AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support)
100  AC_RUN_IFELSE([AC_LANG_SOURCE([[
101#include <sys/types.h>
102#include <sys/wait.h>
103#include <sys/mman.h>
104#include <unistd.h>
105#include <string.h>
106
107#ifndef MAP_ANON
108# ifdef MAP_ANONYMOUS
109#  define MAP_ANON MAP_ANONYMOUS
110# endif
111#endif
112#ifndef MAP_FAILED
113# define MAP_FAILED ((void*)-1)
114#endif
115
116int main() {
117  pid_t pid;
118  int status;
119  char *shm;
120
121  shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
122  if (shm == MAP_FAILED) {
123    return 1;
124  }
125
126  strcpy(shm, "hello");
127
128  pid = fork();
129  if (pid < 0) {
130    return 5;
131  } else if (pid == 0) {
132    strcpy(shm, "bye");
133    return 6;
134  }
135  if (wait(&status) != pid) {
136    return 7;
137  }
138  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
139    return 8;
140  }
141  if (strcmp(shm, "bye") != 0) {
142    return 9;
143  }
144  return 0;
145}
146]])],[dnl
147    AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support])
148    msg=yes],[msg=no],[msg=no])
149  AC_MSG_RESULT([$msg])
150
151  AC_MSG_CHECKING(for mmap() using /dev/zero shared memory support)
152  AC_RUN_IFELSE([AC_LANG_SOURCE([[
153#include <sys/types.h>
154#include <sys/wait.h>
155#include <sys/mman.h>
156#include <sys/stat.h>
157#include <fcntl.h>
158#include <unistd.h>
159#include <string.h>
160
161#ifndef MAP_FAILED
162# define MAP_FAILED ((void*)-1)
163#endif
164
165int main() {
166  pid_t pid;
167  int status;
168  int fd;
169  char *shm;
170
171  fd = open("/dev/zero", O_RDWR, S_IRUSR | S_IWUSR);
172  if (fd == -1) {
173    return 1;
174  }
175
176  shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
177  if (shm == MAP_FAILED) {
178    return 2;
179  }
180
181  strcpy(shm, "hello");
182
183  pid = fork();
184  if (pid < 0) {
185    return 5;
186  } else if (pid == 0) {
187    strcpy(shm, "bye");
188    return 6;
189  }
190  if (wait(&status) != pid) {
191    return 7;
192  }
193  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
194    return 8;
195  }
196  if (strcmp(shm, "bye") != 0) {
197    return 9;
198  }
199  return 0;
200}
201]])],[dnl
202    AC_DEFINE(HAVE_SHM_MMAP_ZERO, 1, [Define if you have mmap("/dev/zero") SHM support])
203    msg=yes],[msg=no],[msg=no])
204  AC_MSG_RESULT([$msg])
205
206  AC_MSG_CHECKING(for mmap() using shm_open() shared memory support)
207  AC_RUN_IFELSE([AC_LANG_SOURCE([[
208#include <sys/types.h>
209#include <sys/wait.h>
210#include <sys/mman.h>
211#include <sys/stat.h>
212#include <fcntl.h>
213#include <unistd.h>
214#include <string.h>
215#include <stdlib.h>
216#include <stdio.h>
217
218#ifndef MAP_FAILED
219# define MAP_FAILED ((void*)-1)
220#endif
221
222int main() {
223  pid_t pid;
224  int status;
225  int fd;
226  char *shm;
227  char tmpname[4096];
228
229  sprintf(tmpname,"test.shm.%dXXXXXX", getpid());
230  if (mktemp(tmpname) == NULL) {
231    return 1;
232  }
233  fd = shm_open(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
234  if (fd == -1) {
235    return 2;
236  }
237  if (ftruncate(fd, 4096) < 0) {
238    close(fd);
239    shm_unlink(tmpname);
240    return 3;
241  }
242
243  shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
244  if (shm == MAP_FAILED) {
245    return 4;
246  }
247  shm_unlink(tmpname);
248  close(fd);
249
250  strcpy(shm, "hello");
251
252  pid = fork();
253  if (pid < 0) {
254    return 5;
255  } else if (pid == 0) {
256    strcpy(shm, "bye");
257    return 6;
258  }
259  if (wait(&status) != pid) {
260    return 7;
261  }
262  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
263    return 8;
264  }
265  if (strcmp(shm, "bye") != 0) {
266    return 9;
267  }
268  return 0;
269}
270]])],[dnl
271    AC_DEFINE(HAVE_SHM_MMAP_POSIX, 1, [Define if you have POSIX mmap() SHM support])
272    msg=yes],[msg=no],[msg=no])
273  AC_MSG_RESULT([$msg])
274
275  AC_MSG_CHECKING(for mmap() using regular file shared memory support)
276  AC_RUN_IFELSE([AC_LANG_SOURCE([[
277#include <sys/types.h>
278#include <sys/wait.h>
279#include <sys/mman.h>
280#include <sys/stat.h>
281#include <fcntl.h>
282#include <unistd.h>
283#include <string.h>
284#include <stdlib.h>
285#include <stdio.h>
286
287#ifndef MAP_FAILED
288# define MAP_FAILED ((void*)-1)
289#endif
290
291int main() {
292  pid_t pid;
293  int status;
294  int fd;
295  char *shm;
296  char tmpname[4096];
297
298  sprintf(tmpname,"test.shm.%dXXXXXX", getpid());
299  if (mktemp(tmpname) == NULL) {
300    return 1;
301  }
302  fd = open(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
303  if (fd == -1) {
304    return 2;
305  }
306  if (ftruncate(fd, 4096) < 0) {
307    close(fd);
308    unlink(tmpname);
309    return 3;
310  }
311
312  shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
313  if (shm == MAP_FAILED) {
314    return 4;
315  }
316  unlink(tmpname);
317  close(fd);
318
319  strcpy(shm, "hello");
320
321  pid = fork();
322  if (pid < 0) {
323    return 5;
324  } else if (pid == 0) {
325    strcpy(shm, "bye");
326    return 6;
327  }
328  if (wait(&status) != pid) {
329    return 7;
330  }
331  if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
332    return 8;
333  }
334  if (strcmp(shm, "bye") != 0) {
335    return 9;
336  }
337  return 0;
338}
339]])],[dnl
340    AC_DEFINE(HAVE_SHM_MMAP_FILE, 1, [Define if you have mmap() SHM support])
341    msg=yes],[msg=no],[msg=no])
342  AC_MSG_RESULT([$msg])
343
344  PHP_NEW_EXTENSION(opcache,
345	ZendAccelerator.c \
346	zend_accelerator_blacklist.c \
347	zend_accelerator_debug.c \
348	zend_accelerator_hash.c \
349	zend_accelerator_module.c \
350	zend_persist.c \
351	zend_persist_calc.c \
352	zend_file_cache.c \
353	zend_shared_alloc.c \
354	zend_accelerator_util_funcs.c \
355	shared_alloc_shm.c \
356	shared_alloc_mmap.c \
357	shared_alloc_posix.c \
358	Optimizer/zend_optimizer.c \
359	Optimizer/pass1_5.c \
360	Optimizer/pass2.c \
361	Optimizer/pass3.c \
362	Optimizer/optimize_func_calls.c \
363	Optimizer/block_pass.c \
364	Optimizer/optimize_temp_vars_5.c \
365	Optimizer/nop_removal.c \
366	Optimizer/compact_literals.c \
367	Optimizer/zend_cfg.c \
368	Optimizer/zend_dfg.c \
369	Optimizer/dfa_pass.c \
370	Optimizer/zend_ssa.c \
371	Optimizer/zend_inference.c \
372	Optimizer/zend_func_info.c \
373	Optimizer/zend_call_graph.c \
374	Optimizer/sccp.c \
375	Optimizer/scdf.c \
376	Optimizer/dce.c \
377	Optimizer/escape_analysis.c \
378	Optimizer/compact_vars.c \
379	Optimizer/zend_dump.c,
380	shared,,-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1,,yes)
381
382  PHP_ADD_BUILD_DIR([$ext_builddir/Optimizer], 1)
383  PHP_ADD_EXTENSION_DEP(opcache, pcre)
384fi
385