[PATCH] D37269: Add support for custom loaders to the sanitizer symbolizer

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 07:32:54 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL314671: Add support for custom loaders to the sanitizer symbolizer (authored by fjricci).

Changed prior to commit:
  https://reviews.llvm.org/D37269?vs=117188&id=117345#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37269

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
@@ -416,6 +416,8 @@
   memory_mapping.DumpListOfModules(&modules_);
 }
 
+void ListOfModules::fallbackInit() { clear(); }
+
 static HandleSignalMode GetHandleSignalModeImpl(int signum) {
   switch (signum) {
     case SIGABRT:
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -488,6 +488,17 @@
   }
 }
 
+// When a custom loader is used, dl_iterate_phdr may not contain the full
+// list of modules. Allow callers to fall back to using procmaps.
+void ListOfModules::fallbackInit() {
+  if (!requiresProcmaps()) {
+    clearOrInit();
+    procmapsInit(&modules_);
+  } else {
+    clear();
+  }
+}
+
 // getrusage does not give us the current RSS, only the max RSS.
 // Still, this is better than nothing if /proc/self/statm is not available
 // for some reason, e.g. due to a sandbox.
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
@@ -152,6 +152,7 @@
                                          uptr *module_offset,
                                          ModuleArch *module_arch);
   ListOfModules modules_;
+  ListOfModules fallback_modules_;
   // If stale, need to reload the modules before looking up addresses.
   bool modules_fresh_;
 
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
@@ -583,7 +583,9 @@
     modules_.push_back(cur_module);
   }
   UnmapOrDie(hmodules, modules_buffer_size);
-};
+}
+
+void ListOfModules::fallbackInit() { clear(); }
 
 // We can't use atexit() directly at __asan_init time as the CRT is not fully
 // initialized at this point.  Place the functions into a vector and use
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
@@ -730,6 +730,7 @@
   ListOfModules() : initialized(false) {}
   ~ListOfModules() { clear(); }
   void init();
+  void fallbackInit();  // Uses fallback init if available, otherwise clears
   const LoadedModule *begin() const { return modules_.begin(); }
   LoadedModule *begin() { return modules_.begin(); }
   const LoadedModule *end() const { return modules_.end(); }
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
@@ -165,6 +165,7 @@
 
 void Symbolizer::RefreshModules() {
   modules_.init();
+  fallback_modules_.fallbackInit();
   RAW_CHECK(modules_.size() > 0);
   modules_fresh_ = true;
 }
@@ -198,6 +199,10 @@
     if (module) return module;
   }
 #endif
+
+  if (fallback_modules_.size()) {
+    module = SearchForModule(fallback_modules_, address);
+  }
   return module;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37269.117345.patch
Type: text/x-patch
Size: 3720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171002/664c6462/attachment.bin>


More information about the llvm-commits mailing list