Index: lib/asan/asan_suppressions.cc =================================================================== --- lib/asan/asan_suppressions.cc +++ lib/asan/asan_suppressions.cc @@ -82,9 +82,10 @@ if (suppression_ctx->HasSuppressionType(kInterceptorViaLibrary)) { // Match "interceptor_via_lib" suppressions. - if (const char *module_name = symbolizer->GetModuleNameForPc(addr)) - if (suppression_ctx->Match(module_name, kInterceptorViaLibrary, &s)) - return true; + InternalScopedString mod_name(kMaxPathLength); + if (symbolizer->GetModuleNameForPc(addr, mod_name.data()) && + suppression_ctx->Match(mod_name.data(), kInterceptorViaLibrary, &s)) + return true; } if (suppression_ctx->HasSuppressionType(kInterceptorViaFunction)) { Index: lib/lsan/lsan_common.cc =================================================================== --- lib/lsan/lsan_common.cc +++ lib/lsan/lsan_common.cc @@ -436,10 +436,10 @@ // Suppress by module name. SuppressionContext *suppressions = GetSuppressionContext(); - if (const char *module_name = - Symbolizer::GetOrInit()->GetModuleNameForPc(addr)) - if (suppressions->Match(module_name, kSuppressionLeak, &s)) - return s; + InternalScopedString module_name(kMaxPathLength); + if (Symbolizer::GetOrInit()->GetModuleNameForPc(addr, module_name.data()) && + suppressions->Match(module_name.data(), kSuppressionLeak, &s)) + return s; // Suppress by file or function name. SymbolizedStack *frames = Symbolizer::GetOrInit()->SymbolizePC(addr); Index: lib/sanitizer_common/sanitizer_coverage_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_coverage_libcdep.cc +++ lib/sanitizer_common/sanitizer_coverage_libcdep.cc @@ -335,12 +335,14 @@ auto sym = Symbolizer::GetOrInit(); if (!sym) return; - const char *module_name = sym->GetModuleNameForPc(caller_pc); - if (!module_name) return; + InternalScopedString module_name(kMaxPathLength); + if (!sym->GetModuleNameForPc(caller_pc, module_name.data())) + return; if (module_name_vec.empty() || - internal_strcmp(module_name_vec.back().copied_module_name, module_name)) - module_name_vec.push_back( - {internal_strdup(module_name), range_beg, range_end}); + internal_strcmp(module_name_vec.back().copied_module_name, + module_name.data())) + module_name_vec.push_back( + { internal_strdup(module_name.data()), range_beg, range_end }); else module_name_vec.back().end = range_end; } @@ -587,12 +589,14 @@ if (!sym) return; InternalScopedString out(32 << 20); + InternalScopedString module_name(kMaxPathLength); for (uptr i = 0, n = size(); i < n; i++) { - const char *module_name = ""; - uptr module_address = 0; - sym->GetModuleNameAndOffsetForPC(UnbundlePc(pc_array[i]), &module_name, - &module_address); - out.append("%s 0x%zx\n", module_name, module_address); + module_name.clear(); + module_name.append(""); + uptr offset = 0; + sym->GetModuleNameAndOffsetForPC(UnbundlePc(pc_array[i]), + module_name.data(), &offset); + out.append("%s 0x%zx\n", module_name.data(), offset); } InternalScopedString path(kMaxPathLength); int fd = CovOpenFile(&path, false, "trace-points"); @@ -637,26 +641,30 @@ return; InternalScopedString out(32 << 20); uptr total = 0; + InternalScopedString caller_module_name(kMaxPathLength), + callee_module_name(kMaxPathLength); for (uptr i = 0; i < max_idx; i++) { uptr *cc_cache = cc_array[i]; CHECK(cc_cache); uptr caller = cc_cache[0]; uptr n_callees = cc_cache[1]; - const char *caller_module_name = ""; - uptr caller_module_address = 0; - sym->GetModuleNameAndOffsetForPC(caller, &caller_module_name, - &caller_module_address); + caller_module_name.clear(); + caller_module_name.append(""); + uptr caller_module_offset = 0; + sym->GetModuleNameAndOffsetForPC(caller, caller_module_name.data(), + &caller_module_offset); for (uptr j = 2; j < n_callees; j++) { uptr callee = cc_cache[j]; if (!callee) break; total++; - const char *callee_module_name = ""; - uptr callee_module_address = 0; - sym->GetModuleNameAndOffsetForPC(callee, &callee_module_name, - &callee_module_address); - out.append("%s 0x%zx\n%s 0x%zx\n", caller_module_name, - caller_module_address, callee_module_name, - callee_module_address); + callee_module_name.clear(); + callee_module_name.append(""); + uptr callee_module_offset = 0; + sym->GetModuleNameAndOffsetForPC(callee, callee_module_name.data(), + &callee_module_offset); + out.append("%s 0x%zx\n%s 0x%zx\n", caller_module_name.data(), + caller_module_offset, callee_module_name.data(), + callee_module_offset); } } InternalScopedString path(kMaxPathLength); @@ -751,9 +759,8 @@ uptr pc = UnbundlePc(pc_array[i]); uptr counter = UnbundleCounter(pc_array[i]); if (!pc) continue; // Not visited. - const char *unused; uptr offset = 0; - sym->GetModuleNameAndOffsetForPC(pc, &unused, &offset); + sym->GetModuleOffsetForPc(pc, &offset); offsets.push_back(BundlePcAndCounter(offset, counter)); } Index: lib/sanitizer_common/sanitizer_symbolizer.h =================================================================== --- lib/sanitizer_common/sanitizer_symbolizer.h +++ lib/sanitizer_common/sanitizer_symbolizer.h @@ -84,15 +84,16 @@ // all inlined functions, if necessary). SymbolizedStack *SymbolizePC(uptr address); bool SymbolizeData(uptr address, DataInfo *info); - bool GetModuleNameAndOffsetForPC(uptr pc, const char **module_name, - uptr *module_address); - const char *GetModuleNameForPc(uptr pc) { - const char *module_name = 0; - uptr unused; - if (GetModuleNameAndOffsetForPC(pc, &module_name, &unused)) - return module_name; - return nullptr; + + // |name| should contain at least kMaxPathLength bytes. + bool GetModuleNameAndOffsetForPC(uptr pc, char *name, uptr *offset); + bool GetModuleNameForPc(uptr pc, char *name) { + return GetModuleNameAndOffsetForPC(pc, name, nullptr); + } + bool GetModuleOffsetForPc(uptr pc, uptr *offset) { + return GetModuleNameAndOffsetForPC(pc, nullptr, offset); } + // Release internal caches (if any). void Flush(); // Attempts to demangle the provided C++ mangled name. Index: lib/sanitizer_common/sanitizer_symbolizer.cc =================================================================== --- lib/sanitizer_common/sanitizer_symbolizer.cc +++ lib/sanitizer_common/sanitizer_symbolizer.cc @@ -129,11 +129,17 @@ return true; } -bool Symbolizer::GetModuleNameAndOffsetForPC(uptr pc, const char **module_name, - uptr *module_address) { +bool Symbolizer::GetModuleNameAndOffsetForPC(uptr pc, char *name, + uptr *offset) { BlockingMutexLock l(&mu_); - return PlatformFindModuleNameAndOffsetForAddress(pc, module_name, - module_address); + const char *internal_name; + bool ret = PlatformFindModuleNameAndOffsetForAddress(pc, &internal_name, + offset); + if (ret && name) { + internal_strncpy(name, internal_name, kMaxPathLength - 1); + name[kMaxPathLength - 1] = '\0'; + } + return ret; } void Symbolizer::Flush() { Index: lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc +++ lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc @@ -400,8 +400,10 @@ LoadedModule *module = FindModuleForAddress(address); if (module == 0) return false; - *module_name = module->full_name(); - *module_offset = address - module->base_address(); + if (module_name) + *module_name = module->full_name(); + if (module_offset) + *module_offset = address - module->base_address(); return true; }