Skip to content

[NFC, sanitizer_symbolizer] Split Fuchsia and Markup. #72305

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 3 commits into from
Nov 15, 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
2 changes: 1 addition & 1 deletion clang/docs/tools/clang-formatted-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_fuchsia.h
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_win.cpp
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_fuchsia.h
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_constants.h
compiler-rt/lib/sanitizer_common/sanitizer_thread_safety.h
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
compiler-rt/lib/sanitizer_common/sanitizer_type_traits.cpp
Expand Down
4 changes: 3 additions & 1 deletion compiler-rt/lib/sanitizer_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ set(SANITIZER_SYMBOLIZER_SOURCES
sanitizer_symbolizer_markup.cpp
sanitizer_symbolizer_posix_libcdep.cpp
sanitizer_symbolizer_report.cpp
sanitizer_symbolizer_report_fuchsia.cpp
sanitizer_symbolizer_win.cpp
sanitizer_unwind_linux_libcdep.cpp
sanitizer_unwind_fuchsia.cpp
sanitizer_unwind_win.cpp
)

Expand Down Expand Up @@ -189,7 +191,7 @@ set(SANITIZER_IMPL_HEADERS
sanitizer_stoptheworld.h
sanitizer_suppressions.h
sanitizer_symbolizer.h
sanitizer_symbolizer_fuchsia.h
sanitizer_symbolizer_markup_constants.h
sanitizer_symbolizer_internal.h
sanitizer_symbolizer_libbacktrace.h
sanitizer_symbolizer_mac.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "sanitizer_common.h"
#include "sanitizer_interface_internal.h"
#include "sanitizer_internal_defs.h"
#include "sanitizer_symbolizer_fuchsia.h"
# include "sanitizer_symbolizer_markup_constants.h"

using namespace __sanitizer;

Expand Down
54 changes: 3 additions & 51 deletions compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@
//===----------------------------------------------------------------------===//

#include "sanitizer_platform.h"
#if SANITIZER_SYMBOLIZER_MARKUP

#if SANITIZER_FUCHSIA
#include "sanitizer_symbolizer_fuchsia.h"
# endif

# include <limits.h>
# include <unwind.h>
#if SANITIZER_SYMBOLIZER_MARKUP

# include "sanitizer_stacktrace.h"
# include "sanitizer_common.h"
# include "sanitizer_stacktrace_printer.h"
# include "sanitizer_symbolizer.h"
# include "sanitizer_symbolizer_markup_constants.h"

namespace __sanitizer {

Expand Down Expand Up @@ -110,49 +105,6 @@ Symbolizer *Symbolizer::PlatformInit() {

void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }

void StartReportDeadlySignal() {}
void ReportDeadlySignal(const SignalContext &sig, u32 tid,
UnwindSignalStackCallbackType unwind,
const void *unwind_context) {}

#if SANITIZER_CAN_SLOW_UNWIND
struct UnwindTraceArg {
BufferedStackTrace *stack;
u32 max_depth;
};

_Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) {
UnwindTraceArg *arg = static_cast<UnwindTraceArg *>(param);
CHECK_LT(arg->stack->size, arg->max_depth);
uptr pc = _Unwind_GetIP(ctx);
if (pc < PAGE_SIZE) return _URC_NORMAL_STOP;
arg->stack->trace_buffer[arg->stack->size++] = pc;
return (arg->stack->size == arg->max_depth ? _URC_NORMAL_STOP
: _URC_NO_REASON);
}

void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
CHECK_GE(max_depth, 2);
size = 0;
UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)};
_Unwind_Backtrace(Unwind_Trace, &arg);
CHECK_GT(size, 0);
// We need to pop a few frames so that pc is on top.
uptr to_pop = LocatePcInTrace(pc);
// trace_buffer[0] belongs to the current function so we always pop it,
// unless there is only 1 frame in the stack trace (1 frame is always better
// than 0!).
PopStackFrames(Min(to_pop, static_cast<uptr>(1)));
trace_buffer[0] = pc;
}

void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
CHECK(context);
CHECK_GE(max_depth, 2);
UNREACHABLE("signal context doesn't exist");
}
#endif // SANITIZER_CAN_SLOW_UNWIND

} // namespace __sanitizer

#endif // SANITIZER_SYMBOLIZER_MARKUP
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//===-- sanitizer_symbolizer_fuchsia.h -----------------------------------===//
//===-- sanitizer_symbolizer_markup_constants.h
//-----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,10 +9,10 @@
//
// This file is shared between various sanitizers' runtime libraries.
//
// Define Fuchsia's string formats and limits for the markup symbolizer.
// Define string formats and limits for the markup symbolizer.
//===----------------------------------------------------------------------===//
#ifndef SANITIZER_SYMBOLIZER_FUCHSIA_H
#define SANITIZER_SYMBOLIZER_FUCHSIA_H
#ifndef SANITIZER_SYMBOLIZER_MARKUP_CONSTANTS_H
#define SANITIZER_SYMBOLIZER_MARKUP_CONSTANTS_H

#include "sanitizer_internal_defs.h"

Expand Down Expand Up @@ -39,4 +40,4 @@ constexpr const char *kFormatFrame = "{{{bt:%u:%p}}}";

} // namespace __sanitizer

#endif // SANITIZER_SYMBOLIZER_FUCHSIA_H
#endif // SANITIZER_SYMBOLIZER_MARKUP_CONSTANTS_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===-- sanitizer_symbolizer_report_fuchsia.cpp
//-----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Implementation of the report functions for fuchsia.
//
//===----------------------------------------------------------------------===//

#include "sanitizer_platform.h"

#if SANITIZER_SYMBOLIZER_MARKUP

# include "sanitizer_common.h"

namespace __sanitizer {
void StartReportDeadlySignal() {}

void ReportDeadlySignal(const SignalContext &sig, u32 tid,
UnwindSignalStackCallbackType unwind,
const void *unwind_context) {}

void HandleDeadlySignal(void *siginfo, void *context, u32 tid,
UnwindSignalStackCallbackType unwind,
const void *unwind_context) {}

} // namespace __sanitizer

#endif // SANITIZER_SYMBOLIZER_MARKUP
66 changes: 66 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_unwind_fuchsia.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//===------------------ sanitizer_unwind_fuchsia.cpp
//---------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
/// Sanitizer unwind Fuchsia specific functions.
//
//===----------------------------------------------------------------------===//

#include "sanitizer_platform.h"
#if SANITIZER_FUCHSIA

# include <limits.h>
# include <unwind.h>

# include "sanitizer_common.h"
# include "sanitizer_stacktrace.h"

namespace __sanitizer {

# if SANITIZER_CAN_SLOW_UNWIND
struct UnwindTraceArg {
BufferedStackTrace *stack;
u32 max_depth;
};

_Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) {
UnwindTraceArg *arg = static_cast<UnwindTraceArg *>(param);
CHECK_LT(arg->stack->size, arg->max_depth);
uptr pc = _Unwind_GetIP(ctx);
if (pc < GetPageSizeCached())
return _URC_NORMAL_STOP;
arg->stack->trace_buffer[arg->stack->size++] = pc;
return (arg->stack->size == arg->max_depth ? _URC_NORMAL_STOP
: _URC_NO_REASON);
}

void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
CHECK_GE(max_depth, 2);
size = 0;
UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)};
_Unwind_Backtrace(Unwind_Trace, &arg);
CHECK_GT(size, 0);
// We need to pop a few frames so that pc is on top.
uptr to_pop = LocatePcInTrace(pc);
// trace_buffer[0] belongs to the current function so we always pop it,
// unless there is only 1 frame in the stack trace (1 frame is always better
// than 0!).
PopStackFrames(Min(to_pop, static_cast<uptr>(1)));
trace_buffer[0] = pc;
}

void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
CHECK(context);
CHECK_GE(max_depth, 2);
UNREACHABLE("signal context doesn't exist");
}
# endif // SANITIZER_CAN_SLOW_UNWIND

} // namespace __sanitizer

#endif // SANITIZER_FUCHSIA
2 changes: 1 addition & 1 deletion compiler-rt/lib/xray/xray_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <utility>

#if SANITIZER_FUCHSIA
#include "sanitizer_common/sanitizer_symbolizer_fuchsia.h"
#include "sanitizer_common/sanitizer_symbolizer_markup_constants.h"

#include <inttypes.h>
#include <zircon/process.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ source_set("sources") {
"sanitizer_suppressions.h",
"sanitizer_symbolizer.cpp",
"sanitizer_symbolizer.h",
"sanitizer_symbolizer_fuchsia.h",
"sanitizer_symbolizer_markup_constants.h",
"sanitizer_symbolizer_internal.h",
"sanitizer_symbolizer_libbacktrace.cpp",
"sanitizer_symbolizer_libbacktrace.h",
Expand Down