diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4 index 444ded9976ac1..fb3324cf82a3d 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 98c5cdaea2494..f9ae2e0cf4b99 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/ext/opcache/jit/Makefile.frag.w32 b/ext/opcache/jit/Makefile.frag.w32 index ed2b4ad4fec89..a9533e98edcea 100644 --- a/ext/opcache/jit/Makefile.frag.w32 +++ b/ext/opcache/jit/Makefile.frag.w32 @@ -12,6 +12,5 @@ $(BUILD_DIR)\ext\opcache\jit\zend_jit.obj: \ ext/opcache/jit/zend_jit_disasm.c \ ext/opcache/jit/zend_jit_gdb.c \ ext/opcache/jit/zend_jit_perf_dump.c \ - ext/opcache/jit/zend_jit_oprofile.c \ ext/opcache/jit/zend_jit_trace.c \ ext/opcache/jit/zend_jit_vtune.c diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index adf48691c3930..231c976d0bab7 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -720,9 +720,6 @@ static int zend_jit_add_veneer(dasm_State *Dst, void *buffer, uint32_t ins, int # include "jit/zend_jit_gdb.h" # include "jit/zend_jit_perf_dump.c" #endif -#ifdef HAVE_OPROFILE -# include "jit/zend_jit_oprofile.c" -#endif #include "Zend/zend_cpuinfo.h" @@ -898,7 +895,7 @@ static void *dasm_link_and_encode(dasm_State **dasm_state, size_t size; int ret; void *entry; -#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_OPROFILE) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE) +#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE) zend_string *str = NULL; #endif @@ -1009,9 +1006,9 @@ static void *dasm_link_and_encode(dasm_State **dasm_state, } } -#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_OPROFILE) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE) +#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE) if (!name) { - 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)) { + 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)) { str = zend_jit_func_name(op_array); if (str) { name = ZSTR_VAL(str); @@ -1059,14 +1056,6 @@ static void *dasm_link_and_encode(dasm_State **dasm_state, } #endif -#ifdef HAVE_OPROFILE - if (JIT_G(debug) & ZEND_JIT_DEBUG_OPROFILE) { - zend_jit_oprofile_register( - name, - entry, - size); - } -#endif #ifdef HAVE_PERFTOOLS 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, } #endif -#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_OPROFILE) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE) +#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE) if (str) { zend_string_release(str); } @@ -4912,14 +4901,6 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, bool reattached) zend_jit_gdb_init(); #endif -#ifdef HAVE_OPROFILE - if (JIT_G(debug) & ZEND_JIT_DEBUG_OPROFILE) { - if (!zend_jit_oprofile_startup()) { - // TODO: error reporting and cleanup ??? - return FAILURE; - } - } -#endif #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP zend_write_protect = pthread_jit_write_protect_supported_np(); #endif @@ -5034,12 +5015,6 @@ ZEND_EXT_API void zend_jit_shutdown(void) fprintf(stderr, "\nJIT memory usage: %td\n", (ptrdiff_t)((char*)*dasm_ptr - (char*)dasm_buf)); } -#ifdef HAVE_OPROFILE - if (JIT_G(debug) & ZEND_JIT_DEBUG_OPROFILE) { - zend_jit_oprofile_shutdown(); - } -#endif - #ifdef HAVE_GDB if (JIT_G(debug) & ZEND_JIT_DEBUG_GDB) { zend_jit_gdb_unregister(); diff --git a/ext/opcache/jit/zend_jit.h b/ext/opcache/jit/zend_jit.h index d22422181af9c..09380f14ebe59 100644 --- a/ext/opcache/jit/zend_jit.h +++ b/ext/opcache/jit/zend_jit.h @@ -58,7 +58,6 @@ #define ZEND_JIT_DEBUG_PERF (1<<4) #define ZEND_JIT_DEBUG_PERF_DUMP (1<<5) -#define ZEND_JIT_DEBUG_OPROFILE (1<<6) #define ZEND_JIT_DEBUG_VTUNE (1<<7) #define ZEND_JIT_DEBUG_GDB (1<<8) diff --git a/ext/opcache/jit/zend_jit_oprofile.c b/ext/opcache/jit/zend_jit_oprofile.c deleted file mode 100644 index 36081064b543e..0000000000000 --- a/ext/opcache/jit/zend_jit_oprofile.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend JIT | - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Dmitry Stogov | - +----------------------------------------------------------------------+ -*/ - -#define HAVE_OPROFILE 1 - -#include - -static op_agent_t op_agent = NULL; - -static void zend_jit_oprofile_register(const char *name, - const void *start, - size_t size) -{ - if (op_agent) { - op_write_native_code(op_agent, name, (uint64_t)(uintptr_t)start, start, size); - } -} - -static int zend_jit_oprofile_startup(void) -{ - op_agent = op_open_agent(); - if (!op_agent) { - fprintf(stderr, "OpAgent initialization failed [%d]!\n", errno); - return 0; - } - return 1; -} - -static void zend_jit_oprofile_shutdown(void) -{ - if (op_agent) { -//??? sleep(60); - op_close_agent(op_agent); - } -}