Skip to content

Commit

Permalink
[NFC] Introduce a LateInitialize() method to SymbolizerTool that …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
delcypher committed Apr 17, 2020
1 parent 3eaeebe commit fccea7f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ Symbolizer::SymbolizerScope::~SymbolizerScope() {
sym_->end_hook_();
}

void Symbolizer::LateInitializeTools() {
for (auto &tool : tools_) {
tool.LateInitialize();
}
}

} // namespace __sanitizer
3 changes: 3 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ class Symbolizer final {
private:
const Symbolizer *sym_;
};

// Calls `LateInitialize()` on all items in `tools_`.
void LateInitializeTools();
};

#ifdef SANITIZER_WINDOWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class SymbolizerTool {
virtual const char *Demangle(const char *name) {
return nullptr;
}

// Called during the LateInitialize phase of Sanitizer initialization.
// Usually this is a safe place to call code that might need to use user
// memory allocators.
virtual void LateInitialize() {}
};

// SymbolizerProcess encapsulates communication between the tool and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ Symbolizer *Symbolizer::PlatformInit() {
return new (symbolizer_allocator_) Symbolizer({});
}

void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
void Symbolizer::LateInitialize() {
Symbolizer::GetOrInit()->LateInitializeTools();
}

void StartReportDeadlySignal() {}
void ReportDeadlySignal(const SignalContext &sig, u32 tid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ Symbolizer *Symbolizer::PlatformInit() {
}

void Symbolizer::LateInitialize() {
Symbolizer::GetOrInit();
Symbolizer::GetOrInit()->LateInitializeTools();
InitializeSwiftDemangler();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Symbolizer *Symbolizer::PlatformInit() {
}

void Symbolizer::LateInitialize() {
Symbolizer::GetOrInit();
Symbolizer::GetOrInit()->LateInitializeTools();
}

} // namespace __sanitizer
Expand Down

0 comments on commit fccea7f

Please sign in to comment.