[PATCH] D20285: [Coverage] Ensure that coverage mapping data has an expected alignment in 'covmapping' files.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 07:18:39 PDT 2016


ikudrin created this revision.
ikudrin added reviewers: bogner, davidxl, vsk.
ikudrin added a subscriber: llvm-commits.

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.

http://reviews.llvm.org/D20285

Files:
  lib/ProfileData/Coverage/CoverageMappingReader.cpp
  test/tools/llvm-cov/Inputs/combine_expansions.covmapping
  test/tools/llvm-cov/Inputs/highlightedRanges.covmapping
  test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping
  test/tools/llvm-cov/Inputs/prevent_false_instantiations.covmapping
  test/tools/llvm-cov/Inputs/regionMarkers.covmapping
  test/tools/llvm-cov/Inputs/showExpansions.covmapping
  test/tools/llvm-cov/Inputs/templateInstantiations.covmapping
  tools/llvm-cov/TestingSupport.cpp

Index: tools/llvm-cov/TestingSupport.cpp
===================================================================
--- tools/llvm-cov/TestingSupport.cpp
+++ 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;
 }
Index: lib/ProfileData/Coverage/CoverageMappingReader.cpp
===================================================================
--- lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ 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::malformed;
+  size_t Pad = alignmentAdjustment(CoverageMapping.data(), 8);
+  if (CoverageMapping.size() < Pad)
+    return coveragemap_error::malformed;
+  CoverageMapping = CoverageMapping.substr(Pad);
   return std::error_code();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20285.57341.patch
Type: text/x-patch
Size: 1410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160516/b7595ec5/attachment.bin>


More information about the llvm-commits mailing list