[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
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 9f27de9..9920c33 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -491,6 +491,13 @@
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();
}
diff --git a/llvm/test/tools/llvm-cov/Inputs/combine_expansions.covmapping b/llvm/test/tools/llvm-cov/Inputs/combine_expansions.covmapping
index 3acc1cd..744bb29 100644
--- a/llvm/test/tools/llvm-cov/Inputs/combine_expansions.covmapping
+++ b/llvm/test/tools/llvm-cov/Inputs/combine_expansions.covmapping
Binary files differ
diff --git a/llvm/test/tools/llvm-cov/Inputs/highlightedRanges.covmapping b/llvm/test/tools/llvm-cov/Inputs/highlightedRanges.covmapping
index e97320b7..5c1b1d6 100644
--- a/llvm/test/tools/llvm-cov/Inputs/highlightedRanges.covmapping
+++ b/llvm/test/tools/llvm-cov/Inputs/highlightedRanges.covmapping
Binary files differ
diff --git a/llvm/test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping b/llvm/test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping
index 9774b89..20d6abf 100644
--- a/llvm/test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping
+++ b/llvm/test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping
Binary files differ
diff --git a/llvm/test/tools/llvm-cov/Inputs/prevent_false_instantiations.covmapping b/llvm/test/tools/llvm-cov/Inputs/prevent_false_instantiations.covmapping
index cfa4e29..bbaefe5 100644
--- a/llvm/test/tools/llvm-cov/Inputs/prevent_false_instantiations.covmapping
+++ b/llvm/test/tools/llvm-cov/Inputs/prevent_false_instantiations.covmapping
Binary files differ
diff --git a/llvm/test/tools/llvm-cov/Inputs/regionMarkers.covmapping b/llvm/test/tools/llvm-cov/Inputs/regionMarkers.covmapping
index 501cba2..1c9b5dd 100644
--- a/llvm/test/tools/llvm-cov/Inputs/regionMarkers.covmapping
+++ b/llvm/test/tools/llvm-cov/Inputs/regionMarkers.covmapping
Binary files differ
diff --git a/llvm/test/tools/llvm-cov/Inputs/showExpansions.covmapping b/llvm/test/tools/llvm-cov/Inputs/showExpansions.covmapping
index e02a728..d4eb527 100644
--- a/llvm/test/tools/llvm-cov/Inputs/showExpansions.covmapping
+++ b/llvm/test/tools/llvm-cov/Inputs/showExpansions.covmapping
Binary files differ
diff --git a/llvm/test/tools/llvm-cov/Inputs/templateInstantiations.covmapping b/llvm/test/tools/llvm-cov/Inputs/templateInstantiations.covmapping
index d243736..2dfc6cd 100644
--- a/llvm/test/tools/llvm-cov/Inputs/templateInstantiations.covmapping
+++ b/llvm/test/tools/llvm-cov/Inputs/templateInstantiations.covmapping
Binary files differ
diff --git a/llvm/tools/llvm-cov/TestingSupport.cpp b/llvm/tools/llvm-cov/TestingSupport.cpp
index f6c91f8..a662a15 100644
--- a/llvm/tools/llvm-cov/TestingSupport.cpp
+++ b/llvm/tools/llvm-cov/TestingSupport.cpp
@@ -88,7 +88,11 @@
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;
}