Skip to content

Commit

Permalink
Merge pull request #2237 from yingcong-wu/yc/1024-devasan-bug-symboli…
Browse files Browse the repository at this point in the history
…zer-destruct-too-early

[DeviceAsan] Symbolizer may destruct before SanitizerInterceptor
  • Loading branch information
pbalcer authored Oct 25, 2024
2 parents 1487f4b + 5a78565 commit ab0a706
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions source/loader/layers/sanitizer/linux/symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@
#include "llvm/DebugInfo/Symbolize/DIPrinter.h"
#include "llvm/DebugInfo/Symbolize/Symbolize.h"

namespace ur_sanitizer_layer {

llvm::symbolize::LLVMSymbolizer *GetSymbolizer() {
static llvm::symbolize::LLVMSymbolizer Symbolizer;
return &Symbolizer;
}

llvm::symbolize::PrinterConfig GetPrinterConfig() {
static llvm::symbolize::PrinterConfig GetPrinterConfig() {
llvm::symbolize::PrinterConfig Config;
Config.Pretty = false;
Config.PrintAddress = false;
Expand All @@ -27,35 +20,32 @@ llvm::symbolize::PrinterConfig GetPrinterConfig() {
return Config;
}

} // namespace ur_sanitizer_layer

extern "C" {

void SymbolizeCode(const char *ModuleName, uint64_t ModuleOffset,
char *ResultString, size_t ResultSize, size_t *RetSize) {
std::string Result;
llvm::raw_string_ostream OS(Result);
llvm::symbolize::Request Request{ModuleName, ModuleOffset};
llvm::symbolize::PrinterConfig Config =
ur_sanitizer_layer::GetPrinterConfig();
llvm::symbolize::PrinterConfig Config = GetPrinterConfig();
llvm::symbolize::ErrorHandler EH = [&](const llvm::ErrorInfoBase &ErrorInfo,
llvm::StringRef ErrorBanner) {
OS << ErrorBanner;
ErrorInfo.log(OS);
OS << '\n';
};
auto Printer =
std::make_unique<llvm::symbolize::LLVMPrinter>(OS, EH, Config);
llvm::symbolize::LLVMSymbolizer Symbolizer;
llvm::symbolize::LLVMPrinter Printer(OS, EH, Config);

auto ResOrErr = ur_sanitizer_layer::GetSymbolizer()->symbolizeInlinedCode(
auto ResOrErr = Symbolizer.symbolizeInlinedCode(
ModuleName,
{ModuleOffset, llvm::object::SectionedAddress::UndefSection});

if (!ResOrErr) {
return;
}
Printer->print(Request, *ResOrErr);
ur_sanitizer_layer::GetSymbolizer()->pruneCache();
Printer.print(Request, *ResOrErr);
Symbolizer.pruneCache();
if (RetSize) {
*RetSize = Result.size() + 1;
}
Expand Down

0 comments on commit ab0a706

Please sign in to comment.