commit:     e3633b3970dbbde652043324504ce21064668f8f
Author:     Brian Evans <grknight <AT> gentoo <DOT> org>
AuthorDate: Fri May  5 13:11:26 2023 +0000
Commit:     Brian Evans <grknight <AT> gentoo <DOT> org>
CommitDate: Fri May  5 13:18:36 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e3633b39

dev-lang/php: Backport capstone detection added upstream

This is a trimmed down version of mjo's patch to apply to a wider array
of versions.  The oprofile bits omiitted are not important as defines
block their calling and the defines are removed from the configure.

Fixes: https://bugs.gentoo.org/905725
Signed-off-by: Brian Evans <grknight <AT> gentoo.org>

 dev-lang/php/files/php-capstone-optional.patch | 78 ++++++++++++++++++++++++++
 dev-lang/php/php-8.1.18.ebuild                 |  1 +
 dev-lang/php/php-8.2.5.ebuild                  |  1 +
 3 files changed, 80 insertions(+)

diff --git a/dev-lang/php/files/php-capstone-optional.patch 
b/dev-lang/php/files/php-capstone-optional.patch
new file mode 100644
index 000000000000..a4719bbb6857
--- /dev/null
+++ b/dev-lang/php/files/php-capstone-optional.patch
@@ -0,0 +1,78 @@
+diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4
+index 444ded9976ac..fb3324cf82a3 100644
+--- a/ext/opcache/config.m4
++++ b/ext/opcache/config.m4
+@@ -18,6 +18,12 @@ PHP_ARG_ENABLE([opcache-jit],
+   [yes],
+   [no])
+ 
++PHP_ARG_WITH([opcache-capstone],,
++  [AS_HELP_STRING([--with-opcache-capstone],
++    [support opcache JIT disassembly through capstone])],
++  [no],
++  [no])
++
+ if test "$PHP_OPCACHE" != "no"; then
+ 
+   dnl Always build as shared extension
+@@ -68,41 +74,18 @@ if test "$PHP_OPCACHE" != "no"; then
+       DASM_FLAGS="$DASM_FLAGS -D ZTS=1"
+     fi
+ 
+-    PKG_CHECK_MODULES([CAPSTONE], [capstone >= 3.0.0],
+-        [have_capstone="yes"], [have_capstone="no"])
+-    if test "$have_capstone" = "yes"; then
+-        AC_DEFINE(HAVE_CAPSTONE, 1, [ ])
++    AS_IF([test x"$with_opcache_capstone" = "xyes"],[
++      PKG_CHECK_MODULES([CAPSTONE],[capstone >= 3.0.0],[
++        AC_DEFINE([HAVE_CAPSTONE], [1], [Capstone is available])
+         PHP_EVAL_LIBLINE($CAPSTONE_LIBS, OPCACHE_SHARED_LIBADD)
+         PHP_EVAL_INCLINE($CAPSTONE_CFLAGS)
+-    fi
+-
+-    PHP_SUBST(DASM_FLAGS)
+-    PHP_SUBST(DASM_ARCH)
+-
+-    AC_MSG_CHECKING(for opagent in default path)
+-    for i in /usr/local /usr; do
+-      if test -r $i/include/opagent.h; then
+-        OPAGENT_DIR=$i
+-        AC_MSG_RESULT(found in $i)
+-        break
+-      fi
+-    done
+-    if test -z "$OPAGENT_DIR"; then
+-      AC_MSG_RESULT(not found)
+-    else
+-      PHP_CHECK_LIBRARY(opagent, op_write_native_code,
+-      [
+-        AC_DEFINE(HAVE_OPROFILE,1,[ ])
+-        PHP_ADD_INCLUDE($OPAGENT_DIR/include)
+-        PHP_ADD_LIBRARY_WITH_PATH(opagent, $OPAGENT_DIR/$PHP_LIBDIR/oprofile, 
OPCACHE_SHARED_LIBADD)
+-        PHP_SUBST(OPCACHE_SHARED_LIBADD)
+-      ],[
+-        AC_MSG_RESULT(not found)
+       ],[
+-        -L$OPAGENT_DIR/$PHP_LIBDIR/oprofile
++        AC_MSG_ERROR([capstone >= 3.0 required but not found])
+       ])
+-    fi
++    ])
+ 
++    PHP_SUBST(DASM_FLAGS)
++    PHP_SUBST(DASM_ARCH)
+   fi
+ 
+   AC_CHECK_FUNCS([mprotect memfd_create])
+diff --git a/ext/opcache/jit/Makefile.frag b/ext/opcache/jit/Makefile.frag
+index 98c5cdaea249..f9ae2e0cf4b9 100644
+--- a/ext/opcache/jit/Makefile.frag
++++ b/ext/opcache/jit/Makefile.frag
+@@ -11,7 +11,6 @@ $(builddir)/jit/zend_jit.lo: \
+       $(srcdir)/jit/zend_jit_disasm.c \
+       $(srcdir)/jit/zend_jit_gdb.c \
+       $(srcdir)/jit/zend_jit_perf_dump.c \
+-      $(srcdir)/jit/zend_jit_oprofile.c \
+       $(srcdir)/jit/zend_jit_vtune.c \
+       $(srcdir)/jit/zend_jit_trace.c \
+       $(srcdir)/jit/zend_elf.c

diff --git a/dev-lang/php/php-8.1.18.ebuild b/dev-lang/php/php-8.1.18.ebuild
index 20d68c6387fd..7a0c8ba9fcf7 100644
--- a/dev-lang/php/php-8.1.18.ebuild
+++ b/dev-lang/php/php-8.1.18.ebuild
@@ -147,6 +147,7 @@ PHP_MV="$(ver_cut 1)"
 
 PATCHES=(
        "${FILESDIR}/php-iodbc-header-location.patch"
+       "${FILESDIR}/php-capstone-optional.patch"
 )
 
 php_install_ini() {

diff --git a/dev-lang/php/php-8.2.5.ebuild b/dev-lang/php/php-8.2.5.ebuild
index bb2d5ee06588..d8e80841110d 100644
--- a/dev-lang/php/php-8.2.5.ebuild
+++ b/dev-lang/php/php-8.2.5.ebuild
@@ -148,6 +148,7 @@ PHP_MV="$(ver_cut 1)"
 
 PATCHES=(
        "${FILESDIR}/php-iodbc-header-location.patch"
+       "${FILESDIR}/php-capstone-optional.patch"
 )
 
 php_install_ini() {

Reply via email to