Index: lib/asan/asan_rtl.cc =================================================================== --- lib/asan/asan_rtl.cc +++ lib/asan/asan_rtl.cc @@ -563,6 +563,8 @@ const char *options = GetEnv("ASAN_OPTIONS"); InitializeFlags(flags(), options); + CacheBinaryName(); + InitializeHighMemEnd(); // Make sure we are not statically linked. Index: lib/sanitizer_common/sanitizer_common.h =================================================================== --- lib/sanitizer_common/sanitizer_common.h +++ lib/sanitizer_common/sanitizer_common.h @@ -178,6 +178,10 @@ const char *module, uptr offset); // OS +uptr ReadBinaryName(/*out*/char *buf, uptr buf_len); +const char *ReadBinaryNameCached(); +void CacheBinaryName(); +const char *BaseName(const char *name); void DisableCoreDumperIfNecessary(); void DumpProcessMap(); bool FileExists(const char *filename); Index: lib/sanitizer_common/sanitizer_common.cc =================================================================== --- lib/sanitizer_common/sanitizer_common.cc +++ lib/sanitizer_common/sanitizer_common.cc @@ -247,6 +247,36 @@ atomic_fetch_sub(&g_total_mmaped, size, memory_order_relaxed); } +static BlockingMutex proc_self_exe_cache_lock; +static char proc_self_exe_cache_str[kMaxPathLength]; +static bool proc_self_exe_cache_initialized = false; + +const char *ReadBinaryNameCached() { + if (proc_self_exe_cache_initialized) + return proc_self_exe_cache_str; + BlockingMutexLock l(&proc_self_exe_cache_lock); + if (!proc_self_exe_cache_initialized) { + ReadBinaryName(proc_self_exe_cache_str, sizeof(proc_self_exe_cache_str)); + atomic_signal_fence(memory_order_seq_cst); + atomic_thread_fence(memory_order_seq_cst); + proc_self_exe_cache_initialized = true; + } + return proc_self_exe_cache_str; +} + +void CacheBinaryName() { + // Call once to make sure that proc_self_exe_cache_str is initialized + ReadBinaryNameCached(); +} + +const char *BaseName(const char *name) { + const char *base1 = internal_strrchr(name, '/'), + *base2 = internal_strrchr(name, '\\'); + if (base1 || base2) + return (base1 > base2 ? base1 : base2) + 1; + return name; +} + } // namespace __sanitizer using namespace __sanitizer; // NOLINT Index: lib/sanitizer_common/sanitizer_flags.cc =================================================================== --- lib/sanitizer_common/sanitizer_flags.cc +++ lib/sanitizer_common/sanitizer_flags.cc @@ -92,8 +92,8 @@ ParseFlag(str, &f->malloc_context_size, "malloc_context_size", "Max number of stack frames kept for each allocation/deallocation."); ParseFlag(str, &f->log_path, "log_path", - "Write logs to \"log_path.pid\". The special values are \"stdout\" and " - "\"stderr\". The default is \"stderr\"."); + "Write logs to \"log_path.pname.pid\". The special values are \"stdout\" " + "and \"stderr\". The default is \"stderr\"."); ParseFlag(str, &f->verbosity, "verbosity", "Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output)."); ParseFlag(str, &f->detect_leaks, "detect_leaks", Index: lib/sanitizer_common/sanitizer_linux.h =================================================================== --- lib/sanitizer_common/sanitizer_linux.h +++ lib/sanitizer_common/sanitizer_linux.h @@ -80,11 +80,6 @@ // information). bool LibraryNameIs(const char *full_name, const char *base_name); -// Read the name of the current binary from /proc/self/exe. -uptr ReadBinaryName(/*out*/char *buf, uptr buf_len); -// Cache the value of /proc/self/exe. -void CacheBinaryName(); - // Call cb for each region mapped by map. void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr)); } // namespace __sanitizer Index: lib/sanitizer_common/sanitizer_linux.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux.cc +++ lib/sanitizer_common/sanitizer_linux.cc @@ -678,17 +678,7 @@ #endif } -static char proc_self_exe_cache_str[kMaxPathLength]; -static uptr proc_self_exe_cache_len = 0; - uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { - if (proc_self_exe_cache_len > 0) { - // If available, use the cached module name. - uptr module_name_len = - internal_snprintf(buf, buf_len, "%s", proc_self_exe_cache_str); - CHECK_LT(module_name_len, buf_len); - return module_name_len; - } #if SANITIZER_FREEBSD const int Mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; size_t Size = buf_len; @@ -712,13 +702,6 @@ return module_name_len; } -void CacheBinaryName() { - if (!proc_self_exe_cache_len) { - proc_self_exe_cache_len = - ReadBinaryName(proc_self_exe_cache_str, kMaxPathLength); - } -} - // Match full names of the form /path/to/base_name{-,.}* bool LibraryNameIs(const char *full_name, const char *base_name) { const char *name = full_name; Index: lib/sanitizer_common/sanitizer_mac.cc =================================================================== --- lib/sanitizer_common/sanitizer_mac.cc +++ lib/sanitizer_common/sanitizer_mac.cc @@ -316,6 +316,13 @@ return result; } +uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { + // FIXME: Actually implement this function. + CHECK_GT(buf_len, 0); + buf[0] = 0; + return 1; +} + } // namespace __sanitizer #endif // SANITIZER_MAC Index: lib/sanitizer_common/sanitizer_posix.cc =================================================================== --- lib/sanitizer_common/sanitizer_posix.cc +++ lib/sanitizer_common/sanitizer_posix.cc @@ -286,13 +286,14 @@ void MaybeOpenReportFile() { if (!log_to_file) return; uptr pid = internal_getpid(); + const char *pname = BaseName(ReadBinaryNameCached()); // If in tracer, use the parent's file. if (pid == stoptheworld_tracer_pid) pid = stoptheworld_tracer_ppid; if (report_fd_pid == pid) return; InternalScopedBuffer report_path_full(4096); internal_snprintf(report_path_full.data(), report_path_full.size(), - "%s.%zu", report_path_prefix, pid); + "%s.%s.%zu", report_path_prefix, pname, pid); uptr openrv = OpenFile(report_path_full.data(), true); if (internal_iserror(openrv)) { report_fd = kStderrFd; Index: lib/sanitizer_common/sanitizer_printf.cc =================================================================== --- lib/sanitizer_common/sanitizer_printf.cc +++ lib/sanitizer_common/sanitizer_printf.cc @@ -253,9 +253,11 @@ needed_length = 0; if (append_pid) { int pid = internal_getpid(); - needed_length += internal_snprintf(buffer, buffer_size, "==%d==", pid); + const char *pname = BaseName(ReadBinaryNameCached()); + needed_length += internal_snprintf(buffer, buffer_size, + "==%s %d==", pname, pid); if (needed_length >= buffer_size) { - // The pid doesn't fit into the current buffer. + // Process name + pid do not fit into the current buffer. if (!use_mmap) continue; RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n"); 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 @@ -637,11 +637,8 @@ } void PrepareForSandboxing() { -#if SANITIZER_LINUX && !SANITIZER_ANDROID BlockingMutexLock l(&mu_); - // Cache /proc/self/exe on Linux. CacheBinaryName(); -#endif } private: Index: lib/sanitizer_common/sanitizer_win.cc =================================================================== --- lib/sanitizer_common/sanitizer_win.cc +++ lib/sanitizer_common/sanitizer_win.cc @@ -527,6 +527,13 @@ return true; } +uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { + // FIXME: Actually implement this function. + CHECK_GT(buf_len, 0); + buf[0] = 0; + return 1; +} + } // namespace __sanitizer #endif // _WIN32