Skip to content

Use capstone explicitly, drop oprofile (GH 10876) #10918

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 2 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
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
43 changes: 13 additions & 30 deletions ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ PHP_ARG_ENABLE([opcache-jit],
[yes],
[no])

PHP_ARG_WITH([opcache-capstone],,
[AS_HELP_STRING([--with-opcache-capstone],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think --with-capstone should be enough.
In general, we need the same flag for Windows.
it's great you kept udis86 yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think disambiguation of flags isn't a bad thing but either works for me.
#10952

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had second thoughts about --with-capstone after seeing that all of the FPM flags were named --with-fpm-foo, but FWIW I don't mind either way.

[support opcache JIT disassembly through capstone])],
[no],
[no])

if test "$PHP_OPCACHE" != "no"; then

dnl Always build as shared extension
Expand Down Expand Up @@ -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])
Expand Down
1 change: 0 additions & 1 deletion ext/opcache/jit/Makefile.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion ext/opcache/jit/Makefile.frag.w32
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 4 additions & 29 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion ext/opcache/jit/zend_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 0 additions & 50 deletions ext/opcache/jit/zend_jit_oprofile.c

This file was deleted.