OSDN Git Service

[sanitizer-coverage] Make sure pc-tables aren't dead stripped
authorJustin Bogner <mail@justinbogner.com>
Fri, 25 Aug 2017 01:24:54 +0000 (01:24 +0000)
committerJustin Bogner <mail@justinbogner.com>
Fri, 25 Aug 2017 01:24:54 +0000 (01:24 +0000)
Add a reference to the PC array in llvm.used so that linkers that
aggressively dead strip (like ld64) don't remove it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311742 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/SanitizerCoverage.cpp

index c6f0d17..fdf2651 100644 (file)
@@ -557,6 +557,10 @@ void SanitizerCoverageModule::CreatePCArray(Function &F,
   FunctionPCsArray->setInitializer(
       ConstantArray::get(ArrayType::get(Int8PtrTy, N), PCs));
   FunctionPCsArray->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(), {FunctionPCsArray});
 }
 
 void SanitizerCoverageModule::CreateFunctionLocalArrays(