[PATCH] D49264: [SanitizerCoverage] Add associated metadata to 8-bit counters.

Matt Morehouse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 12 12:31:09 PDT 2018


morehouse created this revision.
morehouse added a reviewer: eugenis.
Herald added a subscriber: hiraditya.

This allows counters associated with unused functions to be
dead-stripped along with their functions.  This approach is the same one
we used for PC tables.

Fixes an issue where LLD removes an unused PC table but leaves the 8-bit
counter.


https://reviews.llvm.org/D49264

Files:
  compiler-rt/test/fuzzer/gc-sections.test
  llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp


Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -595,7 +595,9 @@
   if (Options.Inline8bitCounters) {
     Function8bitCounterArray = CreateFunctionLocalArrayInSection(
         AllBlocks.size(), F, Int8Ty, SanCovCountersSectionName);
-    GlobalsToAppendToUsed.push_back(Function8bitCounterArray);
+    GlobalsToAppendToCompilerUsed.push_back(Function8bitCounterArray);
+    MDNode *MD = MDNode::get(F.getContext(), ValueAsMetadata::get(&F));
+    Function8bitCounterArray->addMetadata(LLVMContext::MD_associated, *MD);
   }
   if (Options.PCTable) {
     FunctionPCsArray = CreatePCArray(F, AllBlocks);
Index: compiler-rt/test/fuzzer/gc-sections.test
===================================================================
--- compiler-rt/test/fuzzer/gc-sections.test
+++ compiler-rt/test/fuzzer/gc-sections.test
@@ -4,9 +4,11 @@
 RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t
 RUN: nm %t | grep UnusedFunctionShouldBeRemovedByLinker | count 1
 
-With gc-sections. Currently, we can't remove unused code.
+With gc-sections. Currently, we can't remove unused code except with LLD.
 RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -fuse-ld=lld -ffunction-sections -Wl,-gc-sections
 RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker
+RUN: %run %t -runs=0 2>&1 | FileCheck %s
+CHECK-NOT: ERROR: The size of coverage PC tables does not match
 
 With gc sections, with trace-pc. Unused code is removed.
 RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -fsanitize-coverage=0 -fsanitize-coverage=trace-pc -ffunction-sections -Wl,-gc-sections


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49264.155252.patch
Type: text/x-patch
Size: 1753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180712/73d9a94f/attachment.bin>


More information about the llvm-commits mailing list