Skip to content

Commit 3dc098d

Browse files
author
Andres Villegas
authored
[NFC, sanitizer_symbolizer] Split Fuchsia and Markup. (#72305)
This PR separates parts of the symbolizer markup implementation that are Fuchsia OS specific. This is in preparation of enabling symbolizer markup in other OSs.
1 parent 8dfac29 commit 3dc098d

File tree

9 files changed

+115
-61
lines changed

9 files changed

+115
-61
lines changed

clang/docs/tools/clang-formatted-files.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
18371837
compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
18381838
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_fuchsia.h
18391839
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_win.cpp
1840-
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_fuchsia.h
1840+
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_constants.h
18411841
compiler-rt/lib/sanitizer_common/sanitizer_thread_safety.h
18421842
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
18431843
compiler-rt/lib/sanitizer_common/sanitizer_type_traits.cpp

compiler-rt/lib/sanitizer_common/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ set(SANITIZER_SYMBOLIZER_SOURCES
9090
sanitizer_symbolizer_markup.cpp
9191
sanitizer_symbolizer_posix_libcdep.cpp
9292
sanitizer_symbolizer_report.cpp
93+
sanitizer_symbolizer_report_fuchsia.cpp
9394
sanitizer_symbolizer_win.cpp
9495
sanitizer_unwind_linux_libcdep.cpp
96+
sanitizer_unwind_fuchsia.cpp
9597
sanitizer_unwind_win.cpp
9698
)
9799

@@ -189,7 +191,7 @@ set(SANITIZER_IMPL_HEADERS
189191
sanitizer_stoptheworld.h
190192
sanitizer_suppressions.h
191193
sanitizer_symbolizer.h
192-
sanitizer_symbolizer_fuchsia.h
194+
sanitizer_symbolizer_markup_constants.h
193195
sanitizer_symbolizer_internal.h
194196
sanitizer_symbolizer_libbacktrace.h
195197
sanitizer_symbolizer_mac.h

compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "sanitizer_common.h"
3636
#include "sanitizer_interface_internal.h"
3737
#include "sanitizer_internal_defs.h"
38-
#include "sanitizer_symbolizer_fuchsia.h"
38+
# include "sanitizer_symbolizer_markup_constants.h"
3939

4040
using namespace __sanitizer;
4141

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "sanitizer_platform.h"
15-
#if SANITIZER_SYMBOLIZER_MARKUP
16-
17-
#if SANITIZER_FUCHSIA
18-
#include "sanitizer_symbolizer_fuchsia.h"
19-
# endif
2015

21-
# include <limits.h>
22-
# include <unwind.h>
16+
#if SANITIZER_SYMBOLIZER_MARKUP
2317

24-
# include "sanitizer_stacktrace.h"
18+
# include "sanitizer_common.h"
2519
# include "sanitizer_stacktrace_printer.h"
2620
# include "sanitizer_symbolizer.h"
21+
# include "sanitizer_symbolizer_markup_constants.h"
2722

2823
namespace __sanitizer {
2924

@@ -110,49 +105,6 @@ Symbolizer *Symbolizer::PlatformInit() {
110105

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

113-
void StartReportDeadlySignal() {}
114-
void ReportDeadlySignal(const SignalContext &sig, u32 tid,
115-
UnwindSignalStackCallbackType unwind,
116-
const void *unwind_context) {}
117-
118-
#if SANITIZER_CAN_SLOW_UNWIND
119-
struct UnwindTraceArg {
120-
BufferedStackTrace *stack;
121-
u32 max_depth;
122-
};
123-
124-
_Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) {
125-
UnwindTraceArg *arg = static_cast<UnwindTraceArg *>(param);
126-
CHECK_LT(arg->stack->size, arg->max_depth);
127-
uptr pc = _Unwind_GetIP(ctx);
128-
if (pc < PAGE_SIZE) return _URC_NORMAL_STOP;
129-
arg->stack->trace_buffer[arg->stack->size++] = pc;
130-
return (arg->stack->size == arg->max_depth ? _URC_NORMAL_STOP
131-
: _URC_NO_REASON);
132-
}
133-
134-
void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
135-
CHECK_GE(max_depth, 2);
136-
size = 0;
137-
UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)};
138-
_Unwind_Backtrace(Unwind_Trace, &arg);
139-
CHECK_GT(size, 0);
140-
// We need to pop a few frames so that pc is on top.
141-
uptr to_pop = LocatePcInTrace(pc);
142-
// trace_buffer[0] belongs to the current function so we always pop it,
143-
// unless there is only 1 frame in the stack trace (1 frame is always better
144-
// than 0!).
145-
PopStackFrames(Min(to_pop, static_cast<uptr>(1)));
146-
trace_buffer[0] = pc;
147-
}
148-
149-
void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
150-
CHECK(context);
151-
CHECK_GE(max_depth, 2);
152-
UNREACHABLE("signal context doesn't exist");
153-
}
154-
#endif // SANITIZER_CAN_SLOW_UNWIND
155-
156108
} // namespace __sanitizer
157109

158110
#endif // SANITIZER_SYMBOLIZER_MARKUP

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_fuchsia.h renamed to compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_constants.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//===-- sanitizer_symbolizer_fuchsia.h -----------------------------------===//
1+
//===-- sanitizer_symbolizer_markup_constants.h
2+
//-----------------------------------===//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.
@@ -8,10 +9,10 @@
89
//
910
// This file is shared between various sanitizers' runtime libraries.
1011
//
11-
// Define Fuchsia's string formats and limits for the markup symbolizer.
12+
// Define string formats and limits for the markup symbolizer.
1213
//===----------------------------------------------------------------------===//
13-
#ifndef SANITIZER_SYMBOLIZER_FUCHSIA_H
14-
#define SANITIZER_SYMBOLIZER_FUCHSIA_H
14+
#ifndef SANITIZER_SYMBOLIZER_MARKUP_CONSTANTS_H
15+
#define SANITIZER_SYMBOLIZER_MARKUP_CONSTANTS_H
1516

1617
#include "sanitizer_internal_defs.h"
1718

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

4041
} // namespace __sanitizer
4142

42-
#endif // SANITIZER_SYMBOLIZER_FUCHSIA_H
43+
#endif // SANITIZER_SYMBOLIZER_MARKUP_CONSTANTS_H
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- sanitizer_symbolizer_report_fuchsia.cpp
2+
//-----------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// Implementation of the report functions for fuchsia.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "sanitizer_platform.h"
15+
16+
#if SANITIZER_SYMBOLIZER_MARKUP
17+
18+
# include "sanitizer_common.h"
19+
20+
namespace __sanitizer {
21+
void StartReportDeadlySignal() {}
22+
23+
void ReportDeadlySignal(const SignalContext &sig, u32 tid,
24+
UnwindSignalStackCallbackType unwind,
25+
const void *unwind_context) {}
26+
27+
void HandleDeadlySignal(void *siginfo, void *context, u32 tid,
28+
UnwindSignalStackCallbackType unwind,
29+
const void *unwind_context) {}
30+
31+
} // namespace __sanitizer
32+
33+
#endif // SANITIZER_SYMBOLIZER_MARKUP
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===------------------ sanitizer_unwind_fuchsia.cpp
2+
//---------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
/// Sanitizer unwind Fuchsia specific functions.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "sanitizer_platform.h"
15+
#if SANITIZER_FUCHSIA
16+
17+
# include <limits.h>
18+
# include <unwind.h>
19+
20+
# include "sanitizer_common.h"
21+
# include "sanitizer_stacktrace.h"
22+
23+
namespace __sanitizer {
24+
25+
# if SANITIZER_CAN_SLOW_UNWIND
26+
struct UnwindTraceArg {
27+
BufferedStackTrace *stack;
28+
u32 max_depth;
29+
};
30+
31+
_Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, void *param) {
32+
UnwindTraceArg *arg = static_cast<UnwindTraceArg *>(param);
33+
CHECK_LT(arg->stack->size, arg->max_depth);
34+
uptr pc = _Unwind_GetIP(ctx);
35+
if (pc < GetPageSizeCached())
36+
return _URC_NORMAL_STOP;
37+
arg->stack->trace_buffer[arg->stack->size++] = pc;
38+
return (arg->stack->size == arg->max_depth ? _URC_NORMAL_STOP
39+
: _URC_NO_REASON);
40+
}
41+
42+
void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
43+
CHECK_GE(max_depth, 2);
44+
size = 0;
45+
UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)};
46+
_Unwind_Backtrace(Unwind_Trace, &arg);
47+
CHECK_GT(size, 0);
48+
// We need to pop a few frames so that pc is on top.
49+
uptr to_pop = LocatePcInTrace(pc);
50+
// trace_buffer[0] belongs to the current function so we always pop it,
51+
// unless there is only 1 frame in the stack trace (1 frame is always better
52+
// than 0!).
53+
PopStackFrames(Min(to_pop, static_cast<uptr>(1)));
54+
trace_buffer[0] = pc;
55+
}
56+
57+
void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
58+
CHECK(context);
59+
CHECK_GE(max_depth, 2);
60+
UNREACHABLE("signal context doesn't exist");
61+
}
62+
# endif // SANITIZER_CAN_SLOW_UNWIND
63+
64+
} // namespace __sanitizer
65+
66+
#endif // SANITIZER_FUCHSIA

compiler-rt/lib/xray/xray_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <utility>
2929

3030
#if SANITIZER_FUCHSIA
31-
#include "sanitizer_common/sanitizer_symbolizer_fuchsia.h"
31+
#include "sanitizer_common/sanitizer_symbolizer_markup_constants.h"
3232

3333
#include <inttypes.h>
3434
#include <zircon/process.h>

llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ source_set("sources") {
143143
"sanitizer_suppressions.h",
144144
"sanitizer_symbolizer.cpp",
145145
"sanitizer_symbolizer.h",
146-
"sanitizer_symbolizer_fuchsia.h",
146+
"sanitizer_symbolizer_markup_constants.h",
147147
"sanitizer_symbolizer_internal.h",
148148
"sanitizer_symbolizer_libbacktrace.cpp",
149149
"sanitizer_symbolizer_libbacktrace.h",

0 commit comments

Comments
 (0)