llvm.org GIT mirror llvm / 24466cd
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269887 91177308-0d34-0410-b5e6-96231b3b80d8 Igor Kudrin 4 years ago
9 changed file(s) with 12 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
490490 return coveragemap_error::malformed;
491491 ProfileNames.create(Data.substr(0, ProfileNamesSize), Address);
492492 CoverageMapping = Data.substr(ProfileNamesSize);
493 // Skip the padding bytes because coverage map data has an alignment of 8.
494 if (CoverageMapping.size() < 1)
495 return coveragemap_error::truncated;
496 size_t Pad = alignmentAdjustment(CoverageMapping.data(), 8);
497 if (CoverageMapping.size() < Pad)
498 return coveragemap_error::malformed;
499 CoverageMapping = CoverageMapping.substr(Pad);
493500 return std::error_code();
494501 }
495502
8787 OS << "llvmcovmtestdata";
8888 encodeULEB128(ProfileNamesData.size(), OS);
8989 encodeULEB128(ProfileNamesAddress, OS);
90 OS << ProfileNamesData << CoverageMappingData;
90 OS << ProfileNamesData;
91 // Coverage mapping data is expected to have an alignment of 8.
92 for (unsigned Pad = OffsetToAlignment(OS.tell(), 8); Pad; --Pad)
93 OS.write(uint8_t(0));
94 OS << CoverageMappingData;
9195
9296 return 0;
9397 }