forked from OSchip/llvm-project
[Coverage] Ensure that coverage mapping data has an expected alignment in 'covmapping' files.
Coverage mapping data is organized in a sequence of blocks, each of which is expected to be aligned by 8 bytes. This feature is used when reading those blocks, see VersionedCovMapFuncRecordReader::readFunctionRecords(). If a misaligned covearge mapping data has more than one block, it causes llvm-cov to fail. Differential Revision: http://reviews.llvm.org/D20285 llvm-svn: 269887
This commit is contained in:
parent
095fc41523
commit
eb10307347
|
@ -491,6 +491,13 @@ static std::error_code loadTestingFormat(StringRef Data,
|
|||
return coveragemap_error::malformed;
|
||||
ProfileNames.create(Data.substr(0, ProfileNamesSize), Address);
|
||||
CoverageMapping = Data.substr(ProfileNamesSize);
|
||||
// Skip the padding bytes because coverage map data has an alignment of 8.
|
||||
if (CoverageMapping.size() < 1)
|
||||
return coveragemap_error::truncated;
|
||||
size_t Pad = alignmentAdjustment(CoverageMapping.data(), 8);
|
||||
if (CoverageMapping.size() < Pad)
|
||||
return coveragemap_error::malformed;
|
||||
CoverageMapping = CoverageMapping.substr(Pad);
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -88,7 +88,11 @@ int convertForTestingMain(int argc, const char *argv[]) {
|
|||
OS << "llvmcovmtestdata";
|
||||
encodeULEB128(ProfileNamesData.size(), OS);
|
||||
encodeULEB128(ProfileNamesAddress, OS);
|
||||
OS << ProfileNamesData << CoverageMappingData;
|
||||
OS << ProfileNamesData;
|
||||
// Coverage mapping data is expected to have an alignment of 8.
|
||||
for (unsigned Pad = OffsetToAlignment(OS.tell(), 8); Pad; --Pad)
|
||||
OS.write(uint8_t(0));
|
||||
OS << CoverageMappingData;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue