2013-10-03 21:37:17 +08:00
|
|
|
//===-- sanitizer_libignore.cc --------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_platform.h"
|
2015-10-01 07:52:54 +08:00
|
|
|
|
2015-11-03 22:33:39 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC
|
2013-10-03 21:37:17 +08:00
|
|
|
|
|
|
|
#include "sanitizer_libignore.h"
|
2013-10-16 19:28:12 +08:00
|
|
|
#include "sanitizer_flags.h"
|
2015-04-09 20:54:06 +08:00
|
|
|
#include "sanitizer_posix.h"
|
2013-10-03 21:37:17 +08:00
|
|
|
#include "sanitizer_procmaps.h"
|
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
LibIgnore::LibIgnore(LinkerInitialized) {
|
|
|
|
}
|
|
|
|
|
2015-02-20 06:56:49 +08:00
|
|
|
void LibIgnore::AddIgnoredLibrary(const char *name_templ) {
|
2013-10-03 21:37:17 +08:00
|
|
|
BlockingMutexLock lock(&mutex_);
|
2015-02-20 06:56:49 +08:00
|
|
|
if (count_ >= kMaxLibs) {
|
|
|
|
Report("%s: too many ignored libraries (max: %d)\n", SanitizerToolName,
|
|
|
|
kMaxLibs);
|
|
|
|
Die();
|
2013-10-03 21:37:17 +08:00
|
|
|
}
|
2015-02-20 06:56:49 +08:00
|
|
|
Lib *lib = &libs_[count_++];
|
|
|
|
lib->templ = internal_strdup(name_templ);
|
|
|
|
lib->name = nullptr;
|
|
|
|
lib->real_name = nullptr;
|
|
|
|
lib->loaded = false;
|
2013-10-03 21:37:17 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 19:34:59 +08:00
|
|
|
void LibIgnore::OnLibraryLoaded(const char *name) {
|
2013-10-16 19:28:12 +08:00
|
|
|
BlockingMutexLock lock(&mutex_);
|
|
|
|
// Try to match suppressions with symlink target.
|
2014-12-03 06:20:11 +08:00
|
|
|
InternalScopedString buf(kMaxPathLength);
|
2015-10-01 07:52:54 +08:00
|
|
|
if (name && internal_readlink(name, buf.data(), buf.size() - 1) > 0 &&
|
2014-12-03 06:20:11 +08:00
|
|
|
buf[0]) {
|
2013-10-16 19:28:12 +08:00
|
|
|
for (uptr i = 0; i < count_; i++) {
|
|
|
|
Lib *lib = &libs_[i];
|
2015-10-01 07:52:54 +08:00
|
|
|
if (!lib->loaded && (!lib->real_name) &&
|
2013-10-16 19:28:12 +08:00
|
|
|
TemplateMatch(lib->templ, name))
|
|
|
|
lib->real_name = internal_strdup(buf.data());
|
|
|
|
}
|
|
|
|
}
|
2013-10-15 19:34:59 +08:00
|
|
|
|
2013-10-16 19:28:12 +08:00
|
|
|
// Scan suppressions list and find newly loaded and unloaded libraries.
|
2013-10-03 21:37:17 +08:00
|
|
|
MemoryMappingLayout proc_maps(/*cache_enabled*/false);
|
2014-12-03 06:20:11 +08:00
|
|
|
InternalScopedString module(kMaxPathLength);
|
2013-10-03 21:37:17 +08:00
|
|
|
for (uptr i = 0; i < count_; i++) {
|
|
|
|
Lib *lib = &libs_[i];
|
|
|
|
bool loaded = false;
|
|
|
|
proc_maps.Reset();
|
|
|
|
uptr b, e, off, prot;
|
2013-10-15 21:04:42 +08:00
|
|
|
while (proc_maps.Next(&b, &e, &off, module.data(), module.size(), &prot)) {
|
|
|
|
if ((prot & MemoryMappingLayout::kProtectionExecute) == 0)
|
|
|
|
continue;
|
2013-10-16 19:28:12 +08:00
|
|
|
if (TemplateMatch(lib->templ, module.data()) ||
|
2015-10-01 07:52:54 +08:00
|
|
|
(lib->real_name &&
|
2013-10-16 19:28:12 +08:00
|
|
|
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;
|
2013-12-05 20:04:51 +08:00
|
|
|
VReport(1,
|
|
|
|
"Matched called_from_lib suppression '%s' against library"
|
|
|
|
" '%s'\n",
|
|
|
|
lib->templ, module.data());
|
2013-10-16 19:28:12 +08:00
|
|
|
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);
|
2013-10-03 21:37:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lib->loaded && !loaded) {
|
|
|
|
Report("%s: library '%s' that was matched against called_from_lib"
|
|
|
|
" suppression '%s' is unloaded\n",
|
|
|
|
SanitizerToolName, lib->name, lib->templ);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibIgnore::OnLibraryUnloaded() {
|
2015-10-01 07:52:54 +08:00
|
|
|
OnLibraryLoaded(nullptr);
|
2013-10-03 21:37:17 +08:00
|
|
|
}
|
|
|
|
|
2015-10-01 07:52:54 +08:00
|
|
|
} // namespace __sanitizer
|
2013-10-03 21:37:17 +08:00
|
|
|
|
2015-10-01 07:52:54 +08:00
|
|
|
#endif // #if SANITIZER_FREEBSD || SANITIZER_LINUX
|