For llvm-objdump, add the option -private-header (without the trailing ā€™sā€™)
[oota-llvm.git] / lib / ProfileData / CoverageMappingReader.cpp
index 3f59136d08877f0561b42a2db3ccf71c8628b3ea..aa794b080bb7ae434e94db1d6b1ef7668a44cc1a 100644 (file)
@@ -307,7 +307,7 @@ StringRef InstrProfSymtab::getFuncName(uint64_t Pointer, size_t Size) {
 }
 
 template <typename T, support::endianness Endian>
-std::error_code readCoverageMappingData(
+static std::error_code readCoverageMappingData(
     InstrProfSymtab &ProfileNames, StringRef Data,
     std::vector<BinaryCoverageReader::ProfileMappingRecord> &Records,
     std::vector<StringRef> &Filenames) {
@@ -316,19 +316,17 @@ std::error_code readCoverageMappingData(
 
   // Read the records in the coverage data section.
   for (const char *Buf = Data.data(), *End = Buf + Data.size(); Buf < End;) {
-    if (Buf + 4 * sizeof(uint32_t) > End)
+    if (Buf + sizeof(CovMapHeader) > End)
       return coveragemap_error::malformed;
-    uint32_t NRecords = endian::readNext<uint32_t, Endian, unaligned>(Buf);
-    uint32_t FilenamesSize = endian::readNext<uint32_t, Endian, unaligned>(Buf);
-    uint32_t CoverageSize = endian::readNext<uint32_t, Endian, unaligned>(Buf);
-    uint32_t Version = endian::readNext<uint32_t, Endian, unaligned>(Buf);
-
-    switch (Version) {
-    case CoverageMappingVersion1:
-      break;
-    default:
+    auto CovHeader = reinterpret_cast<const coverage::CovMapHeader *>(Buf);
+    uint32_t NRecords = CovHeader->getNRecords<Endian>();
+    uint32_t FilenamesSize = CovHeader->getFilenamesSize<Endian>();
+    uint32_t CoverageSize = CovHeader->getCoverageSize<Endian>();
+    uint32_t Version = CovHeader->getVersion<Endian>();
+    Buf = reinterpret_cast<const char *>(++CovHeader);
+
+    if (Version > coverage::CoverageMappingCurrentVersion)
       return coveragemap_error::unsupported_version;
-    }
 
     // Skip past the function records, saving the start and end for later.
     const char *FunBuf = Buf;
@@ -359,11 +357,8 @@ std::error_code readCoverageMappingData(
         reinterpret_cast<const coverage::CovMapFunctionRecord<T> *>(FunBuf);
     while ((const char *)CFR < FunEnd) {
       // Read the function information
-      T NamePtr = endian::byte_swap<T, Endian>(CFR->NamePtr);
-      uint32_t NameSize = endian::byte_swap<uint32_t, Endian>(CFR->NameSize);
-      uint32_t DataSize = endian::byte_swap<uint32_t, Endian>(CFR->DataSize);
-      uint64_t FuncHash = endian::byte_swap<uint64_t, Endian>(CFR->FuncHash);
-      CFR++;
+      uint32_t DataSize = CFR->template getDataSize<Endian>();
+      uint64_t FuncHash = CFR->template getFuncHash<Endian>();
 
       // Now use that to read the coverage data.
       if (CovBuf + DataSize > CovEnd)
@@ -374,16 +369,18 @@ std::error_code readCoverageMappingData(
       // Ignore this record if we already have a record that points to the same
       // function name. This is useful to ignore the redundant records for the
       // functions with ODR linkage.
-      if (!UniqueFunctionMappingData.insert(NamePtr).second)
+      T NameRef = CFR->template getFuncNameRef<Endian>();
+      if (!UniqueFunctionMappingData.insert(NameRef).second)
         continue;
 
-      // Finally, grab the name and create a record.
-      StringRef FuncName = ProfileNames.getFuncName(NamePtr, NameSize);
-      if (NameSize && FuncName.empty())
-        return coveragemap_error::malformed;
+      StringRef FuncName;
+      if (std::error_code EC =
+          CFR->template getFuncName<Endian>(ProfileNames, FuncName))
+        return EC;
       Records.push_back(BinaryCoverageReader::ProfileMappingRecord(
           CoverageMappingVersion(Version), FuncName, FuncHash, Mapping,
           FilenamesBegin, Filenames.size() - FilenamesBegin));
+      CFR++;
     }
   }