Skip to content

Commit 0f22fac

Browse files
committedAug 14, 2018
[SanitizerCoverage] Add associated metadata to PC guards.
Summary: Without this metadata LLD strips unused PC table entries but won't strip unused guards. This metadata also seems to influence the linker to change the ordering in the PC guard section to match that of the PC table section. The libFuzzer runtime library depends on the ordering of the PC table and PC guard sections being the same. This is not generally guaranteed, so we may need to redesign PC tables/guards/counters in the future. Reviewers: eugenis Reviewed By: eugenis Subscribers: kcc, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D50483 llvm-svn: 339733
1 parent cd4056c commit 0f22fac

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎compiler-rt/test/fuzzer/gc-sections.test

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ With gc-sections. Currently, we can't remove unused code except with LLD.
88
RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -fuse-ld=lld -ffunction-sections -Wl,-gc-sections
99
RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker
1010
RUN: %run %t -runs=0 2>&1 | FileCheck %s
11-
CHECK-NOT: ERROR: The size of coverage PC tables does not match
1211

1312
With gc sections, with trace-pc. Unused code is removed.
1413
RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -fsanitize-coverage=0 -fsanitize-coverage=trace-pc -ffunction-sections -Wl,-gc-sections
1514
RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker
15+
16+
RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard,pc-table -fuse-ld=lld -ffunction-sections -Wl,-gc-sections
17+
RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker
18+
RUN: %run %t -runs=0 2>&1 | FileCheck %s
19+
20+
CHECK-NOT: ERROR: The size of coverage PC tables does not match

‎llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,9 @@ void SanitizerCoverageModule::CreateFunctionLocalArrays(
591591
FunctionGuardArray = CreateFunctionLocalArrayInSection(
592592
AllBlocks.size(), F, Int32Ty, SanCovGuardsSectionName);
593593
GlobalsToAppendToUsed.push_back(FunctionGuardArray);
594+
GlobalsToAppendToCompilerUsed.push_back(FunctionGuardArray);
595+
MDNode *MD = MDNode::get(F.getContext(), ValueAsMetadata::get(&F));
596+
FunctionGuardArray->addMetadata(LLVMContext::MD_associated, *MD);
594597
}
595598
if (Options.Inline8bitCounters) {
596599
Function8bitCounterArray = CreateFunctionLocalArrayInSection(

0 commit comments

Comments
 (0)
Please sign in to comment.