diff options
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_libignore.cc | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libignore.cc b/compiler-rt/lib/sanitizer_common/sanitizer_libignore.cc index 9e17819965f..0f193a13025 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_libignore.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_libignore.cc @@ -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 SuppressionContext &supp) { } 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 char *name) { 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" |

