[compiler-rt] r192785 - tsan: refactor libignore implementation
Dmitry Vyukov
dvyukov at google.com
Wed Oct 16 04:28:12 PDT 2013
Author: dvyukov
Date: Wed Oct 16 06:28:12 2013
New Revision: 192785
URL: http://llvm.org/viewvc/llvm-project?rev=192785&view=rev
Log:
tsan: refactor libignore implementation
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc?rev=192785&r1=192784&r2=192785&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libignore.cc Wed Oct 16 06:28:12 2013
@@ -11,6 +11,7 @@
#if SANITIZER_LINUX
#include "sanitizer_libignore.h"
+#include "sanitizer_flags.h"
#include "sanitizer_procmaps.h"
namespace __sanitizer {
@@ -39,12 +40,20 @@ void LibIgnore::Init(const SuppressionCo
}
void LibIgnore::OnLibraryLoaded(const char *name) {
- const char *real_name = 0;
+ BlockingMutexLock lock(&mutex_);
+ // Try to match suppressions with symlink target.
InternalScopedBuffer<char> buf(4096);
- if (name != 0 && internal_readlink(name, buf.data(), buf.size() - 1) > 0)
- real_name = buf.data();
+ if (name != 0 && internal_readlink(name, buf.data(), buf.size() - 1) > 0 &&
+ buf.data()[0]) {
+ for (uptr i = 0; i < count_; i++) {
+ Lib *lib = &libs_[i];
+ if (!lib->loaded && lib->real_name == 0 &&
+ TemplateMatch(lib->templ, name))
+ lib->real_name = internal_strdup(buf.data());
+ }
+ }
- BlockingMutexLock lock(&mutex_);
+ // Scan suppressions list and find newly loaded and unloaded libraries.
MemoryMappingLayout proc_maps(/*cache_enabled*/false);
InternalScopedBuffer<char> module(4096);
for (uptr i = 0; i < count_; i++) {
@@ -55,36 +64,28 @@ void LibIgnore::OnLibraryLoaded(const ch
while (proc_maps.Next(&b, &e, &off, module.data(), module.size(), &prot)) {
if ((prot & MemoryMappingLayout::kProtectionExecute) == 0)
continue;
- bool matched = false;
- bool symlink = false;
- if (TemplateMatch(lib->templ, module.data()))
- matched = true;
- // Resolve symlinks.
- if (real_name != 0 && real_name[0] != 0 &&
- TemplateMatch(lib->templ, name) &&
- internal_strcmp(real_name, module.data()) == 0) {
- matched = true;
- symlink = true;
+ if (TemplateMatch(lib->templ, module.data()) ||
+ (lib->real_name != 0 &&
+ internal_strcmp(lib->real_name, module.data()) == 0)) {
+ if (loaded) {
+ Report("%s: called_from_lib suppression '%s' is matched against"
+ " 2 libraries: '%s' and '%s'\n",
+ SanitizerToolName, lib->templ, lib->name, module.data());
+ Die();
+ }
+ loaded = true;
+ if (lib->loaded)
+ continue;
+ if (common_flags()->verbosity)
+ Report("Matched called_from_lib suppression '%s' against library"
+ " '%s'\n", lib->templ, module.data());
+ lib->loaded = true;
+ lib->name = internal_strdup(module.data());
+ const uptr idx = atomic_load(&loaded_count_, memory_order_relaxed);
+ code_ranges_[idx].begin = b;
+ code_ranges_[idx].end = e;
+ atomic_store(&loaded_count_, idx + 1, memory_order_release);
}
- if (!matched)
- continue;
- if (loaded) {
- Report("%s: called_from_lib suppression '%s' is matched against"
- " 2 libraries: '%s' and '%s'\n",
- SanitizerToolName, lib->templ, lib->name, module.data());
- Die();
- }
- loaded = true;
- if (lib->loaded)
- continue;
- lib->loaded = true;
- lib->name = internal_strdup(module.data());
- if (symlink)
- lib->real_name = internal_strdup(real_name);
- const uptr idx = atomic_load(&loaded_count_, memory_order_relaxed);
- code_ranges_[idx].begin = b;
- code_ranges_[idx].end = e;
- atomic_store(&loaded_count_, idx + 1, memory_order_release);
}
if (lib->loaded && !loaded) {
Report("%s: library '%s' that was matched against called_from_lib"
More information about the llvm-commits
mailing list