Skip to content

Fix linking library for POSIX shared memory functions #13822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,16 @@ int main(void) {
fi
AC_MSG_RESULT([$have_shm_mmap_anon])

PHP_CHECK_FUNC_LIB(shm_open, rt, root)
AC_MSG_CHECKING(for mmap() using shm_open() shared memory support)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
dnl Check POSIX shared memory object operations and link required library as
dnl needed: rt (older Linux and Solaris <= 10). Most systems have it in the C
dnl standard library (newer Linux, illumos, Solaris 11.4, macOS, BSD-based
dnl systems...). Haiku has it in the root library, which is linked by default.
LIBS_save="$LIBS"
LIBS=
AC_SEARCH_LIBS([shm_open], [rt],
[AC_CACHE_CHECK([for mmap() using shm_open() shared memory support],
[php_cv_shm_mmap_posix],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/mman.h>
Expand Down Expand Up @@ -302,13 +309,20 @@ int main(void) {
return 9;
}
return 0;
}
]])],[have_shm_mmap_posix=yes],[have_shm_mmap_posix=no],[have_shm_mmap_posix=no])
AC_MSG_RESULT([$have_shm_mmap_posix])
if test "$have_shm_mmap_posix" = "yes"; then
AC_DEFINE(HAVE_SHM_MMAP_POSIX, 1, [Define if you have POSIX mmap() SHM support])
PHP_CHECK_LIBRARY(rt, shm_unlink, [PHP_ADD_LIBRARY(rt,1,OPCACHE_SHARED_LIBADD)])
fi
}]])],
[php_cv_shm_mmap_posix=yes],
[php_cv_shm_mmap_posix=no],
[php_cv_shm_mmap_posix=no])
])

if test "$php_cv_shm_mmap_posix" = "yes"; then
AS_VAR_IF([ac_cv_search_shm_open], ["none required"],,
[OPCACHE_SHARED_LIBADD="$OPCACHE_SHARED_LIBADD $ac_cv_search_shm_open"])
AC_DEFINE([HAVE_SHM_MMAP_POSIX], [1],
[Define if you have POSIX mmap() SHM support])
fi
])
LIBS="$LIBS_save"

PHP_NEW_EXTENSION(opcache,
ZendAccelerator.c \
Expand All @@ -329,7 +343,7 @@ int main(void) {

PHP_ADD_EXTENSION_DEP(opcache, pcre)

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

Expand Down