diff --git a/source/loader/layers/sanitizer/linux/symbolizer.cpp b/source/loader/layers/sanitizer/linux/symbolizer.cpp index 824cf712bb..ccc621ac4a 100644 --- a/source/loader/layers/sanitizer/linux/symbolizer.cpp +++ b/source/loader/layers/sanitizer/linux/symbolizer.cpp @@ -7,8 +7,10 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception * */ +#include "common.hpp" #include "llvm/DebugInfo/Symbolize/DIPrinter.h" #include "llvm/DebugInfo/Symbolize/Symbolize.h" +#include static llvm::symbolize::PrinterConfig GetPrinterConfig() { llvm::symbolize::PrinterConfig Config; @@ -20,6 +22,28 @@ static llvm::symbolize::PrinterConfig GetPrinterConfig() { return Config; } +static uintptr_t GetModuleBase(const char *ModuleName) { + uintptr_t Data = (uintptr_t)ModuleName; + int Result = dl_iterate_phdr( + [](struct dl_phdr_info *Info, size_t, void *Arg) { + uintptr_t *Data = (uintptr_t *)Arg; + const char *ModuleName = (const char *)(*Data); + if (strstr(Info->dlpi_name, ModuleName)) { + *Data = (uintptr_t)Info->dlpi_addr; + return 1; + } + return 0; + }, + (void *)&Data); + + // If dl_iterate_phdr return 0, it means the module is main executable, + // its base address should be 0. + if (!Result) { + return 0; + } + return Data; +} + extern "C" { void SymbolizeCode(const char *ModuleName, uint64_t ModuleOffset, @@ -38,8 +62,8 @@ void SymbolizeCode(const char *ModuleName, uint64_t ModuleOffset, llvm::symbolize::LLVMPrinter Printer(OS, EH, Config); auto ResOrErr = Symbolizer.symbolizeInlinedCode( - ModuleName, - {ModuleOffset, llvm::object::SectionedAddress::UndefSection}); + ModuleName, {ModuleOffset - GetModuleBase(ModuleName), + llvm::object::SectionedAddress::UndefSection}); if (!ResOrErr) { return; diff --git a/source/loader/layers/sanitizer/stacktrace.cpp b/source/loader/layers/sanitizer/stacktrace.cpp index 8adaa2cd34..ed7f01c9cf 100644 --- a/source/loader/layers/sanitizer/stacktrace.cpp +++ b/source/loader/layers/sanitizer/stacktrace.cpp @@ -11,6 +11,7 @@ */ #include "stacktrace.hpp" +#include "asan_interceptor.hpp" #include "ur_sanitizer_layer.hpp" extern "C" { @@ -92,9 +93,10 @@ void StackTrace::print() const { BacktraceInfo BI = BacktraceSymbols[i]; // Skip runtime modules - if (Contains(BI, "libsycl.so") || - Contains(BI, "libpi_unified_runtime.so") || - Contains(BI, "libur_loader.so")) { + if (!getContext()->interceptor->getOptions().Debug && + (Contains(BI, "libsycl.so") || Contains(BI, "libur_loader.so") || + Contains(BI, "libomptarget.rtl.unified_runtime.so") || + Contains(BI, "libomptarget.so"))) { continue; }