[PATCH] D37268: Invalidate symbolizer module list from dlopen/dlclose interceptors

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 15:34:18 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL314219: Invalidate symbolizer module list from dlopen/dlclose interceptors (authored by fjricci).

Repository:
  rL LLVM

https://reviews.llvm.org/D37268

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
@@ -71,6 +71,10 @@
 StaticSpinMutex Symbolizer::init_mu_;
 LowLevelAllocator Symbolizer::symbolizer_allocator_;
 
+void Symbolizer::InvalidateModuleList() {
+  modules_fresh_ = false;
+}
+
 void Symbolizer::AddHooks(Symbolizer::StartSymbolizationHook start_hook,
                           Symbolizer::EndSymbolizationHook end_hook) {
   CHECK(start_hook_ == 0 && end_hook_ == 0);
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
@@ -121,6 +121,8 @@
 
   const LoadedModule *FindModuleForAddress(uptr address);
 
+  void InvalidateModuleList();
+
  private:
   // GetModuleNameAndOffsetForPC has to return a string to the caller.
   // Since the corresponding module might get unloaded later, we should create
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
@@ -176,14 +176,15 @@
       return &modules_[i];
     }
   }
-  // Reload the modules and look up again, if we haven't tried it yet.
+  // dlopen/dlclose interceptors invalidate the module list, but when
+  // interception is disabled, we need to retry if the lookup fails in
+  // case the module list changed.
+#if !SANITIZER_INTERCEPT_DLOPEN_DLCLOSE
   if (!modules_were_reloaded) {
-    // FIXME: set modules_fresh_ from dlopen()/dlclose() interceptors.
-    // It's too aggressive to reload the list of modules each time we fail
-    // to find a module for a given address.
     modules_fresh_ = false;
     return FindModuleForAddress(address);
   }
+#endif
   return 0;
 }
 
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -43,6 +43,7 @@
 #include "sanitizer_errno.h"
 #include "sanitizer_placement_new.h"
 #include "sanitizer_platform_interceptors.h"
+#include "sanitizer_symbolizer.h"
 #include "sanitizer_tls_get_addr.h"
 
 #include <stdarg.h>
@@ -5575,14 +5576,16 @@
   if (filename) COMMON_INTERCEPTOR_READ_STRING(ctx, filename, 0);
   COMMON_INTERCEPTOR_ON_DLOPEN(filename, flag);
   void *res = REAL(dlopen)(filename, flag);
+  Symbolizer::GetOrInit()->InvalidateModuleList();
   COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, res);
   return res;
 }
 
 INTERCEPTOR(int, dlclose, void *handle) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER_NOIGNORE(ctx, dlclose, handle);
   int res = REAL(dlclose)(handle);
+  Symbolizer::GetOrInit()->InvalidateModuleList();
   COMMON_INTERCEPTOR_LIBRARY_UNLOADED();
   return res;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37268.116725.patch
Type: text/x-patch
Size: 3286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170926/c1909e5f/attachment.bin>


More information about the llvm-commits mailing list