Skip to content

Commit 1711bf6

Browse files
delcypherdanliew-apple
authored andcommitted
[NFC] Introduce a LateInitialize() method to SymbolizerTool that is called during the LateInitialize stage of the sanitizer runtimes.
Summary: This is implemented by adding a `Symbolizer::LateInitializeTools()` method that iterates over the registered tools and calls the `LateInitialize()` method on them. `Symbolizer::LateInitializeTools()` is now called from the various `Symbolizer::LateInitialize()` implementations. The default implementation of `SymbolizerTool::LateInitialize()` does nothing so this change should be NFC. This change allows `SymbolizerTool` implementations to perform any initialization that they need to perform at the LateInitialize stage of a sanitizer runtime init. rdar://problem/58789439 Reviewers: kubamracek, yln, vitalybuka, cryptoad, phosek, rnk Subscribers: #sanitizers, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D78178 (cherry picked from commit fccea7f)
1 parent f1a1c4b commit 1711bf6

File tree

6 files changed

+19
-3
lines changed

6 files changed

+19
-3
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,10 @@ Symbolizer::SymbolizerScope::~SymbolizerScope() {
126126
sym_->end_hook_();
127127
}
128128

129+
void Symbolizer::LateInitializeTools() {
130+
for (auto &tool : tools_) {
131+
tool.LateInitialize();
132+
}
133+
}
134+
129135
} // namespace __sanitizer

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ class Symbolizer final {
209209
private:
210210
const Symbolizer *sym_;
211211
};
212+
213+
// Calls `LateInitialize()` on all items in `tools_`.
214+
void LateInitializeTools();
212215
};
213216

214217
#ifdef SANITIZER_WINDOWS

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class SymbolizerTool {
6969
virtual const char *Demangle(const char *name) {
7070
return nullptr;
7171
}
72+
73+
// Called during the LateInitialize phase of Sanitizer initialization.
74+
// Usually this is a safe place to call code that might need to use user
75+
// memory allocators.
76+
virtual void LateInitialize() {}
7277
};
7378

7479
// SymbolizerProcess encapsulates communication between the tool and

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ Symbolizer *Symbolizer::PlatformInit() {
9494
return new (symbolizer_allocator_) Symbolizer({});
9595
}
9696

97-
void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
97+
void Symbolizer::LateInitialize() {
98+
Symbolizer::GetOrInit()->LateInitializeTools();
99+
}
98100

99101
void StartReportDeadlySignal() {}
100102
void ReportDeadlySignal(const SignalContext &sig, u32 tid,

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ Symbolizer *Symbolizer::PlatformInit() {
488488
}
489489

490490
void Symbolizer::LateInitialize() {
491-
Symbolizer::GetOrInit();
491+
Symbolizer::GetOrInit()->LateInitializeTools();
492492
InitializeSwiftDemangler();
493493
}
494494

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ Symbolizer *Symbolizer::PlatformInit() {
310310
}
311311

312312
void Symbolizer::LateInitialize() {
313-
Symbolizer::GetOrInit();
313+
Symbolizer::GetOrInit()->LateInitializeTools();
314314
}
315315

316316
} // namespace __sanitizer

0 commit comments

Comments
 (0)