[SampleFDO] Allow forward compatibility when adding a new section for extbinary

format.

Currently when we add a new section in the profile format and generate a profile
containing the new section, older compiler which reads the new profile will
issue an error. The forward incompatibility can cause unnecessary churn when
extending the profile. This patch removes the incompatibility when adding a new
section for extbinary format.

Differential Revision: https://reviews.llvm.org/D109398
This commit is contained in:
Wei Mi 2021-09-07 19:33:36 -07:00
parent b0d4d969e2
commit 8eb617d719
4 changed files with 30 additions and 1 deletions

View File

@ -149,8 +149,9 @@ static inline std::string getSecName(SecType Type) {
return "CSNameTableSection";
case SecLBRProfile:
return "LBRProfileSection";
default:
return "UnknownSection";
}
llvm_unreachable("A SecType has no name for output");
}
// Entry type of section header table used by SampleProfileExtBinaryBaseReader

View File

@ -786,6 +786,8 @@ private:
virtual std::error_code verifySPMagic(uint64_t Magic) override;
virtual std::error_code
readCustomSection(const SecHdrTableEntry &Entry) override {
// Update the data reader pointer to the end of the section.
Data += Entry.Size;
return sampleprof_error::success;
};

View File

@ -0,0 +1,26 @@
RUN: llvm-profdata show -sample %S/Inputs/unknown.section.extbin.profdata | FileCheck %s
RUN: llvm-profdata show -sample -show-sec-info-only %S/Inputs/unknown.section.extbin.profdata | FileCheck %s -check-prefix=HDR
# The input unknown.section.extbin.profdata contains an unknown section type
# which uses an enum value which won't be used in the near future. Check
# llvm-profdata can read it without problem. This is to ensure adding new
# section in extbinary format for SampleFDO won't cause forward compatibility
# issue.
CHECK: Function: main: 366846, 0, 3 sampled lines
CHECK-NEXT: Samples collected in the function's body {
CHECK-NEXT: 2.1: 60401
CHECK-NEXT: 3: 0
CHECK-NEXT: 4: 0
CHECK-NEXT: }
HDR: ProfileSummarySection - Offset: 242, Size: 121, Flags: {}
HDR-NEXT: NameTableSection - Offset: 363, Size: 6, Flags: {}
HDR-NEXT: UnknownSection - Offset: 369, Size: 1, Flags: {}
HDR-NEXT: FuncOffsetTableSection - Offset: 391, Size: 3, Flags: {}
HDR-NEXT: LBRProfileSection - Offset: 370, Size: 21, Flags: {}
HDR-NEXT: ProfileSymbolListSection - Offset: 391, Size: 0, Flags: {}
HDR-NEXT: FunctionMetadata - Offset: 394, Size: 0, Flags: {}
HDR-NEXT: Header Size: 242
HDR-NEXT: Total Sections Size: 152
HDR-NEXT: File Size: 394