1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[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:
Igor Kudrin 2016-05-18 07:43:27 +00:00
parent a0fa384ff9
commit 5a4a55829a
9 changed files with 12 additions and 1 deletions

View File

@ -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();
}

View File

@ -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;
}