Skip to content
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
3 changes: 2 additions & 1 deletion ci/test/00_setup_env_native_tsan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export PACKAGES="clang-8 llvm-8 python3-zmq qtbase5-dev qttools5-dev-tools libev
export DEP_OPTS="NO_UPNP=1 DEBUG=1"
export TEST_RUNNER_EXTRA="--extended --exclude feature_pruning,feature_dbcrash,wallet_multiwallet.py" # Temporarily suppress ASan heap-use-after-free (see issue #14163)
export GOAL="install"
export BITCOIN_CONFIG="--enable-zmq --enable-reduce-exports --enable-crash-hooks --with-sanitizers=thread"
export BITCOIN_CONFIG="--enable-zmq --enable-reduce-exports --enable-crash-hooks --enable-suppress-external-warnings --with-sanitizers=thread"
export BITCOIN_CONFIG="${BITCOIN_CONFIG} CC=clang-15 CXX=clang++-15 CXXFLAGS=-Werror=thread-safety"
export CPPFLAGS="-DDEBUG_LOCKORDER -DENABLE_DASH_DEBUG -DARENA_DEBUG"
export PYZMQ=true
17 changes: 15 additions & 2 deletions contrib/containers/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ RUN apt-get update && apt-get install $APT_ARGS \
wine-stable \
wine32 \
wine64 \
xorriso \
&& rm -rf /var/lib/apt/lists/*
xorriso

ARG CPPCHECK_VERSION=2.10
RUN curl -sL "https://github.com/danmar/cppcheck/archive/${CPPCHECK_VERSION}.tar.gz" | tar -xvzf - --directory /tmp/
Expand All @@ -102,6 +101,20 @@ RUN \
update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix; \
exit 0

ARG LLVM_VERSION=15
# Setup Clang+LLVM support
RUN apt-get update && apt-get install $APT_ARGS \
lsb-release \
software-properties-common \
gnupg \
&& rm -rf /var/lib/apt/lists/*

RUN cd /tmp && \
wget https://apt.llvm.org/llvm.sh && \
chmod +x llvm.sh && \
/tmp/llvm.sh ${LLVM_VERSION} && \
rm -rf /tmp/llvm.sh

RUN \
mkdir -p /src/dash && \
mkdir -p /cache/ccache && \
Expand Down
47 changes: 22 additions & 25 deletions src/stacktraces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <memory>
#include <atomic>

#if WIN32
#if defined(WIN32)
#include <windows.h>
#include <dbghelp.h>
#include <thread>
Expand All @@ -30,14 +30,14 @@
#include <csignal>
#endif

#if !WIN32
#if !defined(WIN32)
#include <dlfcn.h>
#if !__APPLE__
#if !defined(__APPLE__)
#include <link.h>
#endif
#endif

#if __APPLE__
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#include <mach/mach_init.h>
#include <sys/sysctl.h>
Expand All @@ -52,7 +52,7 @@

std::string DemangleSymbol(const std::string& name)
{
#if __GNUC__ || __clang__
#if defined(__GNUC__) || defined(__clang__)
int status = -4; // some arbitrary value to eliminate the compiler warning
char* str = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status);
if (status != 0) {
Expand All @@ -74,7 +74,7 @@ static std::atomic<bool> skipAbortSignal(false);

static ssize_t GetExeFileNameImpl(char* buf, size_t bufSize)
{
#if WIN32
#if defined(WIN32)
std::vector<TCHAR> tmp(bufSize);
DWORD len = GetModuleFileName(nullptr, tmp.data(), bufSize);
if (len >= bufSize) {
Expand All @@ -84,7 +84,7 @@ static ssize_t GetExeFileNameImpl(char* buf, size_t bufSize)
buf[i] = (char)tmp[i];
}
return len;
#elif __APPLE__
#elif defined(__APPLE__)
uint32_t bufSize2 = (uint32_t)bufSize;
if (_NSGetExecutablePath(buf, &bufSize2) != 0) {
// it's not entirely clear if the value returned by _NSGetExecutablePath includes the null character
Expand Down Expand Up @@ -127,7 +127,7 @@ static void my_backtrace_error_callback (void *data, const char *msg,

static backtrace_state* GetLibBacktraceState()
{
#if WIN32
#if defined(WIN32)
// libbacktrace is not able to handle the DWARF debuglink in the .exe
// but luckily we can just specify the .dbg file here as it's a valid PE/XCOFF file
static std::string debugFileName = g_exeFileName + ".dbg";
Expand All @@ -140,7 +140,7 @@ static backtrace_state* GetLibBacktraceState()
}
#endif // ENABLE_STACKTRACES

#if WIN32
#if defined(WIN32)
static uint64_t GetBaseAddress()
{
return 0;
Expand Down Expand Up @@ -188,15 +188,15 @@ static __attribute__((noinline)) std::vector<uint64_t> GetStackFrames(size_t ski
STACKFRAME64 stackframe;
ZeroMemory(&stackframe, sizeof(STACKFRAME64));

#ifdef __i386__
#if defined(__i386__)
image = IMAGE_FILE_MACHINE_I386;
stackframe.AddrPC.Offset = context.Eip;
stackframe.AddrPC.Mode = AddrModeFlat;
stackframe.AddrFrame.Offset = context.Ebp;
stackframe.AddrFrame.Mode = AddrModeFlat;
stackframe.AddrStack.Offset = context.Esp;
stackframe.AddrStack.Mode = AddrModeFlat;
#elif __x86_64__
#elif defined(__x86_64__)
image = IMAGE_FILE_MACHINE_AMD64;
stackframe.AddrPC.Offset = context.Rip;
stackframe.AddrPC.Mode = AddrModeFlat;
Expand Down Expand Up @@ -240,7 +240,7 @@ static __attribute__((noinline)) std::vector<uint64_t> GetStackFrames(size_t ski
}
#else

#if __APPLE__
#if defined(__APPLE__)
static uint64_t GetBaseAddress()
{
mach_port_name_t target_task;
Expand Down Expand Up @@ -534,14 +534,11 @@ static void PrintCrashInfo(const crash_info& ci)
static StdMutex g_stacktraces_mutex;
static std::map<void*, std::shared_ptr<std::vector<uint64_t>>> g_stacktraces;

#if CRASH_HOOKS_WRAPPED_CXX_ABI
#ifdef CRASH_HOOKS_WRAPPED_CXX_ABI
// These come in through -Wl,-wrap
// It only works on GCC
extern "C" void* __real___cxa_allocate_exception(size_t thrown_size);
extern "C" void __real___cxa_free_exception(void * thrown_exception);
#if __clang__
#error not supported on WIN32 (no dlsym support)
#elif WIN32
#if defined(WIN32)
extern "C" void __real__assert(const char *assertion, const char *file, unsigned int line);
extern "C" void __real__wassert(const wchar_t *assertion, const wchar_t *file, unsigned int line);
#else
Expand All @@ -560,13 +557,13 @@ extern "C" void __real___cxa_free_exception(void * thrown_exception)
static auto f = (void(*)(void*))dlsym(RTLD_NEXT, "__cxa_free_exception");
return f(thrown_exception);
}
#if __clang__
#if defined(__clang__) && defined(__APPLE__)
extern "C" void __attribute__((noreturn)) __real___assert_rtn(const char *function, const char *file, int line, const char *assertion)
{
static auto f = (void(__attribute__((noreturn)) *) (const char*, const char*, int, const char*))dlsym(RTLD_NEXT, "__assert_rtn");
f(function, file, line, assertion);
}
#elif WIN32
#elif defined(WIN32)
#error not supported on WIN32 (no dlsym support)
#else
extern "C" void __real___assert_fail(const char *assertion, const char *file, unsigned int line, const char *function)
Expand All @@ -577,7 +574,7 @@ extern "C" void __real___assert_fail(const char *assertion, const char *file, un
#endif
#endif

#if CRASH_HOOKS_WRAPPED_CXX_ABI
#ifdef CRASH_HOOKS_WRAPPED_CXX_ABI
#define WRAPPED_NAME(x) __wrap_##x
#else
#define WRAPPED_NAME(x) x
Expand Down Expand Up @@ -625,15 +622,15 @@ static __attribute__((noinline)) crash_info GetCrashInfoFromAssertion(const char
return ci;
}

#if __clang__
#if defined(__clang__) && defined(__APPLE__)
extern "C" void __attribute__((noinline)) WRAPPED_NAME(__assert_rtn)(const char *function, const char *file, int line, const char *assertion)
{
auto ci = GetCrashInfoFromAssertion(assertion, file, line, function);
PrintCrashInfo(ci);
skipAbortSignal = true;
__real___assert_rtn(function, file, line, assertion);
}
#elif WIN32
#elif defined(WIN32)
extern "C" void __attribute__((noinline)) WRAPPED_NAME(_assert)(const char *assertion, const char *file, unsigned int line)
{
auto ci = GetCrashInfoFromAssertion(assertion, file, line, nullptr);
Expand Down Expand Up @@ -763,7 +760,7 @@ void RegisterPrettyTerminateHander()
std::set_terminate(terminate_handler);
}

#if !WIN32
#if !defined(WIN32)
static void HandlePosixSignal(int s)
{
if (s == SIGABRT && skipAbortSignal) {
Expand Down Expand Up @@ -840,7 +837,7 @@ LONG WINAPI HandleWindowsException(EXCEPTION_POINTERS * ExceptionInfo)

void RegisterPrettySignalHandlers()
{
#if WIN32
#if defined(WIN32)
SetUnhandledExceptionFilter(HandleWindowsException);
#else
const std::vector<int> posix_signals = {
Expand All @@ -856,7 +853,7 @@ void RegisterPrettySignalHandlers()
SIGTRAP, // Trace/breakpoint trap
SIGXCPU, // CPU time limit exceeded (4.2BSD)
SIGXFSZ, // File size limit exceeded (4.2BSD)
#if __APPLE__
#if defined(__APPLE__)
SIGEMT, // emulation instruction executed
#endif
};
Expand Down