diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2013-10-15 12:25:29 +0000 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2013-10-15 12:25:29 +0000 |
| commit | 7ac0b2b0e1f683e11b074d61c8a915560ab74588 (patch) | |
| tree | bec306b1273cf11b7270f3d63f5f607a811b38bc | |
| parent | 7a2bbc30a2a397134ac22262e5bcaf0afc8ce98d (diff) | |
| download | bcm5719-llvm-7ac0b2b0e1f683e11b074d61c8a915560ab74588.tar.gz bcm5719-llvm-7ac0b2b0e1f683e11b074d61c8a915560ab74588.zip | |
tsan: use sanitizer::CommonFlags in tsan
llvm-svn: 192692
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common.cc | 22 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_flags.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_flags.h | 9 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h | 6 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_flags.cc | 17 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_flags.h | 14 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 7 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc | 1 |
8 files changed, 30 insertions, 48 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 4cf694aacfc..76f90712c76 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -202,7 +202,8 @@ using namespace __sanitizer; // NOLINT extern "C" { void __sanitizer_set_report_path(const char *path) { - if (!path) return; + if (!path) + return; uptr len = internal_strlen(path); if (len > sizeof(report_path_prefix) - 100) { Report("ERROR: Path is too long: %c%c%c%c%c%c%c%c...\n", @@ -210,18 +211,21 @@ void __sanitizer_set_report_path(const char *path) { path[4], path[5], path[6], path[7]); Die(); } - internal_strncpy(report_path_prefix, path, sizeof(report_path_prefix)); - report_path_prefix[len] = '\0'; - report_fd = kInvalidFd; - log_to_file = true; -} - -void __sanitizer_set_report_fd(int fd) { if (report_fd != kStdoutFd && report_fd != kStderrFd && report_fd != kInvalidFd) internal_close(report_fd); - report_fd = fd; + report_fd = kInvalidFd; + log_to_file = false; + if (internal_strcmp(path, "stdout") == 0) { + report_fd = kStdoutFd; + } else if (internal_strcmp(path, "stderr") == 0) { + report_fd = kStderrFd; + } else { + internal_strncpy(report_path_prefix, path, sizeof(report_path_prefix)); + report_path_prefix[len] = '\0'; + log_to_file = true; + } } void NOINLINE __sanitizer_sandbox_on_notify(void *reserved) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc index 036f97b9d51..4c9f4e7e05c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc @@ -18,8 +18,6 @@ namespace __sanitizer { -CommonFlags common_flags_dont_use_directly; - void ParseCommonFlagsFromString(const char *str) { CommonFlags *f = common_flags(); ParseFlag(str, &f->malloc_context_size, "malloc_context_size"); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.h b/compiler-rt/lib/sanitizer_common/sanitizer_flags.h index 43632e65c5f..7740b240f04 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.h @@ -37,7 +37,9 @@ struct CommonFlags { bool handle_ioctl; // Max number of stack frames kept for each allocation/deallocation. int malloc_context_size; - // Write logs to "log_path.pid" instead of stderr. + // Write logs to "log_path.pid". + // The special values are "stdout" and "stderr". + // The default is "stderr". const char *log_path; // Enable memory leak detection. bool detect_leaks; @@ -49,10 +51,9 @@ struct CommonFlags { bool allocator_may_return_null; }; -extern CommonFlags common_flags_dont_use_directly; - inline CommonFlags *common_flags() { - return &common_flags_dont_use_directly; + static CommonFlags f; + return &f; } void ParseCommonFlagsFromString(const char *str); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h index 77bc967c563..1087f8190e4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h @@ -83,14 +83,10 @@ typedef u64 OFF64_T; extern "C" { // Tell the tools to write their reports to "path.<pid>" instead of stderr. + // The special values are "stdout" and "stderr". SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_set_report_path(const char *path); - // Tell the tools to write their reports to given file descriptor instead of - // stderr. - SANITIZER_INTERFACE_ATTRIBUTE - void __sanitizer_set_report_fd(int fd); - // Notify the tools that the sandbox is going to be turned on. The reserved // parameter will be used in the future to hold a structure with functions // that the tools may call to bypass the sandbox. diff --git a/compiler-rt/lib/tsan/rtl/tsan_flags.cc b/compiler-rt/lib/tsan/rtl/tsan_flags.cc index b864f929eaf..679ea992936 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_flags.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_flags.cc @@ -47,13 +47,11 @@ void InitializeFlags(Flags *f, const char *env) { f->report_signal_unsafe = true; f->report_atomic_races = true; f->force_seq_cst_atomics = false; - f->strip_path_prefix = ""; f->suppressions = ""; f->print_suppressions = false; f->print_benign = false; f->exitcode = 66; f->halt_on_error = false; - f->log_path = "stderr"; f->atexit_sleep_ms = 1000; f->verbosity = 0; f->profile_memory = ""; @@ -62,10 +60,8 @@ void InitializeFlags(Flags *f, const char *env) { f->memory_limit_mb = 0; f->stop_on_start = false; f->running_on_valgrind = false; - f->external_symbolizer_path = ""; f->history_size = kGoMode ? 1 : 2; // There are a lot of goroutines in Go. f->io_sync = 1; - f->allocator_may_return_null = false; // Let a frontend override. OverrideFlags(f); @@ -81,13 +77,11 @@ void InitializeFlags(Flags *f, const char *env) { ParseFlag(env, &f->report_signal_unsafe, "report_signal_unsafe"); ParseFlag(env, &f->report_atomic_races, "report_atomic_races"); ParseFlag(env, &f->force_seq_cst_atomics, "force_seq_cst_atomics"); - ParseFlag(env, &f->strip_path_prefix, "strip_path_prefix"); ParseFlag(env, &f->suppressions, "suppressions"); ParseFlag(env, &f->print_suppressions, "print_suppressions"); ParseFlag(env, &f->print_benign, "print_benign"); ParseFlag(env, &f->exitcode, "exitcode"); ParseFlag(env, &f->halt_on_error, "halt_on_error"); - ParseFlag(env, &f->log_path, "log_path"); ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms"); ParseFlag(env, &f->verbosity, "verbosity"); ParseFlag(env, &f->profile_memory, "profile_memory"); @@ -95,10 +89,8 @@ void InitializeFlags(Flags *f, const char *env) { ParseFlag(env, &f->flush_symbolizer_ms, "flush_symbolizer_ms"); ParseFlag(env, &f->memory_limit_mb, "memory_limit_mb"); ParseFlag(env, &f->stop_on_start, "stop_on_start"); - ParseFlag(env, &f->external_symbolizer_path, "external_symbolizer_path"); ParseFlag(env, &f->history_size, "history_size"); ParseFlag(env, &f->io_sync, "io_sync"); - ParseFlag(env, &f->allocator_may_return_null, "allocator_may_return_null"); if (!f->report_bugs) { f->report_thread_leaks = false; @@ -118,8 +110,13 @@ void InitializeFlags(Flags *f, const char *env) { Die(); } - common_flags()->allocator_may_return_null = f->allocator_may_return_null; - common_flags()->strip_path_prefix = f->strip_path_prefix; + *common_flags() = *f; + ParseCommonFlagsFromString("strip_path_prefix="); + ParseCommonFlagsFromString("log_path=stderr"); + ParseCommonFlagsFromString("external_symbolizer_path="); + ParseCommonFlagsFromString("allocator_may_return_null=0"); + ParseCommonFlagsFromString(env); + *static_cast<CommonFlags*>(f) = *common_flags(); } } // namespace __tsan diff --git a/compiler-rt/lib/tsan/rtl/tsan_flags.h b/compiler-rt/lib/tsan/rtl/tsan_flags.h index 86e1a2cb063..b240fdce4a2 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_flags.h +++ b/compiler-rt/lib/tsan/rtl/tsan_flags.h @@ -20,9 +20,11 @@ // header may be included in the user code, and shouldn't include // other headers from TSan or common sanitizer runtime. +#include "sanitizer_common/sanitizer_flags.h" + namespace __tsan { -struct Flags { +struct Flags : CommonFlags { // Enable dynamic annotations, otherwise they are no-ops. bool enable_annotations; // Supress a race report if we've already output another race report @@ -48,8 +50,6 @@ struct Flags { // If set, all atomics are effectively sequentially consistent (seq_cst), // regardless of what user actually specified. bool force_seq_cst_atomics; - // Strip that prefix from file paths in reports. - const char *strip_path_prefix; // Suppressions filename. const char *suppressions; // Print matched suppressions at exit. @@ -60,10 +60,6 @@ struct Flags { int exitcode; // Exit after first reported error. bool halt_on_error; - // Write logs to "log_path.pid". - // The special values are "stdout" and "stderr". - // The default is "stderr". - const char *log_path; // Sleep in main thread before exiting for that many ms // (useful to catch "at exit" races). int atexit_sleep_ms; @@ -82,8 +78,6 @@ struct Flags { bool stop_on_start; // Controls whether RunningOnValgrind() returns true or false. bool running_on_valgrind; - // Path to external symbolizer. - const char *external_symbolizer_path; // Per-thread history size, controls how many previous memory accesses // are remembered per thread. Possible values are [0..7]. // history_size=0 amounts to 32K memory accesses. Each next value doubles @@ -95,8 +89,6 @@ struct Flags { // 1 - reasonable level of synchronization (write->read) // 2 - global synchronization of all IO operations int io_sync; - // If false, the allocator will crash instead of returning 0 on out-of-memory. - bool allocator_may_return_null; }; Flags *flags(); diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index 1ce991729f6..dcaf071460d 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -231,12 +231,7 @@ void Initialize(ThreadState *thr) { #endif InitializeFlags(&ctx->flags, env); // Setup correct file descriptor for error reports. - if (internal_strcmp(flags()->log_path, "stdout") == 0) - __sanitizer_set_report_fd(kStdoutFd); - else if (internal_strcmp(flags()->log_path, "stderr") == 0) - __sanitizer_set_report_fd(kStderrFd); - else - __sanitizer_set_report_path(flags()->log_path); + __sanitizer_set_report_path(flags()->log_path); InitializeSuppressions(); #ifndef TSAN_GO InitializeLibIgnore(); diff --git a/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc index 47f9e1fbf41..b186d3b38ec 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc @@ -60,7 +60,6 @@ static void NOINLINE InitModule(ModuleDesc *m) { } int pid = fork(); if (pid == 0) { - __sanitizer_set_report_fd(STDERR_FILENO); internal_close(STDOUT_FILENO); internal_close(STDIN_FILENO); internal_dup2(outfd[0], STDIN_FILENO); |

