summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Morehouse <mascasa@google.com>2018-07-12 20:24:58 +0000
committerMatt Morehouse <mascasa@google.com>2018-07-12 20:24:58 +0000
commit45438161503f1688ed4af9ffda626b5c79454781 (patch)
tree46dd5400322fba0e73ce5db7263cd062a8219302
parent94259ba13af6ba594fc1bd17611f15511d1730c0 (diff)
downloadbcm5719-llvm-45438161503f1688ed4af9ffda626b5c79454781.tar.gz
bcm5719-llvm-45438161503f1688ed4af9ffda626b5c79454781.zip
[SanitizerCoverage] Add associated metadata to 8-bit counters.
Summary: 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. Reviewers: eugenis Reviewed By: eugenis Subscribers: llvm-commits, hiraditya, kcc Differential Revision: https://reviews.llvm.org/D49264 llvm-svn: 336941
-rw-r--r--compiler-rt/test/fuzzer/gc-sections.test4
-rw-r--r--llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp4
2 files changed, 6 insertions, 2 deletions
diff --git a/compiler-rt/test/fuzzer/gc-sections.test b/compiler-rt/test/fuzzer/gc-sections.test
index 7bc2f831b42..b8abfbbdf17 100644
--- a/compiler-rt/test/fuzzer/gc-sections.test
+++ b/compiler-rt/test/fuzzer/gc-sections.test
@@ -4,9 +4,11 @@ No gc-sections:
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
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index a9336381edd..a4dd48c8dd6 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -595,7 +595,9 @@ void SanitizerCoverageModule::CreateFunctionLocalArrays(
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);
OpenPOWER on IntegriCloud