[llvm] r311959 - [sanitizer-coverage] Mark the guard and 8-bit counter arrays as used

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 17:11:06 PDT 2017


Author: bogner
Date: Mon Aug 28 17:11:05 2017
New Revision: 311959

URL: http://llvm.org/viewvc/llvm-project?rev=311959&view=rev
Log:
[sanitizer-coverage] Mark the guard and 8-bit counter arrays as used

In r311742 we marked the PCs array as used so it wouldn't be dead
stripped, but left the guard and 8-bit counters arrays alone since
these are referenced by the coverage instrumentation. This doesn't
quite work if we want the indices of the PCs array to match the other
arrays though, since elements can still end up being dead and
disappear.

Instead, we mark all three of these arrays as used so that they'll be
consistent with one another.

Modified:
    llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Modified: llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp?rev=311959&r1=311958&r2=311959&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp Mon Aug 28 17:11:05 2017
@@ -566,23 +566,30 @@ SanitizerCoverageModule::CreatePCArray(F
       ConstantArray::get(ArrayType::get(IntptrPtrTy, N * 2), PCs));
   PCArray->setConstant(true);
 
-  // We don't reference the PCs array in any of our runtime functions, so we
-  // need to prevent it from being dead stripped.
-  appendToUsed(*F.getParent(), {PCArray});
-
   return PCArray;
 }
 
 void SanitizerCoverageModule::CreateFunctionLocalArrays(
     Function &F, ArrayRef<BasicBlock *> AllBlocks) {
-  if (Options.TracePCGuard)
+  SmallVector<GlobalValue *, 3> LocalArrays;
+  if (Options.TracePCGuard) {
     FunctionGuardArray = CreateFunctionLocalArrayInSection(
         AllBlocks.size(), F, Int32Ty, SanCovGuardsSectionName);
-  if (Options.Inline8bitCounters)
+    LocalArrays.push_back(FunctionGuardArray);
+  }
+  if (Options.Inline8bitCounters) {
     Function8bitCounterArray = CreateFunctionLocalArrayInSection(
         AllBlocks.size(), F, Int8Ty, SanCovCountersSectionName);
-  if (Options.PCTable)
+    LocalArrays.push_back(Function8bitCounterArray);
+  }
+  if (Options.PCTable) {
     FunctionPCsArray = CreatePCArray(F, AllBlocks);
+    LocalArrays.push_back(FunctionPCsArray);
+  }
+
+  // We don't reference these arrays directly in any of our runtime functions,
+  // so we need to prevent them from being dead stripped.
+  appendToUsed(*F.getParent(), LocalArrays);
 }
 
 bool SanitizerCoverageModule::InjectCoverage(Function &F,




More information about the llvm-commits mailing list