[compiler-rt] r192692 - tsan: use sanitizer::CommonFlags in tsan

Alexey Samsonov samsonov at google.com
Tue Oct 15 06:46:40 PDT 2013


On Tue, Oct 15, 2013 at 4:25 PM, Dmitry Vyukov <dvyukov at google.com> wrote:

> Author: dvyukov
> Date: Tue Oct 15 07:25:29 2013
> New Revision: 192692
>
> URL: http://llvm.org/viewvc/llvm-project?rev=192692&view=rev
> Log:
> tsan: use sanitizer::CommonFlags in tsan
>
>
> Modified:
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
>     compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
>     compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
>     compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
>     compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=192692&r1=192691&r2=192692&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Tue Oct 15
> 07:25:29 2013
> @@ -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 c
>             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) {
>

This is an interface function. If it has no users in the outer world (I
think we're unaware of them),
then it should be also deleted from
include/sanitizer/common_interface_defs.h


>    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) {
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=192692&r1=192691&r2=192692&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Tue Oct 15
> 07:25:29 2013
> @@ -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");
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h?rev=192692&r1=192691&r2=192692&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h Tue Oct 15
> 07:25:29 2013
> @@ -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);
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=192692&r1=192691&r2=192692&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
> (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Tue
> Oct 15 07:25:29 2013
> @@ -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.
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc?rev=192692&r1=192691&r2=192692&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Tue Oct 15 07:25:29 2013
> @@ -47,13 +47,11 @@ void InitializeFlags(Flags *f, const cha
>    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 cha
>    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 cha
>    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 cha
>    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 cha
>      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
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h?rev=192692&r1=192691&r2=192692&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h Tue Oct 15 07:25:29 2013
> @@ -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();
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=192692&r1=192691&r2=192692&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Tue Oct 15 07:25:29 2013
> @@ -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();
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc?rev=192692&r1=192691&r2=192692&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc
> (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc Tue
> Oct 15 07:25:29 2013
> @@ -60,7 +60,6 @@ static void NOINLINE InitModule(ModuleDe
>    }
>    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);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



-- 
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131015/2a610959/attachment.html>


More information about the llvm-commits mailing list