Index: projects/compiler-rt/lib/sanitizer_common/sanitizer_file.cc =================================================================== --- projects/compiler-rt/lib/sanitizer_common/sanitizer_file.cc +++ projects/compiler-rt/lib/sanitizer_common/sanitizer_file.cc @@ -59,6 +59,9 @@ } else { internal_snprintf(full_path, kMaxPathLength, "%s.%zu", path_prefix, pid); } + if (common_flags()->log_suffix) { + internal_strlcat(full_path, common_flags()->log_suffix, kMaxPathLength); + } fd = OpenFile(full_path, WrOnly); if (fd == kInvalidFd) { const char *ErrorMsgPrefix = "ERROR: Can't open file: "; Index: projects/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc =================================================================== --- projects/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc +++ projects/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc @@ -56,6 +56,9 @@ "Mention name of executable when reporting error and " "append executable name to logs (as in \"log_path.exe_name.pid\").") COMMON_FLAG( + const char *, log_suffix, nullptr, + "String to append to log file name, e.g. \".txt\".") +COMMON_FLAG( bool, log_to_syslog, SANITIZER_ANDROID || SANITIZER_MAC, "Write all sanitizer output to syslog in addition to other means of " "logging.") Index: projects/compiler-rt/test/asan/TestCases/suffix-log-path_test.cc =================================================================== --- projects/compiler-rt/test/asan/TestCases/suffix-log-path_test.cc +++ projects/compiler-rt/test/asan/TestCases/suffix-log-path_test.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx_asan %s -o %T/suffix-log-path_test-binary + +// The glob below requires bash. +// REQUIRES: shell + +// Good log_path with suffix. +// RUN: rm -f %T/asan.log.*.txt +// RUN: %env_asan_opts=log_path=%T/asan.log:log_exe_name=1:log_suffix=.txt not %run %T/suffix-log-path_test-binary 2> %t.out +// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %T/asan.log.suffix-log-path_test-binary.*.txt + +// FIXME: only FreeBSD, NetBSD and Linux have verbose log paths now. +// XFAIL: win32,android +// UNSUPPORTED: ios + +#include +#include +int main(int argc, char **argv) { + if (argc > 2) return 0; + char *x = (char*)malloc(10); + memset(x, 0, 10); + int res = x[argc * 10]; // BOOOM + free(x); + return res; +} +// CHECK-ERROR: ERROR: AddressSanitizer +