Skip to content

Commit dd10dba

Browse files
committed
Fix linking library for POSIX shared memory functions
The POSIX shared memory object operations functions (shm_open, shm_unlink...) are in: * C library on most systems (newer Linux, Solaris 11.4, illumos, BSD*, macOS, Haiku R1, etc.) * real-time (rt) library on older Linux distributions and Solaris <= 10. * root library on Haiku nightly Previous check always added additional rt or root library to global LIBS and rt to OPCACHE_SHARED_LIBADD. Now, the library containing shm_open is linked as needed to the always shared opcache extension. This also removes unused HAVE_SHM_OPEN and HAVE_LIBROOT symbols.
1 parent 413f2cd commit dd10dba

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

ext/opcache/config.m4

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,16 @@ int main(void) {
238238
fi
239239
AC_MSG_RESULT([$have_shm_mmap_anon])
240240

241-
PHP_CHECK_FUNC_LIB(shm_open, rt, root)
242-
AC_MSG_CHECKING(for mmap() using shm_open() shared memory support)
243-
AC_RUN_IFELSE([AC_LANG_SOURCE([[
241+
dnl Check POSIX shared memory object operations and link required library as
242+
dnl needed: rt (older Linux and Solaris <= 10), root (Haiku nightly), other
243+
dnl systems have it in C library (newer Linux, illumos, Solaris 11.4, macOS,
244+
dnl BSD-based systems, Haiku R1...).
245+
LIBS_save="$LIBS"
246+
LIBS=
247+
AC_SEARCH_LIBS([shm_open], [rt root],
248+
[AC_CACHE_CHECK([for mmap() using shm_open() shared memory support],
249+
[php_cv_shm_mmap_posix],
250+
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
244251
#include <sys/types.h>
245252
#include <sys/wait.h>
246253
#include <sys/mman.h>
@@ -302,13 +309,20 @@ int main(void) {
302309
return 9;
303310
}
304311
return 0;
305-
}
306-
]])],[have_shm_mmap_posix=yes],[have_shm_mmap_posix=no],[have_shm_mmap_posix=no])
307-
AC_MSG_RESULT([$have_shm_mmap_posix])
308-
if test "$have_shm_mmap_posix" = "yes"; then
309-
AC_DEFINE(HAVE_SHM_MMAP_POSIX, 1, [Define if you have POSIX mmap() SHM support])
310-
PHP_CHECK_LIBRARY(rt, shm_unlink, [PHP_ADD_LIBRARY(rt,1,OPCACHE_SHARED_LIBADD)])
311-
fi
312+
}]])],
313+
[php_cv_shm_mmap_posix=yes],
314+
[php_cv_shm_mmap_posix=no],
315+
[php_cv_shm_mmap_posix=no])
316+
])
317+
318+
if test "$php_cv_shm_mmap_posix" = "yes"; then
319+
AS_VAR_IF([ac_cv_search_shm_open], ["none required"],,
320+
[OPCACHE_SHARED_LIBADD="$OPCACHE_SHARED_LIBADD $ac_cv_search_shm_open"])
321+
AC_DEFINE([HAVE_SHM_MMAP_POSIX], [1],
322+
[Define if you have POSIX mmap() SHM support])
323+
fi
324+
])
325+
LIBS="$LIBS_save"
312326

313327
PHP_NEW_EXTENSION(opcache,
314328
ZendAccelerator.c \
@@ -329,7 +343,7 @@ int main(void) {
329343

330344
PHP_ADD_EXTENSION_DEP(opcache, pcre)
331345

332-
if test "$have_shm_ipc" != "yes" && test "$have_shm_mmap_posix" != "yes" && test "$have_shm_mmap_anon" != "yes"; then
346+
if test "$have_shm_ipc" != "yes" && test "$php_cv_shm_mmap_posix" != "yes" && test "$have_shm_mmap_anon" != "yes"; then
333347
AC_MSG_ERROR([No supported shared memory caching support was found when configuring opcache. Check config.log for any errors or missing dependencies.])
334348
fi
335349

0 commit comments

Comments
 (0)