[compiler-rt] r303422 - Use write instead of read permissions to check for global sections on mac

Francis Ricci via llvm-commits llvm-commits at lists.llvm.org
Fri May 19 06:34:03 PDT 2017


Author: fjricci
Date: Fri May 19 08:34:02 2017
New Revision: 303422

URL: http://llvm.org/viewvc/llvm-project?rev=303422&view=rev
Log:
Use write instead of read permissions to check for global sections on mac

Summary:
The LINKEDIT section is very large and is read-only. Scanning this
section caused LSan on darwin to be very slow. When only writable sections
are scanned for global pointers, performance improved by a factor of about 25x.

Reviewers: alekseyshl, kubamracek

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D33322

Modified:
    compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
    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_procmaps_common.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc

Modified: compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_mac.cc?rev=303422&r1=303421&r2=303422&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common_mac.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common_mac.cc Fri May 19 08:34:02 2017
@@ -110,7 +110,8 @@ void ProcessGlobalRegions(Frontier *fron
 
     for (const __sanitizer::LoadedModule::AddressRange &range :
          modules[i].ranges()) {
-      if (range.executable || !range.readable) continue;
+      // Sections storing global variables are writable and non-executable
+      if (range.executable || !range.writable) continue;
 
       ScanGlobalRange(range.beg, range.end, frontier);
     }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=303422&r1=303421&r2=303422&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Fri May 19 08:34:02 2017
@@ -285,9 +285,9 @@ void LoadedModule::clear() {
 }
 
 void LoadedModule::addAddressRange(uptr beg, uptr end, bool executable,
-                                   bool readable) {
+                                   bool writable) {
   void *mem = InternalAlloc(sizeof(AddressRange));
-  AddressRange *r = new(mem) AddressRange(beg, end, executable, readable);
+  AddressRange *r = new(mem) AddressRange(beg, end, executable, writable);
   ranges_.push_back(r);
   if (executable && end > max_executable_address_)
     max_executable_address_ = end;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=303422&r1=303421&r2=303422&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Fri May 19 08:34:02 2017
@@ -717,7 +717,7 @@ class LoadedModule {
   void set(const char *module_name, uptr base_address, ModuleArch arch,
            u8 uuid[kModuleUUIDSize], bool instrumented);
   void clear();
-  void addAddressRange(uptr beg, uptr end, bool executable, bool readable);
+  void addAddressRange(uptr beg, uptr end, bool executable, bool writable);
   bool containsAddress(uptr address) const;
 
   const char *full_name() const { return full_name_; }
@@ -732,14 +732,14 @@ class LoadedModule {
     uptr beg;
     uptr end;
     bool executable;
-    bool readable;
+    bool writable;
 
-    AddressRange(uptr beg, uptr end, bool executable, bool readable)
+    AddressRange(uptr beg, uptr end, bool executable, bool writable)
         : next(nullptr),
           beg(beg),
           end(end),
           executable(executable),
-          readable(readable) {}
+          writable(writable) {}
   };
 
   const IntrusiveList<AddressRange> &ranges() const { return ranges_; }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=303422&r1=303421&r2=303422&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Fri May 19 08:34:02 2017
@@ -447,9 +447,9 @@ static int dl_iterate_phdr_cb(dl_phdr_in
       uptr cur_beg = info->dlpi_addr + phdr->p_vaddr;
       uptr cur_end = cur_beg + phdr->p_memsz;
       bool executable = phdr->p_flags & PF_X;
-      bool readable = phdr->p_flags & PF_R;
+      bool writable = phdr->p_flags & PF_W;
       cur_module.addAddressRange(cur_beg, cur_end, executable,
-                                 readable);
+                                 writable);
     }
   }
   data->modules->push_back(cur_module);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc?rev=303422&r1=303421&r2=303422&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc Fri May 19 08:34:02 2017
@@ -142,7 +142,7 @@ void MemoryMappingLayout::DumpListOfModu
     LoadedModule cur_module;
     cur_module.set(cur_name, base_address);
     cur_module.addAddressRange(cur_beg, cur_end, prot & kProtectionExecute,
-                               prot & kProtectionRead);
+                               prot & kProtectionWrite);
     modules->push_back(cur_module);
   }
 }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc?rev=303422&r1=303421&r2=303422&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_mac.cc Fri May 19 08:34:02 2017
@@ -336,7 +336,7 @@ void MemoryMappingLayout::DumpListOfModu
                       current_instrumented_);
     }
     cur_module->addAddressRange(cur_beg, cur_end, prot & kProtectionExecute,
-                                prot & kProtectionRead);
+                                prot & kProtectionWrite);
   }
 }
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=303422&r1=303421&r2=303422&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Fri May 19 08:34:02 2017
@@ -554,7 +554,7 @@ void ListOfModules::init() {
     cur_module.set(module_name, adjusted_base);
     // We add the whole module as one single address range.
     cur_module.addAddressRange(base_address, end_address, /*executable*/ true,
-                               /*readable*/ true);
+                               /*writable*/ true);
     modules_.push_back(cur_module);
   }
   UnmapOrDie(hmodules, modules_buffer_size);




More information about the llvm-commits mailing list