From ce98452516bc0a743243dc83c04f442db29d2bed Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Tue, 3 Jun 2014 15:27:15 +0000 Subject: [PATCH] [sancov] Delay opening dump file until the first module constructor. llvm-svn: 210109 --- .../lib/sanitizer_common/sanitizer_coverage_libcdep.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc index 0094c61..e0f021f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc @@ -85,12 +85,12 @@ class CoverageData { int pc_fd; StaticSpinMutex mu; - void DirectInit(); + void DirectOpen(); }; static CoverageData coverage_data; -void CoverageData::DirectInit() { +void CoverageData::DirectOpen() { InternalScopedString path(1024); internal_snprintf((char *)path.data(), path.size(), "%s/%zd.sancov.raw", common_flags()->coverage_dir, internal_getpid()); @@ -100,9 +100,7 @@ void CoverageData::DirectInit() { Die(); } - atomic_store(&pc_array_size, 0, memory_order_relaxed); pc_array_mapped_size = 0; - CovUpdateMapping(); } @@ -110,20 +108,23 @@ void CoverageData::Init() { pc_array = reinterpret_cast( MmapNoReserveOrDie(sizeof(uptr) * kPcArrayMaxSize, "CovInit")); if (common_flags()->coverage_direct) { - DirectInit(); + atomic_store(&pc_array_size, 0, memory_order_relaxed); + atomic_store(&pc_array_index, 0, memory_order_relaxed); } else { pc_fd = 0; atomic_store(&pc_array_size, kPcArrayMaxSize, memory_order_relaxed); + atomic_store(&pc_array_index, 0, memory_order_relaxed); } } // Extend coverage PC array to fit additional npcs elements. void CoverageData::Extend(uptr npcs) { - // If pc_fd=0, pc array is a huge anonymous mapping that does not need to be - // resized. - if (!pc_fd) return; + if (!common_flags()->coverage_direct) return; SpinMutexLock l(&mu); + if (!pc_fd) DirectOpen(); + CHECK(pc_fd); + uptr size = atomic_load(&pc_array_size, memory_order_relaxed); size += npcs * sizeof(uptr); -- 2.7.4