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"
|
|
|
|
|
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.
|
|
|
|
#ifndef TSAN_GO
|
|
|
|
extern "C" const char *WEAK __tsan_default_suppressions() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
namespace __tsan {
|
|
|
|
|
2014-08-05 08:43:23 +08:00
|
|
|
static bool suppressions_inited = false;
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void InitializeSuppressions() {
|
2014-08-05 08:43:23 +08:00
|
|
|
CHECK(!suppressions_inited);
|
|
|
|
SuppressionContext::InitIfNecessary();
|
2013-01-24 21:50:10 +08:00
|
|
|
#ifndef TSAN_GO
|
2014-07-31 05:53:30 +08:00
|
|
|
SuppressionContext::Get()->Parse(__tsan_default_suppressions());
|
2014-07-31 04:54:37 +08:00
|
|
|
SuppressionContext::Get()->Parse(std_suppressions);
|
2013-01-24 21:50:10 +08:00
|
|
|
#endif
|
2014-08-05 08:43:23 +08:00
|
|
|
suppressions_inited = true;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2013-06-10 23:38:44 +08:00
|
|
|
SuppressionType conv(ReportType typ) {
|
2012-05-10 21:48:04 +08:00
|
|
|
if (typ == ReportTypeRace)
|
2013-06-10 23:38:44 +08:00
|
|
|
return SuppressionRace;
|
2013-05-29 19:23:54 +08:00
|
|
|
else if (typ == ReportTypeVptrRace)
|
2013-06-10 23:38:44 +08:00
|
|
|
return SuppressionRace;
|
2013-05-29 19:23:54 +08:00
|
|
|
else if (typ == ReportTypeUseAfterFree)
|
2013-08-07 20:39:00 +08:00
|
|
|
return SuppressionRace;
|
2014-10-13 16:46:25 +08:00
|
|
|
else if (typ == ReportTypeVptrUseAfterFree)
|
|
|
|
return SuppressionRace;
|
2012-05-10 21:48:04 +08:00
|
|
|
else if (typ == ReportTypeThreadLeak)
|
2013-06-10 23:38:44 +08:00
|
|
|
return SuppressionThread;
|
2012-05-10 21:48:04 +08:00
|
|
|
else if (typ == ReportTypeMutexDestroyLocked)
|
2013-06-10 23:38:44 +08:00
|
|
|
return SuppressionMutex;
|
2014-04-25 18:09:18 +08: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-05-10 21:48:04 +08:00
|
|
|
else if (typ == ReportTypeSignalUnsafe)
|
2013-06-10 23:38:44 +08:00
|
|
|
return SuppressionSignal;
|
2013-05-29 19:23:54 +08:00
|
|
|
else if (typ == ReportTypeErrnoInSignal)
|
2013-06-10 23:38:44 +08:00
|
|
|
return SuppressionNone;
|
2014-03-19 20:26:33 +08:00
|
|
|
else if (typ == ReportTypeDeadlock)
|
|
|
|
return SuppressionDeadlock;
|
2013-06-10 23:38:44 +08:00
|
|
|
Printf("ThreadSanitizer: unknown report type %d\n", typ),
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
|
|
|
uptr IsSuppressed(ReportType typ, const ReportStack *stack, Suppression **sp) {
|
2014-07-31 04:54:37 +08:00
|
|
|
if (!SuppressionContext::Get()->SuppressionCount() || stack == 0 ||
|
|
|
|
!stack->suppressable)
|
2014-05-29 02:03:32 +08:00
|
|
|
return 0;
|
2013-06-10 23:38:44 +08:00
|
|
|
SuppressionType stype = conv(typ);
|
|
|
|
if (stype == SuppressionNone)
|
2012-10-05 23:51:32 +08:00
|
|
|
return 0;
|
2013-06-26 23:37:14 +08:00
|
|
|
Suppression *s;
|
2012-05-10 21:48:04 +08:00
|
|
|
for (const ReportStack *frame = stack; frame; frame = frame->next) {
|
2014-11-05 04:52:37 +08: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-06-26 23:37:14 +08:00
|
|
|
DPrintf("ThreadSanitizer: matched suppression '%s'\n", s->templ);
|
|
|
|
s->hit_count++;
|
|
|
|
*sp = s;
|
2014-11-05 04:52:37 +08:00
|
|
|
return info.address;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2014-07-31 04:54:37 +08:00
|
|
|
if (!SuppressionContext::Get()->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;
|
|
|
|
SuppressionType stype = conv(typ);
|
|
|
|
if (stype == SuppressionNone)
|
|
|
|
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;
|
|
|
|
if (SuppressionContext::Get()->Match(global.name, stype, &s) ||
|
|
|
|
SuppressionContext::Get()->Match(global.module, stype, &s)) {
|
2013-06-27 00:49:34 +08:00
|
|
|
DPrintf("ThreadSanitizer: matched suppression '%s'\n", s->templ);
|
2013-06-26 23:37:14 +08:00
|
|
|
s->hit_count++;
|
|
|
|
*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);
|
2014-07-31 04:54:37 +08:00
|
|
|
SuppressionContext::Get()->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++)
|
|
|
|
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);
|
2013-03-28 01:59:57 +08:00
|
|
|
}
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
} // namespace __tsan
|