forked from OSchip/llvm-project
[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
This commit is contained in:
parent
cd4056c881
commit
0f22fac274
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue