[llvm] r255582 - sancov: coverage can be reported by multiple functions.

Mike Aizatsky via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 14 15:55:05 PST 2015


Author: aizatsky
Date: Mon Dec 14 17:55:04 2015
New Revision: 255582

URL: http://llvm.org/viewvc/llvm-project?rev=255582&view=rev
Log:
sancov: coverage can be reported by multiple functions.

Differential Revision: http://reviews.llvm.org/D15430

Modified:
    llvm/trunk/tools/sancov/sancov.cc

Modified: llvm/trunk/tools/sancov/sancov.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/sancov.cc?rev=255582&r1=255581&r2=255582&view=diff
==============================================================================
--- llvm/trunk/tools/sancov/sancov.cc (original)
+++ llvm/trunk/tools/sancov/sancov.cc Mon Dec 14 17:55:04 2015
@@ -207,21 +207,30 @@ std::set<FunctionLoc> computeFunctionLoc
   return result;
 }
 
-// Locate __sanitizer_cov function address.
-static uint64_t findSanitizerCovFunction(const object::ObjectFile &O) {
+// Locate __sanitizer_cov* function addresses that are used for coverage
+// reporting.
+static std::set<uint64_t>
+findSanitizerCovFunctions(const object::ObjectFile &O) {
+  std::set<uint64_t> Result;
+
   for (const object::SymbolRef &Symbol : O.symbols()) {
     ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
     FailIfError(AddressOrErr);
 
-    ErrorOr<StringRef> Name = Symbol.getName();
-    FailIfError(Name);
-
-    if (Name.get() == "__sanitizer_cov") {
-      return AddressOrErr.get();
+    ErrorOr<StringRef> NameOrErr = Symbol.getName();
+    FailIfError(NameOrErr);
+    StringRef Name = NameOrErr.get();
+
+    if (Name == "__sanitizer_cov" || Name == "__sanitizer_cov_with_check" ||
+        Name == "__sanitizer_cov_trace_func_enter") {
+      Result.insert(AddressOrErr.get());
     }
   }
-  FailIfNotEmpty("__sanitizer_cov not found");
-  return 0; // not reachable.
+
+  if (Result.empty())
+    FailIfNotEmpty("__sanitizer_cov* functions not found");
+
+  return Result;
 }
 
 // Locate addresses of all coverage points in a file. Coverage point
@@ -262,7 +271,7 @@ static void getObjectCoveragePoints(cons
       TheTarget->createMCInstrAnalysis(MII.get()));
   FailIfEmpty(MIA, "no instruction analysis info for target " + TripleName);
 
-  uint64_t SanCovAddr = findSanitizerCovFunction(O);
+  auto SanCovAddrs = findSanitizerCovFunctions(O);
 
   for (const auto Section : O.sections()) {
     if (Section.isVirtual() || !Section.isText()) // llvm-objdump does the same.
@@ -292,7 +301,7 @@ static void getObjectCoveragePoints(cons
       uint64_t Target;
       if (MIA->isCall(Inst) &&
           MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) {
-        if (Target == SanCovAddr) {
+        if (SanCovAddrs.find(Target) != SanCovAddrs.end()) {
           // Sanitizer coverage uses the address of the next instruction - 1.
           Addrs->insert(Index + SectionAddr + Size - 1);
         }




More information about the llvm-commits mailing list