Skip to content

Commit

Permalink
[SanitizerCoverage] Add associated metadata to PC guards.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
morehouse committed Aug 14, 2018
1 parent cd4056c commit 0f22fac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler-rt/test/fuzzer/gc-sections.test
Expand Up @@ -8,8 +8,13 @@ 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
RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker

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
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
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Expand Up @@ -591,6 +591,9 @@ void SanitizerCoverageModule::CreateFunctionLocalArrays(
FunctionGuardArray = CreateFunctionLocalArrayInSection(
AllBlocks.size(), F, Int32Ty, SanCovGuardsSectionName);
GlobalsToAppendToUsed.push_back(FunctionGuardArray);
GlobalsToAppendToCompilerUsed.push_back(FunctionGuardArray);
MDNode *MD = MDNode::get(F.getContext(), ValueAsMetadata::get(&F));
FunctionGuardArray->addMetadata(LLVMContext::MD_associated, *MD);
}
if (Options.Inline8bitCounters) {
Function8bitCounterArray = CreateFunctionLocalArrayInSection(
Expand Down

0 comments on commit 0f22fac

Please sign in to comment.