Skip to contentSkip to conversation

package/pcre2: add JIT support option

PATCH New Artem Panfilov 2 participants 4 messages Feb 15, 2019 – Apr 13, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 package/pcre2: add JIT support option

Add JIT support option.

---
 package/pcre2/Config.in | 8 ++++++++
 package/pcre2/pcre2.mk  | 6 ++++++
 2 files changed, 14 insertions(+)
package/pcre2/Config.in +8 -0
index bb576c75a1..007dd960c6 100644
@@ -23,4 +23,12 @@ config BR2_PACKAGE_PCRE2_32
 	  This option builds the 32-bits pcre2 library, i.e
 	  'libpcre2-32'
 
+config BR2_PACKAGE_PCRE2_JIT
+	bool "enable JIT support"
+	depends on BR2_i386 || BR2_x86_64 || BR2_arm  || BR2_armeb || \
+		BR2_aarch64 || BR2_mips || BR2_mipsel || \
+		BR2_mips64 || BR2_mips64el || BR2_powerpc || BR2_sparc
+	help
+	  This option enables JIT support
+
 endif
package/pcre2/pcre2.mk +6 -0
index ee3cacb9aa..6d103c2b9b 100644
@@ -16,6 +16,12 @@ PCRE2_CONF_OPTS += --enable-pcre2-8
 PCRE2_CONF_OPTS += $(if $(BR2_PACKAGE_PCRE2_16),--enable-pcre2-16,--disable-pcre2-16)
 PCRE2_CONF_OPTS += $(if $(BR2_PACKAGE_PCRE2_32),--enable-pcre2-32,--disable-pcre2-32)
 
+ifeq ($(BR2_PACKAGE_PCRE2_JIT),y)
+PCRE2_CONF_OPTS += --enable-jit
+else
+PCRE2_CONF_OPTS += --disable-jit
+endif
+
 # disable fork usage if not available
 ifeq ($(BR2_USE_MMU),)
 PCRE2_CONF_OPTS += --disable-pcre2grep-callout
Signature · 1 line
2.19.1
#1 lore raw

PATCH 2/2 package/php: fix how external PCRE2 JIT is enabled

When the external PCRE2 library is used, PHP JIT option is enabled based on architecture. If the external library was compiled without JIT support runtime will fail.

When I call "php -m" command, I have the following error message:
PHP Fatal error: Unable to start pcre module in Unknown on line 0

---
 ...0006-pcre2-tweak-pcre2-jit-detection.patch | 41 +++++++++++++++++++
 package/php/php.mk                            |  7 ++++
 2 files changed, 48 insertions(+)
 create mode 100644 package/php/0006-pcre2-tweak-pcre2-jit-detection.patch
package/php/0006-pcre2-tweak-pcre2-jit-detection.patch new file +41 -0
new file mode 100644
index 0000000000..492abf008b
@@ -0,0 +1,41 @@
+diff --git a/ext/pcre/config0.m4 b/ext/pcre/config0.m4
+index b9542f0113..f4c66a8369 100644
+--- a/ext/pcre/config0.m4
++++ b/ext/pcre/config0.m4
+@@ -53,35 +53,7 @@ PHP_ARG_WITH(pcre-jit,,[  --with-pcre-jit         Enable PCRE JIT functionality
+     AC_DEFINE(HAVE_PCRE, 1, [ ])
+ 
+     if test "$PHP_PCRE_JIT" != "no"; then
+-      AC_MSG_CHECKING([for JIT support in PCRE2])
+-      AC_RUN_IFELSE([
+-        AC_LANG_SOURCE([[
+-            #include <pcre2.h>
+-            #include <stdlib.h>
+-            int main(void) {
+-              uint32_t have_jit;
+-              pcre2_config_8(PCRE2_CONFIG_JIT, &have_jit);
+-              return !have_jit;
+-            }
+-        ]])], [
+-        AC_MSG_RESULT([yes])
+-        AC_DEFINE(HAVE_PCRE_JIT_SUPPORT, 1, [])
+-      ],
+-      [
+-        AC_MSG_RESULT([no])
+-      ],
+-      [
+-        AC_CANONICAL_HOST
+-        case $host_cpu in
+-        arm*|i[34567]86|x86_64|mips*|powerpc*|sparc)
+-          AC_MSG_RESULT([yes])
+-          AC_DEFINE(HAVE_PCRE_JIT_SUPPORT, 1, [])
+-          ;;
+-        *)
+-          AC_MSG_RESULT([no])
+-          ;;
+-        esac
+-      ])
++      AC_DEFINE(HAVE_PCRE_JIT_SUPPORT, 1, [])
+     fi
+ 
+     PHP_NEW_EXTENSION(pcre, php_pcre.c, no,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
package/php/php.mk +7 -0
index 061b2f2609..eb6907972b 100644
@@ -246,6 +246,13 @@ PHP_POST_CONFIGURE_HOOKS += PHP_DISABLE_VALGRIND
 ifeq ($(BR2_PACKAGE_PCRE2),y)
 PHP_CONF_OPTS += --with-pcre-regex=$(STAGING_DIR)/usr
 PHP_DEPENDENCIES += pcre2
+
+ifeq ($(BR2_PACKAGE_PCRE2_JIT),y)
+PHP_CONF_OPTS += --with-pcre-jit
+else
+PHP_CONF_OPTS += --without-pcre-jit
+endif
+
 else
 # The bundled pcre library is not configurable through ./configure options,
 # and by default is configured to be thread-safe, so it wants pthreads. So
Signature · 1 line
2.19.1
#2 lore raw

PATCH 2/2 package/php: fix how external PCRE2 JIT is enabled

Hello Artem,

Quoted 8 lines · On Sat, 16 Feb 2019 02:20:59 +0300 Artem Panfilov <[email protected]>…

When the external PCRE2 library is used, PHP JIT option is enabled based on architecture. If the external library was compiled without JIT support runtime will fail.

When I call "php -m" command, I have the following error message:
PHP Fatal error: Unable to start pcre module in Unknown on line 0

Thanks for this patch. See some comments below.

package/php/0006-pcre2-tweak-pcre2-jit-detection.patch line 1

Quoted 7 lines
package/php/0006-pcre2-tweak-pcre2-jit-detection.patch new file +1 -0
new file mode 100644
index 0000000000..492abf008b
@@ -0,0 +1,41 @@
+diff --git a/ext/pcre/config0.m4 b/ext/pcre/config0.m4

We need all patches to have a Signed-off-by and a description. Also, since PHP is maintained under Git upstream I believe, the patch should be generated by Git format-patch.

Quoted 28 lines
package/php/0006-pcre2-tweak-pcre2-jit-detection.patch new file +4 -0
+index b9542f0113..f4c66a8369 100644
+--- a/ext/pcre/config0.m4
++++ b/ext/pcre/config0.m4
+@@ -53,35 +53,7 @@ PHP_ARG_WITH(pcre-jit,,[  --with-pcre-jit

Enable PCRE JIT functionality

package/php/0006-pcre2-tweak-pcre2-jit-detection.patch new file +23 -0
+     AC_DEFINE(HAVE_PCRE, 1, [ ])
+ 
+     if test "$PHP_PCRE_JIT" != "no"; then
+-      AC_MSG_CHECKING([for JIT support in PCRE2])
+-      AC_RUN_IFELSE([
+-        AC_LANG_SOURCE([[
+-            #include <pcre2.h>
+-            #include <stdlib.h>
+-            int main(void) {
+-              uint32_t have_jit;
+-              pcre2_config_8(PCRE2_CONFIG_JIT, &have_jit);
+-              return !have_jit;
+-            }
+-        ]])], [
+-        AC_MSG_RESULT([yes])
+-        AC_DEFINE(HAVE_PCRE_JIT_SUPPORT, 1, [])
+-      ],
+-      [
+-        AC_MSG_RESULT([no])
+-      ],
+-      [
+-        AC_CANONICAL_HOST
+-        case $host_cpu in

package/php/0006-pcre2-tweak-pcre2-jit-detection.patch line 38

Quoted 10 lines
package/php/0006-pcre2-tweak-pcre2-jit-detection.patch new file +10 -0
+-        arm*|i[34567]86|x86_64|mips*|powerpc*|sparc)
+-          AC_MSG_RESULT([yes])
+-          AC_DEFINE(HAVE_PCRE_JIT_SUPPORT, 1, [])
+-          ;;
+-        *)
+-          AC_MSG_RESULT([no])
+-          ;;
+-        esac
+-      ])
++      AC_DEFINE(HAVE_PCRE_JIT_SUPPORT, 1, [])

This change is not really great, as it cannot be contributed upstream. Better approaches would be

* Add an autoconf cache variable
(https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Caching-Results.html)
that allows to preseed the fact that the pcre2 library is built with JIT support, and therefore avoid the AC_TRY_RUN check. This is fully backward compatible.

* Change the semantic of the option. If --with-pcre-jit is passed, assume it is available. Only if it is *not* passed do the AC_TRY_RUN check. However, this is changing a bit the semantic of the option.

So perhaps the cache variable is the least annoying solution. Could you have a look at implementing this ?

Thanks a lot!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

PATCH 1/2 package/pcre2: add JIT support option

In reply to Artem Panfilov
Quoted 7 lines · On Sat, 16 Feb 2019 02:20:58 +0300 Artem Panfilov <[email protected]>…

Add JIT support option.

---
 package/pcre2/Config.in | 8 ++++++++
 package/pcre2/pcre2.mk  | 6 ++++++
 2 files changed, 14 insertions(+)

Applied to master, thanks.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com