2012-11-22 23:03:11 +01:00
|
|
|
//===-- tsan_suppressions.cc ----------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
|
|
|
#include "sanitizer_common/sanitizer_suppressions.h"
|
2012-11-22 23:03:11 +01:00
|
|
|
#include "tsan_suppressions.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_flags.h"
|
|
|
|
#include "tsan_mman.h"
|
|
|
|
#include "tsan_platform.h"
|
|
|
|
|
2013-11-04 22:33:31 +01: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.
|
|
|
|
"race:std::_Sp_counted_ptr_inplace<std::thread::_Impl\n";
|
|
|
|
|
2013-02-13 11:46:01 +01:00
|
|
|
// Can be overriden in frontend.
|
|
|
|
#ifndef TSAN_GO
|
|
|
|
extern "C" const char *WEAK __tsan_default_suppressions() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
namespace __tsan {
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
static bool suppressions_inited = false;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
void InitializeSuppressions() {
|
2014-09-23 19:59:53 +02:00
|
|
|
CHECK(!suppressions_inited);
|
|
|
|
SuppressionContext::InitIfNecessary();
|
2013-02-13 11:46:01 +01:00
|
|
|
#ifndef TSAN_GO
|
2014-09-23 19:59:53 +02:00
|
|
|
SuppressionContext::Get()->Parse(__tsan_default_suppressions());
|
|
|
|
SuppressionContext::Get()->Parse(std_suppressions);
|
2013-02-13 11:46:01 +01:00
|
|
|
#endif
|
2014-09-23 19:59:53 +02:00
|
|
|
suppressions_inited = true;
|
2013-12-05 10:18:38 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
SuppressionType conv(ReportType typ) {
|
2012-11-22 23:03:11 +01:00
|
|
|
if (typ == ReportTypeRace)
|
2013-11-04 22:33:31 +01:00
|
|
|
return SuppressionRace;
|
|
|
|
else if (typ == ReportTypeVptrRace)
|
|
|
|
return SuppressionRace;
|
|
|
|
else if (typ == ReportTypeUseAfterFree)
|
|
|
|
return SuppressionRace;
|
2014-11-13 21:41:38 +01:00
|
|
|
else if (typ == ReportTypeVptrUseAfterFree)
|
|
|
|
return SuppressionRace;
|
2012-11-22 23:03:11 +01:00
|
|
|
else if (typ == ReportTypeThreadLeak)
|
2013-11-04 22:33:31 +01:00
|
|
|
return SuppressionThread;
|
2012-11-22 23:03:11 +01:00
|
|
|
else if (typ == ReportTypeMutexDestroyLocked)
|
2013-11-04 22:33:31 +01:00
|
|
|
return SuppressionMutex;
|
2014-05-22 09:09:21 +02:00
|
|
|
else if (typ == ReportTypeMutexDoubleLock)
|
|
|
|
return SuppressionMutex;
|
|
|
|
else if (typ == ReportTypeMutexBadUnlock)
|
|
|
|
return SuppressionMutex;
|
|
|
|
else if (typ == ReportTypeMutexBadReadLock)
|
|
|
|
return SuppressionMutex;
|
|
|
|
else if (typ == ReportTypeMutexBadReadUnlock)
|
|
|
|
return SuppressionMutex;
|
2012-11-22 23:03:11 +01:00
|
|
|
else if (typ == ReportTypeSignalUnsafe)
|
2013-11-04 22:33:31 +01:00
|
|
|
return SuppressionSignal;
|
|
|
|
else if (typ == ReportTypeErrnoInSignal)
|
|
|
|
return SuppressionNone;
|
2014-05-22 09:09:21 +02:00
|
|
|
else if (typ == ReportTypeDeadlock)
|
|
|
|
return SuppressionDeadlock;
|
2013-11-04 22:33:31 +01:00
|
|
|
Printf("ThreadSanitizer: unknown report type %d\n", typ),
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
|
|
|
uptr IsSuppressed(ReportType typ, const ReportStack *stack, Suppression **sp) {
|
2014-09-23 19:59:53 +02:00
|
|
|
if (!SuppressionContext::Get()->SuppressionCount() || stack == 0 ||
|
|
|
|
!stack->suppressable)
|
|
|
|
return 0;
|
2013-11-04 22:33:31 +01:00
|
|
|
SuppressionType stype = conv(typ);
|
|
|
|
if (stype == SuppressionNone)
|
2012-11-22 23:03:11 +01:00
|
|
|
return 0;
|
2013-11-04 22:33:31 +01:00
|
|
|
Suppression *s;
|
2012-11-22 23:03:11 +01:00
|
|
|
for (const ReportStack *frame = stack; frame; frame = frame->next) {
|
2014-11-13 21:41:38 +01:00
|
|
|
const AddressInfo &info = frame->info;
|
|
|
|
if (SuppressionContext::Get()->Match(info.function, stype, &s) ||
|
|
|
|
SuppressionContext::Get()->Match(info.file, stype, &s) ||
|
|
|
|
SuppressionContext::Get()->Match(info.module, stype, &s)) {
|
2013-11-04 22:33:31 +01:00
|
|
|
DPrintf("ThreadSanitizer: matched suppression '%s'\n", s->templ);
|
|
|
|
s->hit_count++;
|
|
|
|
*sp = s;
|
2014-11-13 21:41:38 +01:00
|
|
|
return info.address;
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
uptr IsSuppressed(ReportType typ, const ReportLocation *loc, Suppression **sp) {
|
2014-09-23 19:59:53 +02:00
|
|
|
if (!SuppressionContext::Get()->SuppressionCount() || loc == 0 ||
|
|
|
|
loc->type != ReportLocationGlobal || !loc->suppressable)
|
2013-11-04 22:33:31 +01:00
|
|
|
return 0;
|
|
|
|
SuppressionType stype = conv(typ);
|
|
|
|
if (stype == SuppressionNone)
|
|
|
|
return 0;
|
|
|
|
Suppression *s;
|
2014-11-13 21:41:38 +01:00
|
|
|
const DataInfo &global = loc->global;
|
|
|
|
if (SuppressionContext::Get()->Match(global.name, stype, &s) ||
|
|
|
|
SuppressionContext::Get()->Match(global.module, stype, &s)) {
|
2013-11-04 22:33:31 +01:00
|
|
|
DPrintf("ThreadSanitizer: matched suppression '%s'\n", s->templ);
|
|
|
|
s->hit_count++;
|
|
|
|
*sp = s;
|
2014-11-13 21:41:38 +01:00
|
|
|
return global.start;
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintMatchedSuppressions() {
|
|
|
|
InternalMmapVector<Suppression *> matched(1);
|
2014-09-23 19:59:53 +02:00
|
|
|
SuppressionContext::Get()->GetMatched(&matched);
|
2013-11-04 22:33:31 +01:00
|
|
|
if (!matched.size())
|
|
|
|
return;
|
|
|
|
int hit_count = 0;
|
|
|
|
for (uptr i = 0; i < matched.size(); i++)
|
|
|
|
hit_count += matched[i]->hit_count;
|
|
|
|
Printf("ThreadSanitizer: Matched %d suppressions (pid=%d):\n", hit_count,
|
|
|
|
(int)internal_getpid());
|
|
|
|
for (uptr i = 0; i < matched.size(); i++) {
|
|
|
|
Printf("%d %s:%s\n", matched[i]->hit_count,
|
|
|
|
SuppressionTypeString(matched[i]->type), matched[i]->templ);
|
|
|
|
}
|
|
|
|
}
|
2012-11-22 23:03:11 +01:00
|
|
|
} // namespace __tsan
|