[PATCH] D16212: Fix reading gcov data that does not have function names

Arseny Kapoulkine via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 20:59:34 PST 2016


arseny.kapoulkine created this revision.
arseny.kapoulkine added a reviewer: bogner.
arseny.kapoulkine added a subscriber: llvm-commits.

In order for recent gcov versions to read the coverage data, you have to use UseCfgChecksum=true and FunctionNamesInData=false options for coverage profiling pass. This is because gcov is expecting the function section in .gcda to be exactly 3 words in size, containing ident and two checksums.

While llvm-cov is compatible with UseCfgChecksum=true, it always expects a function name in .gcda function sections (it's not compatible with FunctionNamesInData=false). Thus it's currently impossible to generate one set of coverage files that works with both gcov and llvm-cov.

This change fixes the reading of coverage information to only read the function name if it's present.

http://reviews.llvm.org/D16212

Files:
  lib/IR/GCOV.cpp

Index: lib/IR/GCOV.cpp
===================================================================
--- lib/IR/GCOV.cpp
+++ lib/IR/GCOV.cpp
@@ -247,10 +247,22 @@
 /// readGCDA - Read a function from the GCDA buffer. Return false if an error
 /// occurs.
 bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
-  uint32_t Dummy;
-  if (!Buff.readInt(Dummy))
+  uint32_t HeaderLength;
+  if (!Buff.readInt(HeaderLength))
     return false; // Function header length
 
+  uint32_t MinHeaderLength = 2;
+
+  if (Version != GCOV::V402) {
+    MinHeaderLength++; // CfgChecksum
+  }
+
+  if (HeaderLength < MinHeaderLength) {
+    errs() << "Function header is invalid: expected " << MinHeaderLength
+           << " words, got " << HeaderLength << " (in " << Name << ").\n";
+    return false;
+  }
+
   uint32_t GCDAIdent;
   if (!Buff.readInt(GCDAIdent))
     return false;
@@ -280,13 +292,15 @@
     }
   }
 
-  StringRef GCDAName;
-  if (!Buff.readString(GCDAName))
-    return false;
-  if (Name != GCDAName) {
-    errs() << "Function names do not match: " << Name << " != " << GCDAName
-           << ".\n";
-    return false;
+  if (MinHeaderLength < HeaderLength) {
+    StringRef GCDAName;
+    if (!Buff.readString(GCDAName))
+      return false;
+    if (Name != GCDAName) {
+      errs() << "Function names do not match: " << Name << " != " << GCDAName
+             << ".\n";
+      return false;
+    }
   }
 
   if (!Buff.readArcTag()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16212.44954.patch
Type: text/x-patch
Size: 1461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160115/cabe5872/attachment.bin>


More information about the llvm-commits mailing list