forked from OSchip/llvm-project
tsan: use sanitizer::CommonFlags in tsan
llvm-svn: 192692
This commit is contained in:
parent
7a2bbc30a2
commit
7ac0b2b0e1
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue