Skip to content

Commit 8792241

Browse files
authored
Use capstone explicitly, drop oprofile (GH 10876) (#10918)
* ext/opcache/config.m4: new --with-opcache-capstone flag. Until now, libcapstone has been detected "automagically" and used for JIT disassembly whenever it is available on the system used to compile PHP. This can have some unintended consequences, however: many users have capstone installed for some other purpose, and are surprised to find that PHP breaks when capstone is later uninstalled. To address this, we have introduced a new --with-opcache-capstone flag that is disabled by default, and that makes the user's preference explicit. It is ignored unless the JIT is enabled. * ext/opcache: drop support for the oprofile JIT profiler. Recently we have replaced the "automagic" detection of capstone at build time with a --with-opcache-capstone flag. The detection of oprofile causes similar problems and would likely have the same solution; however, it was suggested that we might remove oprofile altogether. So, this commit removes it: * Remove the detection bits from ext/opcache/config.m4. * Drop HAVE_OPROFILE ifdef blocks. * Delete ext/opcache/jit/zend_jit_oprofile.c. * Undefine the ZEND_JIT_DEBUG_OPROFILE constant.
1 parent e49777f commit 8792241

File tree

6 files changed

+17
-112
lines changed

6 files changed

+17
-112
lines changed

ext/opcache/config.m4

+13-30
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ PHP_ARG_ENABLE([opcache-jit],
1818
[yes],
1919
[no])
2020

21+
PHP_ARG_WITH([opcache-capstone],,
22+
[AS_HELP_STRING([--with-opcache-capstone],
23+
[support opcache JIT disassembly through capstone])],
24+
[no],
25+
[no])
26+
2127
if test "$PHP_OPCACHE" != "no"; then
2228

2329
dnl Always build as shared extension
@@ -68,41 +74,18 @@ if test "$PHP_OPCACHE" != "no"; then
6874
DASM_FLAGS="$DASM_FLAGS -D ZTS=1"
6975
fi
7076

71-
PKG_CHECK_MODULES([CAPSTONE], [capstone >= 3.0.0],
72-
[have_capstone="yes"], [have_capstone="no"])
73-
if test "$have_capstone" = "yes"; then
74-
AC_DEFINE(HAVE_CAPSTONE, 1, [ ])
77+
AS_IF([test x"$with_opcache_capstone" = "xyes"],[
78+
PKG_CHECK_MODULES([CAPSTONE],[capstone >= 3.0.0],[
79+
AC_DEFINE([HAVE_CAPSTONE], [1], [Capstone is available])
7580
PHP_EVAL_LIBLINE($CAPSTONE_LIBS, OPCACHE_SHARED_LIBADD)
7681
PHP_EVAL_INCLINE($CAPSTONE_CFLAGS)
77-
fi
78-
79-
PHP_SUBST(DASM_FLAGS)
80-
PHP_SUBST(DASM_ARCH)
81-
82-
AC_MSG_CHECKING(for opagent in default path)
83-
for i in /usr/local /usr; do
84-
if test -r $i/include/opagent.h; then
85-
OPAGENT_DIR=$i
86-
AC_MSG_RESULT(found in $i)
87-
break
88-
fi
89-
done
90-
if test -z "$OPAGENT_DIR"; then
91-
AC_MSG_RESULT(not found)
92-
else
93-
PHP_CHECK_LIBRARY(opagent, op_write_native_code,
94-
[
95-
AC_DEFINE(HAVE_OPROFILE,1,[ ])
96-
PHP_ADD_INCLUDE($OPAGENT_DIR/include)
97-
PHP_ADD_LIBRARY_WITH_PATH(opagent, $OPAGENT_DIR/$PHP_LIBDIR/oprofile, OPCACHE_SHARED_LIBADD)
98-
PHP_SUBST(OPCACHE_SHARED_LIBADD)
99-
],[
100-
AC_MSG_RESULT(not found)
10182
],[
102-
-L$OPAGENT_DIR/$PHP_LIBDIR/oprofile
83+
AC_MSG_ERROR([capstone >= 3.0 required but not found])
10384
])
104-
fi
85+
])
10586

87+
PHP_SUBST(DASM_FLAGS)
88+
PHP_SUBST(DASM_ARCH)
10689
fi
10790

10891
AC_CHECK_FUNCS([mprotect memfd_create])

ext/opcache/jit/Makefile.frag

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ $(builddir)/jit/zend_jit.lo: \
1111
$(srcdir)/jit/zend_jit_disasm.c \
1212
$(srcdir)/jit/zend_jit_gdb.c \
1313
$(srcdir)/jit/zend_jit_perf_dump.c \
14-
$(srcdir)/jit/zend_jit_oprofile.c \
1514
$(srcdir)/jit/zend_jit_vtune.c \
1615
$(srcdir)/jit/zend_jit_trace.c \
1716
$(srcdir)/jit/zend_elf.c

ext/opcache/jit/Makefile.frag.w32

-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ $(BUILD_DIR)\ext\opcache\jit\zend_jit.obj: \
1212
ext/opcache/jit/zend_jit_disasm.c \
1313
ext/opcache/jit/zend_jit_gdb.c \
1414
ext/opcache/jit/zend_jit_perf_dump.c \
15-
ext/opcache/jit/zend_jit_oprofile.c \
1615
ext/opcache/jit/zend_jit_trace.c \
1716
ext/opcache/jit/zend_jit_vtune.c

ext/opcache/jit/zend_jit.c

+4-29
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,6 @@ static int zend_jit_add_veneer(dasm_State *Dst, void *buffer, uint32_t ins, int
720720
# include "jit/zend_jit_gdb.h"
721721
# include "jit/zend_jit_perf_dump.c"
722722
#endif
723-
#ifdef HAVE_OPROFILE
724-
# include "jit/zend_jit_oprofile.c"
725-
#endif
726723

727724
#include "Zend/zend_cpuinfo.h"
728725

@@ -898,7 +895,7 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
898895
size_t size;
899896
int ret;
900897
void *entry;
901-
#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_OPROFILE) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE)
898+
#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE)
902899
zend_string *str = NULL;
903900
#endif
904901

@@ -1009,9 +1006,9 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
10091006
}
10101007
}
10111008

1012-
#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_OPROFILE) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE)
1009+
#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE)
10131010
if (!name) {
1014-
if (JIT_G(debug) & (ZEND_JIT_DEBUG_ASM|ZEND_JIT_DEBUG_GDB|ZEND_JIT_DEBUG_OPROFILE|ZEND_JIT_DEBUG_PERF|ZEND_JIT_DEBUG_VTUNE|ZEND_JIT_DEBUG_PERF_DUMP)) {
1011+
if (JIT_G(debug) & (ZEND_JIT_DEBUG_ASM|ZEND_JIT_DEBUG_GDB|ZEND_JIT_DEBUG_PERF|ZEND_JIT_DEBUG_VTUNE|ZEND_JIT_DEBUG_PERF_DUMP)) {
10151012
str = zend_jit_func_name(op_array);
10161013
if (str) {
10171014
name = ZSTR_VAL(str);
@@ -1059,14 +1056,6 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
10591056
}
10601057
#endif
10611058

1062-
#ifdef HAVE_OPROFILE
1063-
if (JIT_G(debug) & ZEND_JIT_DEBUG_OPROFILE) {
1064-
zend_jit_oprofile_register(
1065-
name,
1066-
entry,
1067-
size);
1068-
}
1069-
#endif
10701059

10711060
#ifdef HAVE_PERFTOOLS
10721061
if (JIT_G(debug) & (ZEND_JIT_DEBUG_PERF|ZEND_JIT_DEBUG_PERF_DUMP)) {
@@ -1096,7 +1085,7 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
10961085
}
10971086
#endif
10981087

1099-
#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_OPROFILE) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE)
1088+
#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE)
11001089
if (str) {
11011090
zend_string_release(str);
11021091
}
@@ -4912,14 +4901,6 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, bool reattached)
49124901
zend_jit_gdb_init();
49134902
#endif
49144903

4915-
#ifdef HAVE_OPROFILE
4916-
if (JIT_G(debug) & ZEND_JIT_DEBUG_OPROFILE) {
4917-
if (!zend_jit_oprofile_startup()) {
4918-
// TODO: error reporting and cleanup ???
4919-
return FAILURE;
4920-
}
4921-
}
4922-
#endif
49234904
#ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
49244905
zend_write_protect = pthread_jit_write_protect_supported_np();
49254906
#endif
@@ -5034,12 +5015,6 @@ ZEND_EXT_API void zend_jit_shutdown(void)
50345015
fprintf(stderr, "\nJIT memory usage: %td\n", (ptrdiff_t)((char*)*dasm_ptr - (char*)dasm_buf));
50355016
}
50365017

5037-
#ifdef HAVE_OPROFILE
5038-
if (JIT_G(debug) & ZEND_JIT_DEBUG_OPROFILE) {
5039-
zend_jit_oprofile_shutdown();
5040-
}
5041-
#endif
5042-
50435018
#ifdef HAVE_GDB
50445019
if (JIT_G(debug) & ZEND_JIT_DEBUG_GDB) {
50455020
zend_jit_gdb_unregister();

ext/opcache/jit/zend_jit.h

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
#define ZEND_JIT_DEBUG_PERF (1<<4)
6060
#define ZEND_JIT_DEBUG_PERF_DUMP (1<<5)
61-
#define ZEND_JIT_DEBUG_OPROFILE (1<<6)
6261
#define ZEND_JIT_DEBUG_VTUNE (1<<7)
6362

6463
#define ZEND_JIT_DEBUG_GDB (1<<8)

ext/opcache/jit/zend_jit_oprofile.c

-50
This file was deleted.

0 commit comments

Comments
 (0)