2019-08-14 10:47:11 +02:00
|
|
|
//===-- tsan_flags.cpp ----------------------------------------------------===//
|
2012-11-22 23:03:11 +01:00
|
|
|
//
|
2019-08-14 10:47:11 +02:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-11-22 23:03:11 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "sanitizer_common/sanitizer_flag_parser.h"
|
2012-11-22 23:03:11 +01:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
|
|
|
#include "tsan_flags.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_mman.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "ubsan/ubsan_flags.h"
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
|
|
|
// Can be overriden in frontend.
|
|
|
|
#ifdef TSAN_EXTERNAL_HOOKS
|
2013-12-05 10:18:38 +01:00
|
|
|
extern "C" const char* __tsan_default_options();
|
2012-11-22 23:03:11 +01:00
|
|
|
#else
|
2016-11-08 23:04:09 +01:00
|
|
|
SANITIZER_WEAK_DEFAULT_IMPL
|
|
|
|
const char *__tsan_default_options() {
|
2013-12-05 10:18:38 +01:00
|
|
|
return "";
|
|
|
|
}
|
2012-11-22 23:03:11 +01:00
|
|
|
#endif
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
void Flags::SetDefaults() {
|
|
|
|
#define TSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
|
|
|
|
#include "tsan_flags.inc"
|
|
|
|
#undef TSAN_FLAG
|
|
|
|
// DDFlags
|
|
|
|
second_deadlock_stack = false;
|
|
|
|
}
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
void RegisterTsanFlags(FlagParser *parser, Flags *f) {
|
|
|
|
#define TSAN_FLAG(Type, Name, DefaultValue, Description) \
|
|
|
|
RegisterFlag(parser, #Name, Description, &f->Name);
|
|
|
|
#include "tsan_flags.inc"
|
|
|
|
#undef TSAN_FLAG
|
2014-05-22 09:09:21 +02:00
|
|
|
// DDFlags
|
2015-10-21 09:32:45 +02:00
|
|
|
RegisterFlag(parser, "second_deadlock_stack",
|
|
|
|
"Report where each mutex is locked in deadlock reports",
|
|
|
|
&f->second_deadlock_stack);
|
2013-12-05 10:18:38 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
void InitializeFlags(Flags *f, const char *env, const char *env_option_name) {
|
2015-10-21 09:32:45 +02:00
|
|
|
SetCommonFlagsDefaults();
|
|
|
|
{
|
|
|
|
// Override some common flags defaults.
|
|
|
|
CommonFlags cf;
|
|
|
|
cf.CopyFrom(*common_flags());
|
|
|
|
cf.allow_addr2line = true;
|
2016-11-08 23:04:09 +01:00
|
|
|
if (SANITIZER_GO) {
|
2015-11-23 10:07:18 +01:00
|
|
|
// Does not work as expected for Go: runtime handles SIGABRT and crashes.
|
|
|
|
cf.abort_on_error = false;
|
|
|
|
// Go does not have mutexes.
|
2019-08-14 10:47:11 +02:00
|
|
|
cf.detect_deadlocks = false;
|
2015-11-23 10:07:18 +01:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
cf.print_suppressions = false;
|
|
|
|
cf.stack_trace_format = " #%n %f %S %M";
|
|
|
|
cf.exitcode = 66;
|
2016-11-08 23:04:09 +01:00
|
|
|
cf.intercept_tls_get_addr = true;
|
2015-10-21 09:32:45 +02:00
|
|
|
OverrideCommonFlags(cf);
|
|
|
|
}
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
f->SetDefaults();
|
|
|
|
|
|
|
|
FlagParser parser;
|
|
|
|
RegisterTsanFlags(&parser, f);
|
|
|
|
RegisterCommonFlags(&parser);
|
2013-12-05 10:18:38 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#if TSAN_CONTAINS_UBSAN
|
|
|
|
__ubsan::Flags *uf = __ubsan::flags();
|
|
|
|
uf->SetDefaults();
|
|
|
|
|
|
|
|
FlagParser ubsan_parser;
|
|
|
|
__ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
|
|
|
|
RegisterCommonFlags(&ubsan_parser);
|
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
// Let a frontend override.
|
2015-10-21 09:32:45 +02:00
|
|
|
parser.ParseString(__tsan_default_options());
|
|
|
|
#if TSAN_CONTAINS_UBSAN
|
2020-10-16 10:03:04 +02:00
|
|
|
const char *ubsan_default_options = __ubsan_default_options();
|
2015-10-21 09:32:45 +02:00
|
|
|
ubsan_parser.ParseString(ubsan_default_options);
|
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
// Override from command line.
|
2019-08-14 10:47:11 +02:00
|
|
|
parser.ParseString(env, env_option_name);
|
2015-10-21 09:32:45 +02:00
|
|
|
#if TSAN_CONTAINS_UBSAN
|
2019-08-14 10:47:11 +02:00
|
|
|
ubsan_parser.ParseStringFromEnv("UBSAN_OPTIONS");
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif
|
2012-11-23 15:46:25 +01:00
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
// Sanity check.
|
2012-11-23 15:46:25 +01:00
|
|
|
if (!f->report_bugs) {
|
|
|
|
f->report_thread_leaks = false;
|
|
|
|
f->report_destroy_locked = false;
|
|
|
|
f->report_signal_unsafe = false;
|
|
|
|
}
|
2012-12-05 14:19:55 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
InitializeCommonFlags();
|
2015-10-21 09:32:45 +02:00
|
|
|
|
|
|
|
if (Verbosity()) ReportUnrecognizedFlags();
|
|
|
|
|
|
|
|
if (common_flags()->help) parser.PrintFlagDescriptions();
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2012-12-05 14:19:55 +01:00
|
|
|
if (f->history_size < 0 || f->history_size > 7) {
|
|
|
|
Printf("ThreadSanitizer: incorrect value for history_size"
|
|
|
|
" (must be [0..7])\n");
|
|
|
|
Die();
|
|
|
|
}
|
2013-01-10 13:44:08 +01:00
|
|
|
|
|
|
|
if (f->io_sync < 0 || f->io_sync > 2) {
|
|
|
|
Printf("ThreadSanitizer: incorrect value for io_sync"
|
|
|
|
" (must be [0..2])\n");
|
|
|
|
Die();
|
|
|
|
}
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __tsan
|