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
|
|
|
|
2017-07-20 21:33:06 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC || SANITIZER_NETBSD
|
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.
|
2016-11-22 17:49:11 +08:00
|
|
|
ListOfModules modules;
|
|
|
|
modules.init();
|
2013-10-03 21:37:17 +08:00
|
|
|
for (uptr i = 0; i < count_; i++) {
|
|
|
|
Lib *lib = &libs_[i];
|
|
|
|
bool loaded = false;
|
2016-11-22 17:49:11 +08:00
|
|
|
for (const auto &mod : modules) {
|
|
|
|
for (const auto &range : mod.ranges()) {
|
|
|
|
if (!range.executable)
|
|
|
|
continue;
|
|
|
|
if (!TemplateMatch(lib->templ, mod.full_name()) &&
|
|
|
|
!(lib->real_name &&
|
|
|
|
internal_strcmp(lib->real_name, mod.full_name()) == 0))
|
|
|
|
continue;
|
2013-10-16 19:28:12 +08:00
|
|
|
if (loaded) {
|
|
|
|
Report("%s: called_from_lib suppression '%s' is matched against"
|
|
|
|
" 2 libraries: '%s' and '%s'\n",
|
2016-11-22 17:49:11 +08:00
|
|
|
SanitizerToolName, lib->templ, lib->name, mod.full_name());
|
2013-10-16 19:28:12 +08:00
|
|
|
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",
|
2016-11-22 17:49:11 +08:00
|
|
|
lib->templ, mod.full_name());
|
2013-10-16 19:28:12 +08:00
|
|
|
lib->loaded = true;
|
2016-11-22 17:49:11 +08:00
|
|
|
lib->name = internal_strdup(mod.full_name());
|
2017-01-11 08:54:26 +08:00
|
|
|
const uptr idx =
|
|
|
|
atomic_load(&ignored_ranges_count_, memory_order_relaxed);
|
|
|
|
CHECK_LT(idx, kMaxLibs);
|
|
|
|
ignored_code_ranges_[idx].begin = range.beg;
|
|
|
|
ignored_code_ranges_[idx].end = range.end;
|
|
|
|
atomic_store(&ignored_ranges_count_, idx + 1, memory_order_release);
|
2016-11-22 17:49:11 +08:00
|
|
|
break;
|
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();
|
|
|
|
}
|
|
|
|
}
|
2017-01-11 08:54:26 +08:00
|
|
|
|
|
|
|
// Track instrumented ranges.
|
|
|
|
if (track_instrumented_libs_) {
|
|
|
|
for (const auto &mod : modules) {
|
|
|
|
if (!mod.instrumented())
|
|
|
|
continue;
|
|
|
|
for (const auto &range : mod.ranges()) {
|
|
|
|
if (!range.executable)
|
|
|
|
continue;
|
|
|
|
if (IsPcInstrumented(range.beg) && IsPcInstrumented(range.end - 1))
|
|
|
|
continue;
|
|
|
|
VReport(1, "Adding instrumented range %p-%p from library '%s'\n",
|
|
|
|
range.beg, range.end, mod.full_name());
|
|
|
|
const uptr idx =
|
|
|
|
atomic_load(&instrumented_ranges_count_, memory_order_relaxed);
|
|
|
|
CHECK_LT(idx, kMaxLibs);
|
|
|
|
instrumented_code_ranges_[idx].begin = range.beg;
|
|
|
|
instrumented_code_ranges_[idx].end = range.end;
|
|
|
|
atomic_store(&instrumented_ranges_count_, idx + 1,
|
|
|
|
memory_order_release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-03 21:37:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-07-20 22:15:00 +08:00
|
|
|
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC ||
|
|
|
|
// SANITIZER_NETBSD
|