* function.c (dump_stack_clash_frame_info): New function.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_libignore.cc
blob4b8cbed5ee326e4a4ba5555ec348e6b07e1fc064
1 //===-- sanitizer_libignore.cc --------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
8 #include "sanitizer_platform.h"
10 #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC
12 #include "sanitizer_libignore.h"
13 #include "sanitizer_flags.h"
14 #include "sanitizer_posix.h"
15 #include "sanitizer_procmaps.h"
17 namespace __sanitizer {
19 LibIgnore::LibIgnore(LinkerInitialized) {
22 void LibIgnore::AddIgnoredLibrary(const char *name_templ) {
23 BlockingMutexLock lock(&mutex_);
24 if (count_ >= kMaxLibs) {
25 Report("%s: too many ignored libraries (max: %d)\n", SanitizerToolName,
26 kMaxLibs);
27 Die();
29 Lib *lib = &libs_[count_++];
30 lib->templ = internal_strdup(name_templ);
31 lib->name = nullptr;
32 lib->real_name = nullptr;
33 lib->loaded = false;
36 void LibIgnore::OnLibraryLoaded(const char *name) {
37 BlockingMutexLock lock(&mutex_);
38 // Try to match suppressions with symlink target.
39 InternalScopedString buf(kMaxPathLength);
40 if (name && internal_readlink(name, buf.data(), buf.size() - 1) > 0 &&
41 buf[0]) {
42 for (uptr i = 0; i < count_; i++) {
43 Lib *lib = &libs_[i];
44 if (!lib->loaded && (!lib->real_name) &&
45 TemplateMatch(lib->templ, name))
46 lib->real_name = internal_strdup(buf.data());
50 // Scan suppressions list and find newly loaded and unloaded libraries.
51 MemoryMappingLayout proc_maps(/*cache_enabled*/false);
52 InternalScopedString module(kMaxPathLength);
53 for (uptr i = 0; i < count_; i++) {
54 Lib *lib = &libs_[i];
55 bool loaded = false;
56 proc_maps.Reset();
57 uptr b, e, off, prot;
58 while (proc_maps.Next(&b, &e, &off, module.data(), module.size(), &prot)) {
59 if ((prot & MemoryMappingLayout::kProtectionExecute) == 0)
60 continue;
61 if (TemplateMatch(lib->templ, module.data()) ||
62 (lib->real_name &&
63 internal_strcmp(lib->real_name, module.data()) == 0)) {
64 if (loaded) {
65 Report("%s: called_from_lib suppression '%s' is matched against"
66 " 2 libraries: '%s' and '%s'\n",
67 SanitizerToolName, lib->templ, lib->name, module.data());
68 Die();
70 loaded = true;
71 if (lib->loaded)
72 continue;
73 VReport(1,
74 "Matched called_from_lib suppression '%s' against library"
75 " '%s'\n",
76 lib->templ, module.data());
77 lib->loaded = true;
78 lib->name = internal_strdup(module.data());
79 const uptr idx = atomic_load(&loaded_count_, memory_order_relaxed);
80 code_ranges_[idx].begin = b;
81 code_ranges_[idx].end = e;
82 atomic_store(&loaded_count_, idx + 1, memory_order_release);
85 if (lib->loaded && !loaded) {
86 Report("%s: library '%s' that was matched against called_from_lib"
87 " suppression '%s' is unloaded\n",
88 SanitizerToolName, lib->name, lib->templ);
89 Die();
94 void LibIgnore::OnLibraryUnloaded() {
95 OnLibraryLoaded(nullptr);
98 } // namespace __sanitizer
100 #endif // #if SANITIZER_FREEBSD || SANITIZER_LINUX