From b2b4c3ab32a82606a6106c1730d41286329ed5e8 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 11 Jun 2014 10:11:51 +0000 Subject: [PATCH] [asan] Exclude non-executable mappings from coverage. llvm-svn: 210649 --- compiler-rt/lib/sanitizer_common/sanitizer_common.cc | 3 ++- compiler-rt/lib/sanitizer_common/sanitizer_common.h | 4 +++- .../sanitizer_common/sanitizer_coverage_mapping_libcdep.cc | 14 ++++++++------ .../lib/sanitizer_common/sanitizer_linux_libcdep.cc | 3 ++- .../lib/sanitizer_common/sanitizer_procmaps_linux.cc | 6 +++--- compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cc | 6 +++--- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 05bd876..6b76714 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -218,10 +218,11 @@ LoadedModule::LoadedModule(const char *module_name, uptr base_address) { n_ranges_ = 0; } -void LoadedModule::addAddressRange(uptr beg, uptr end) { +void LoadedModule::addAddressRange(uptr beg, uptr end, bool executable) { CHECK_LT(n_ranges_, kMaxNumberOfAddressRanges); ranges_[n_ranges_].beg = beg; ranges_[n_ranges_].end = end; + exec_[n_ranges_] = executable; n_ranges_++; } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 02271e7..6dc9500 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -482,7 +482,7 @@ uptr InternalBinarySearch(const Container &v, uptr first, uptr last, class LoadedModule { public: LoadedModule(const char *module_name, uptr base_address); - void addAddressRange(uptr beg, uptr end); + void addAddressRange(uptr beg, uptr end, bool executable); bool containsAddress(uptr address) const; const char *full_name() const { return full_name_; } @@ -491,6 +491,7 @@ class LoadedModule { uptr n_ranges() const { return n_ranges_; } uptr address_range_start(int i) const { return ranges_[i].beg; } uptr address_range_end(int i) const { return ranges_[i].end; } + bool address_range_executable(int i) const { return exec_[i]; } private: struct AddressRange { @@ -501,6 +502,7 @@ class LoadedModule { uptr base_address_; static const uptr kMaxNumberOfAddressRanges = 6; AddressRange ranges_[kMaxNumberOfAddressRanges]; + bool exec_[kMaxNumberOfAddressRanges]; uptr n_ranges_; }; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc index 28c9369..e4ee875 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc @@ -82,12 +82,14 @@ void CovUpdateMapping(uptr caller_pc) { for (int i = 0; i < n_modules; ++i) { char *module_name = StripModuleName(modules[i].full_name()); for (unsigned j = 0; j < modules[i].n_ranges(); ++j) { - uptr start = modules[i].address_range_start(j); - uptr end = modules[i].address_range_end(j); - uptr base = modules[i].base_address(); - text.append("%zx %zx %zx %s\n", start, end, base, module_name); - if (caller_pc && caller_pc >= start && caller_pc < end) - cached_mapping.SetModuleRange(start, end); + if (modules[i].address_range_executable(j)) { + uptr start = modules[i].address_range_start(j); + uptr end = modules[i].address_range_end(j); + uptr base = modules[i].base_address(); + text.append("%zx %zx %zx %s\n", start, end, base, module_name); + if (caller_pc && caller_pc >= start && caller_pc < end) + cached_mapping.SetModuleRange(start, end); + } } InternalFree(module_name); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index 396a0a8..0fb3864 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -507,7 +507,8 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { if (phdr->p_type == PT_LOAD) { uptr cur_beg = info->dlpi_addr + phdr->p_vaddr; uptr cur_end = cur_beg + phdr->p_memsz; - cur_module->addAddressRange(cur_beg, cur_end); + bool executable = phdr->p_flags & PF_X; + cur_module->addAddressRange(cur_beg, cur_end, executable); } } return 0; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_linux.cc index 4e8bf10..c647765 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_linux.cc @@ -244,12 +244,12 @@ uptr MemoryMappingLayout::DumpListOfModules(LoadedModule *modules, uptr max_modules, string_predicate_t filter) { Reset(); - uptr cur_beg, cur_end, cur_offset; + uptr cur_beg, cur_end, cur_offset, prot; InternalScopedBuffer module_name(kMaxPathLength); uptr n_modules = 0; for (uptr i = 0; n_modules < max_modules && Next(&cur_beg, &cur_end, &cur_offset, module_name.data(), - module_name.size(), 0); + module_name.size(), &prot); i++) { const char *cur_name = module_name.data(); if (cur_name[0] == '\0') @@ -270,7 +270,7 @@ uptr MemoryMappingLayout::DumpListOfModules(LoadedModule *modules, // first entry. uptr base_address = (i ? cur_beg : 0) - cur_offset; LoadedModule *cur_module = new(mem) LoadedModule(cur_name, base_address); - cur_module->addAddressRange(cur_beg, cur_end); + cur_module->addAddressRange(cur_beg, cur_end, prot & kProtectionExecute); n_modules++; } return n_modules; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cc b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cc index 1eb02ab..a3e094c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cc @@ -157,12 +157,12 @@ uptr MemoryMappingLayout::DumpListOfModules(LoadedModule *modules, uptr max_modules, string_predicate_t filter) { Reset(); - uptr cur_beg, cur_end; + uptr cur_beg, cur_end, prot; InternalScopedBuffer module_name(kMaxPathLength); uptr n_modules = 0; for (uptr i = 0; n_modules < max_modules && Next(&cur_beg, &cur_end, 0, module_name.data(), - module_name.size(), 0); + module_name.size(), &prot); i++) { const char *cur_name = module_name.data(); if (cur_name[0] == '\0') @@ -178,7 +178,7 @@ uptr MemoryMappingLayout::DumpListOfModules(LoadedModule *modules, cur_module = new(mem) LoadedModule(cur_name, cur_beg); n_modules++; } - cur_module->addAddressRange(cur_beg, cur_end); + cur_module->addAddressRange(cur_beg, cur_end, prot & kProtectionExecute); } return n_modules; } -- 2.7.4