kphp: Depend on libandroid-execinfo

This commit is contained in:
Tee KOBAYASHI 2022-11-07 09:40:29 +09:00 committed by xtkoba
parent 69cd4ef6a9
commit f560953ff5
8 changed files with 8 additions and 236 deletions

View File

@ -4,10 +4,10 @@ TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_MAINTAINER="@termux"
_COMMIT=b1b2cec0f0e1206e1c134830ebd1f28e21bbd330
TERMUX_PKG_VERSION=2021.12.30
TERMUX_PKG_REVISION=2
TERMUX_PKG_REVISION=3
TERMUX_PKG_SRCURL=https://github.com/VKCOM/kphp.git
TERMUX_PKG_GIT_BRANCH=master
TERMUX_PKG_DEPENDS="fmt, libc++, libcurl, libmsgpack-cxx, libre2, libuber-h3, libucontext, libyaml-cpp, openssl-1.1, pcre, zstd"
TERMUX_PKG_DEPENDS="fmt, libandroid-execinfo, libc++, libcurl, libmsgpack-cxx, libre2, libuber-h3, libucontext, libyaml-cpp, openssl-1.1, pcre, zstd"
TERMUX_PKG_BUILD_DEPENDS="kphp-timelib"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DKPHP_TESTS=OFF
@ -30,6 +30,8 @@ termux_step_post_get_source() {
}
termux_step_pre_configure() {
LDFLAGS+=" -landroid-execinfo"
_NEED_DUMMY_LIBPTHREAD_A=
_LIBPTHREAD_A=$TERMUX_PREFIX/lib/libpthread.a
if [ ! -e $_LIBPTHREAD_A ]; then
@ -40,7 +42,6 @@ termux_step_pre_configure() {
CPPFLAGS="-I$TERMUX_PREFIX/include/openssl-1.1 $CPPFLAGS"
CXXFLAGS="-I$TERMUX_PREFIX/include/openssl-1.1 $CXXFLAGS"
LDFLAGS="-L$TERMUX_PREFIX/lib/openssl-1.1 -Wl,-rpath=$TERMUX_PREFIX/lib/openssl-1.1 $LDFLAGS"
}
termux_step_post_configure() {

View File

@ -1,54 +0,0 @@
--- a/common/dl-utils-lite.cpp
+++ b/common/dl-utils-lite.cpp
@@ -7,7 +7,9 @@
#include <array>
#include <cassert>
#include <cinttypes>
+#ifndef __ANDROID__
#include <execinfo.h>
+#endif
#include <fcntl.h>
#include <limits>
#include <stdarg.h>
@@ -23,6 +25,7 @@
#include "common/stats/provider.h"
#include "common/wrappers/pathname.h"
+#ifndef __ANDROID__
#if DL_DEBUG_MEM >= 1
# define MEM_POS {\
void *buffer[64]; \
@@ -34,6 +37,9 @@
#else
# define MEM_POS
#endif
+#else /* __ANDROID__ */
+# define MEM_POS
+#endif
static std::array<char, 1024> assert_message{{0}};
@@ -44,16 +50,23 @@
return static_cast<double>(T.tv_sec) + static_cast<double>(T.tv_nsec) * 1e-9;
}
+#ifdef __ANDROID__
+void dl_print_backtrace(void **, int) {
+}
+#else
void dl_print_backtrace(void **trace, int trace_size) {
write (2, "\n------- Stack Backtrace -------\n", 33);
backtrace_symbols_fd (trace, trace_size, 2);
write (2, "-------------------------------\n", 32);
}
+#endif
void dl_print_backtrace() {
+#ifndef __ANDROID__
void *buffer[64];
int nptrs = backtrace (buffer, 64);
dl_print_backtrace(buffer, nptrs);
+#endif
}
void dl_print_backtrace_gdb() {

View File

@ -1,33 +1,11 @@
--- a/common/fast-backtrace.cpp
+++ b/common/fast-backtrace.cpp
@@ -6,12 +6,19 @@
#include <algorithm>
#include <cassert>
+#ifndef __ANDROID__
#include <execinfo.h>
+#endif
#include "common/sanitizer.h"
char *stack_end;
+#ifdef __ANDROID__
+int fast_backtrace (void **, int) {
+ return 0;
+}
+#else
#if defined(__aarch64__) || defined(__APPLE__)
int fast_backtrace (void **buffer, int size) {
return backtrace(buffer, size);
@@ -52,8 +59,9 @@
#else
@@ -53,7 +53,7 @@
#error "Unsupported arch"
#endif
+#endif /* __ANDROID__ */
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__ANDROID__)
+#if defined(__aarch64__) || defined(__APPLE__)
int fast_backtrace_without_recursions(void **, int) noexcept {
return 0;
}

View File

@ -1,37 +1,6 @@
--- a/common/server/signals.cpp
+++ b/common/server/signals.cpp
@@ -7,7 +7,9 @@
#include <cerrno>
#include <cstdlib>
#include <cstring>
+#ifndef __ANDROID__
#include <execinfo.h>
+#endif
#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>
@@ -42,9 +44,12 @@
}
extra_debug_handler_t extra_debug_handler;
+#ifndef __ANDROID__
static volatile int double_print_backtrace_guard;
+#endif
void print_backtrace() {
+#ifndef __ANDROID__
if (double_print_backtrace_guard) {
kwrite(STDERR_FILENO, "\n---Ignoring recursive print backtrace---\n", 42);
return;
@@ -65,6 +70,7 @@
extra_debug_handler = nullptr;
debug_handler();
}
+#endif /* __ANDROID__ */
}
static pthread_t debug_main_pthread_id;
@@ -224,6 +230,10 @@
@@ -224,6 +224,10 @@
}

View File

@ -1,31 +0,0 @@
--- a/runtime/kphp-backtrace.cpp
+++ b/runtime/kphp-backtrace.cpp
@@ -5,7 +5,9 @@
#include "runtime/kphp-backtrace.h"
#include <cxxabi.h>
+#ifndef __ANDROID__
#include <execinfo.h>
+#endif
#include "common/fast-backtrace.h"
#include "common/wrappers/string_view.h"
@@ -14,6 +16,10 @@
std::forward_list<char **> KphpBacktrace::last_used_symbols_;
+#ifdef __ANDROID__
+KphpBacktrace::KphpBacktrace(void **, int32_t) noexcept {
+}
+#else
KphpBacktrace::KphpBacktrace(void **raw_backtrace, int32_t size) noexcept {
dl::CriticalSectionGuard signal_critical_section;
if ((symbols_begin_ = backtrace_symbols(raw_backtrace, size))) {
@@ -21,6 +27,7 @@
last_used_symbols_.emplace_front(symbols_begin_);
}
}
+#endif
void KphpBacktrace::clear() noexcept {
dl::CriticalSectionGuard signal_critical_section;

View File

@ -1,31 +0,0 @@
--- a/runtime/php_assert.cpp
+++ b/runtime/php_assert.cpp
@@ -12,7 +12,9 @@
#include <csignal>
#include <ctime>
#include <cxxabi.h>
+#ifndef __ANDROID__
#include <execinfo.h>
+#endif
#include <unistd.h>
#include <sys/wait.h>
@@ -46,6 +48,10 @@
return &__start_run_scheduler_section <= address && address <= &__stop_run_scheduler_section;
};
+#ifdef __ANDROID__
+static void print_demangled_adresses(void **, int, int, bool) {
+}
+#else
static void print_demangled_adresses(void **buffer, int nptrs, int num_shift, bool allow_gdb) {
if (php_warning_level == 1) {
for (int i = 0; i < nptrs; i++) {
@@ -87,6 +93,7 @@
}
}
}
+#endif /* __ANDROID__ */
static void php_warning_impl(bool out_of_memory, int error_type, char const *message, va_list args) {
if (php_warning_level == 0 || php_disable_warnings) {

View File

@ -1,29 +0,0 @@
--- a/server/json-logger.cpp
+++ b/server/json-logger.cpp
@@ -4,7 +4,9 @@
#include <cstring>
#include <cinttypes>
+#ifndef __ANDROID__
#include <execinfo.h>
+#endif
#include <fcntl.h>
#include <unistd.h>
@@ -241,11 +243,16 @@
json_out_it->finish_json_and_flush(json_log_fd_);
}
+#ifdef __ANDROID__
+void JsonLogger::write_log_with_backtrace(vk::string_view, int) noexcept {
+}
+#else
void JsonLogger::write_log_with_backtrace(vk::string_view message, int type) noexcept {
std::array<void *, 64> trace{};
const int trace_size = backtrace(trace.data(), trace.size());
write_log(message, type, time(nullptr), trace.data(), trace_size, true);
}
+#endif
void JsonLogger::write_stack_overflow_log(int type) noexcept {
std::array<void *, 64> trace{};

View File

@ -1,13 +1,6 @@
--- a/server/php-runner.cpp
+++ b/server/php-runner.cpp
@@ -9,11 +9,17 @@
#include <cstdlib>
#include <cstring>
#include <exception>
+#ifndef __ANDROID__
#include <execinfo.h>
+#endif
#include <sys/mman.h>
@@ -14,6 +14,10 @@
#include <sys/time.h>
#include <unistd.h>
@ -18,27 +11,3 @@
#include "common/fast-backtrace.h"
#include "common/kernel-version.h"
#include "common/kprintf.h"
@@ -518,7 +524,11 @@
print_prologue(cur_time);
void *trace[64];
+#ifndef __ANDROID__
const int trace_size = backtrace(trace, 64);
+#else
+ const int trace_size = 0;
+#endif
void *addr = info->si_addr;
if (PHPScriptBase::is_running && PHPScriptBase::current_script->is_protected(static_cast<char *>(addr))) {
@@ -549,7 +559,11 @@
void sigabrt_handler(int) {
const int64_t cur_time = time(nullptr);
void *trace[64];
+#ifndef __ANDROID__
const int trace_size = backtrace(trace, 64);
+#else
+ const int trace_size = 0;
+#endif
vk::string_view msg{dl_get_assert_message()};
if (msg.empty()) {
msg = "SIGABRT terminating program";