2012-06-04 21:55:19 +08:00
|
|
|
//===-- tsan_suppressions.cc ----------------------------------------------===//
|
2012-05-10 21:48:04 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-06-18 16:44:30 +08:00
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
2012-06-05 15:46:31 +08:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2013-06-26 23:37:14 +08:00
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
|
|
|
#include "sanitizer_common/sanitizer_suppressions.h"
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_suppressions.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_flags.h"
|
|
|
|
#include "tsan_mman.h"
|
|
|
|
#include "tsan_platform.h"
|
|
|
|
|
2015-03-13 02:14:42 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-09-03 19:43:04 +08:00
|
|
|
// Suppressions for true/false positives in standard libraries.
|
|
|
|
static const char *const std_suppressions =
|
|
|
|
// Libstdc++ 4.4 has data races in std::string.
|
|
|
|
// See http://crbug.com/181502 for an example.
|
|
|
|
"race:^_M_rep$\n"
|
|
|
|
"race:^_M_is_leaked$\n"
|
|
|
|
// False positive when using std <thread>.
|
|
|
|
// Happens because we miss atomic synchronization in libstdc++.
|
|
|
|
// See http://llvm.org/bugs/show_bug.cgi?id=17066 for details.
|
2013-09-03 19:50:48 +08:00
|
|
|
"race:std::_Sp_counted_ptr_inplace<std::thread::_Impl\n";
|
2013-09-03 19:43:04 +08:00
|
|
|
|
2013-01-24 21:50:10 +08:00
|
|
|
// Can be overriden in frontend.
|
2015-11-30 21:27:18 +08:00
|
|
|
SANITIZER_WEAK_DEFAULT_IMPL
|
|
|
|
const char *__tsan_default_suppressions() {
|
2013-01-24 21:50:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
namespace __tsan {
|
|
|
|
|
2015-02-21 01:41:59 +08:00
|
|
|
ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
|
|
|
|
static SuppressionContext *suppression_ctx = nullptr;
|
|
|
|
static const char *kSuppressionTypes[] = {
|
2015-06-29 22:38:31 +08:00
|
|
|
kSuppressionRace, kSuppressionRaceTop, kSuppressionMutex,
|
|
|
|
kSuppressionThread, kSuppressionSignal, kSuppressionLib,
|
|
|
|
kSuppressionDeadlock};
|
2014-08-05 08:43:23 +08:00
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void InitializeSuppressions() {
|
2015-02-21 01:41:59 +08:00
|
|
|
CHECK_EQ(nullptr, suppression_ctx);
|
|
|
|
suppression_ctx = new (suppression_placeholder) // NOLINT
|
|
|
|
SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
|
|
|
|
suppression_ctx->ParseFromFile(flags()->suppressions);
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2015-02-21 01:41:59 +08:00
|
|
|
suppression_ctx->Parse(__tsan_default_suppressions());
|
|
|
|
suppression_ctx->Parse(std_suppressions);
|
2013-01-24 21:50:10 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2015-02-21 01:41:59 +08:00
|
|
|
SuppressionContext *Suppressions() {
|
|
|
|
CHECK(suppression_ctx);
|
|
|
|
return suppression_ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *conv(ReportType typ) {
|
2012-05-10 21:48:04 +08:00
|
|
|
if (typ == ReportTypeRace)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionRace;
|
2013-05-29 19:23:54 +08:00
|
|
|
else if (typ == ReportTypeVptrRace)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionRace;
|
2013-05-29 19:23:54 +08:00
|
|
|
else if (typ == ReportTypeUseAfterFree)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionRace;
|
2014-10-13 16:46:25 +08:00
|
|
|
else if (typ == ReportTypeVptrUseAfterFree)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionRace;
|
2012-05-10 21:48:04 +08:00
|
|
|
else if (typ == ReportTypeThreadLeak)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionThread;
|
2012-05-10 21:48:04 +08:00
|
|
|
else if (typ == ReportTypeMutexDestroyLocked)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionMutex;
|
2014-04-25 18:09:18 +08:00
|
|
|
else if (typ == ReportTypeMutexDoubleLock)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionMutex;
|
2016-03-16 23:39:20 +08:00
|
|
|
else if (typ == ReportTypeMutexInvalidAccess)
|
|
|
|
return kSuppressionMutex;
|
2014-04-25 18:09:18 +08:00
|
|
|
else if (typ == ReportTypeMutexBadUnlock)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionMutex;
|
2014-04-25 18:09:18 +08:00
|
|
|
else if (typ == ReportTypeMutexBadReadLock)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionMutex;
|
2014-04-25 18:09:18 +08:00
|
|
|
else if (typ == ReportTypeMutexBadReadUnlock)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionMutex;
|
2012-05-10 21:48:04 +08:00
|
|
|
else if (typ == ReportTypeSignalUnsafe)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionSignal;
|
2013-05-29 19:23:54 +08:00
|
|
|
else if (typ == ReportTypeErrnoInSignal)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionNone;
|
2014-03-19 20:26:33 +08:00
|
|
|
else if (typ == ReportTypeDeadlock)
|
2015-02-21 01:41:59 +08:00
|
|
|
return kSuppressionDeadlock;
|
2016-02-19 06:07:42 +08:00
|
|
|
Printf("ThreadSanitizer: unknown report type %d\n", typ);
|
2013-06-10 23:38:44 +08:00
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2015-06-29 22:38:31 +08:00
|
|
|
static uptr IsSuppressed(const char *stype, const AddressInfo &info,
|
|
|
|
Suppression **sp) {
|
|
|
|
if (suppression_ctx->Match(info.function, stype, sp) ||
|
|
|
|
suppression_ctx->Match(info.file, stype, sp) ||
|
|
|
|
suppression_ctx->Match(info.module, stype, sp)) {
|
2015-09-03 19:20:46 +08:00
|
|
|
VPrintf(2, "ThreadSanitizer: matched suppression '%s'\n", (*sp)->templ);
|
|
|
|
atomic_fetch_add(&(*sp)->hit_count, 1, memory_order_relaxed);
|
2015-06-29 22:38:31 +08:00
|
|
|
return info.address;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-10 23:38:44 +08:00
|
|
|
uptr IsSuppressed(ReportType typ, const ReportStack *stack, Suppression **sp) {
|
2015-02-21 01:41:59 +08:00
|
|
|
CHECK(suppression_ctx);
|
|
|
|
if (!suppression_ctx->SuppressionCount() || stack == 0 ||
|
2014-07-31 04:54:37 +08:00
|
|
|
!stack->suppressable)
|
2014-05-29 02:03:32 +08:00
|
|
|
return 0;
|
2015-02-21 01:41:59 +08:00
|
|
|
const char *stype = conv(typ);
|
|
|
|
if (0 == internal_strcmp(stype, kSuppressionNone))
|
2012-10-05 23:51:32 +08:00
|
|
|
return 0;
|
2014-12-03 03:48:40 +08:00
|
|
|
for (const SymbolizedStack *frame = stack->frames; frame;
|
2015-06-29 22:38:31 +08:00
|
|
|
frame = frame->next) {
|
|
|
|
uptr pc = IsSuppressed(stype, frame->info, sp);
|
|
|
|
if (pc != 0)
|
|
|
|
return pc;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
2015-06-29 22:38:31 +08:00
|
|
|
if (0 == internal_strcmp(stype, kSuppressionRace) && stack->frames != nullptr)
|
|
|
|
return IsSuppressed(kSuppressionRaceTop, stack->frames->info, sp);
|
2012-10-05 23:51:32 +08:00
|
|
|
return 0;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
2013-03-28 01:59:57 +08:00
|
|
|
|
2013-06-10 23:38:44 +08:00
|
|
|
uptr IsSuppressed(ReportType typ, const ReportLocation *loc, Suppression **sp) {
|
2015-02-21 01:41:59 +08:00
|
|
|
CHECK(suppression_ctx);
|
|
|
|
if (!suppression_ctx->SuppressionCount() || loc == 0 ||
|
2014-05-29 02:03:32 +08:00
|
|
|
loc->type != ReportLocationGlobal || !loc->suppressable)
|
2013-06-10 23:38:44 +08:00
|
|
|
return 0;
|
2015-02-21 01:41:59 +08:00
|
|
|
const char *stype = conv(typ);
|
|
|
|
if (0 == internal_strcmp(stype, kSuppressionNone))
|
2013-06-10 23:38:44 +08:00
|
|
|
return 0;
|
2013-06-26 23:37:14 +08:00
|
|
|
Suppression *s;
|
2014-11-05 06:07:57 +08:00
|
|
|
const DataInfo &global = loc->global;
|
2015-02-21 01:41:59 +08:00
|
|
|
if (suppression_ctx->Match(global.name, stype, &s) ||
|
|
|
|
suppression_ctx->Match(global.module, stype, &s)) {
|
2015-09-03 19:20:46 +08:00
|
|
|
VPrintf(2, "ThreadSanitizer: matched suppression '%s'\n", s->templ);
|
|
|
|
atomic_fetch_add(&s->hit_count, 1, memory_order_relaxed);
|
2013-06-26 23:37:14 +08:00
|
|
|
*sp = s;
|
2014-11-05 06:07:57 +08:00
|
|
|
return global.start;
|
2013-06-10 23:38:44 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-28 01:59:57 +08:00
|
|
|
void PrintMatchedSuppressions() {
|
2013-06-26 23:37:14 +08:00
|
|
|
InternalMmapVector<Suppression *> matched(1);
|
2015-02-21 01:41:59 +08:00
|
|
|
CHECK(suppression_ctx);
|
|
|
|
suppression_ctx->GetMatched(&matched);
|
2013-06-26 23:37:14 +08:00
|
|
|
if (!matched.size())
|
2013-03-28 01:59:57 +08:00
|
|
|
return;
|
2013-06-26 23:37:14 +08:00
|
|
|
int hit_count = 0;
|
|
|
|
for (uptr i = 0; i < matched.size(); i++)
|
2015-09-03 19:20:46 +08:00
|
|
|
hit_count += atomic_load_relaxed(&matched[i]->hit_count);
|
2013-06-26 23:37:14 +08:00
|
|
|
Printf("ThreadSanitizer: Matched %d suppressions (pid=%d):\n", hit_count,
|
|
|
|
(int)internal_getpid());
|
|
|
|
for (uptr i = 0; i < matched.size(); i++) {
|
2016-02-04 13:28:48 +08:00
|
|
|
Printf("%d %s:%s\n", atomic_load_relaxed(&matched[i]->hit_count),
|
|
|
|
matched[i]->type, matched[i]->templ);
|
2013-03-28 01:59:57 +08:00
|
|
|
}
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
} // namespace __tsan
|