[llvm] r317743 - [cfi-verify] Adds blacklist blame behaviour to cfi-verify.

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 16:18:31 PST 2017


Author: hctim
Date: Wed Nov  8 16:18:31 2017
New Revision: 317743

URL: http://llvm.org/viewvc/llvm-project?rev=317743&view=rev
Log:
[cfi-verify] Adds blacklist blame behaviour to cfi-verify.

Adds the blacklist behaviour to llvm-cfi-verify. Now will calculate which lines caused expected failures in the blacklist and reports the number of affected indirect CF instructions for each blacklist entry.

Also moved DWARF checking after instruction analysis to improve performance significantly - unrolling the inlining stack is expensive.

Reviewers: vlad.tsyrklevich

Subscribers: aprantl, pcc, kcc, llvm-commits

Differential Revision: https://reviews.llvm.org/D39750

Modified:
    llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-expected-unprotected.s
    llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-match-fun.s
    llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-unexpected-protected.s
    llvm/trunk/tools/llvm-cfi-verify/lib/FileAnalysis.cpp
    llvm/trunk/tools/llvm-cfi-verify/llvm-cfi-verify.cpp

Modified: llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-expected-unprotected.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-expected-unprotected.s?rev=317743&r1=317742&r2=317743&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-expected-unprotected.s (original)
+++ llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-expected-unprotected.s Wed Nov  8 16:18:31 2017
@@ -5,7 +5,7 @@
 
 # CHECK-LABEL: U
 # CHECK-NEXT: tiny.cc:11
-# CHECK-NEXT: BLACKLIST MATCH, 'src'
+# CHECK-NEXT: {{^Blacklist Match:.*blacklist\.txt:1$}}
 # CHECK-NEXT: ====> Expected Unprotected
 
 # CHECK: Expected Protected: 0 (0.00%)

Modified: llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-match-fun.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-match-fun.s?rev=317743&r1=317742&r2=317743&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-match-fun.s (original)
+++ llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-match-fun.s Wed Nov  8 16:18:31 2017
@@ -5,7 +5,7 @@
 
 # CHECK-LABEL: U
 # CHECK-NEXT: tiny.cc:11
-# CHECK-NEXT: BLACKLIST MATCH, 'fun'
+# CHECK-NEXT: {{^Blacklist Match:.*blacklist\.txt:1$}}
 # CHECK-NEXT: ====> Expected Unprotected
 
 # CHECK: Expected Protected: 0 (0.00%)

Modified: llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-unexpected-protected.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-unexpected-protected.s?rev=317743&r1=317742&r2=317743&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-unexpected-protected.s (original)
+++ llvm/trunk/test/tools/llvm-cfi-verify/X86/blacklist-unexpected-protected.s Wed Nov  8 16:18:31 2017
@@ -5,7 +5,7 @@
 
 # CHECK-LABEL: P
 # CHECK-NEXT: tiny.cc:11
-# CHECK-NEXT: BLACKLIST MATCH, 'src'
+# CHECK-NEXT: {{^Blacklist Match:.*blacklist\.txt:1$}}
 # CHECK-NEXT: ====> Unexpected Protected
 
 # CHECK: Expected Protected: 0 (0.00%)

Modified: llvm/trunk/tools/llvm-cfi-verify/lib/FileAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cfi-verify/lib/FileAnalysis.cpp?rev=317743&r1=317742&r2=317743&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cfi-verify/lib/FileAnalysis.cpp (original)
+++ llvm/trunk/tools/llvm-cfi-verify/lib/FileAnalysis.cpp Wed Nov  8 16:18:31 2017
@@ -370,21 +370,6 @@ void FileAnalysis::parseSectionContents(
     InstrMeta.InstructionSize = InstructionSize;
     InstrMeta.Valid = ValidInstruction;
 
-    // Check if this instruction exists in the range of the DWARF metadata.
-    if (!IgnoreDWARFFlag) {
-      auto LineInfo =
-          Symbolizer->symbolizeCode(Object->getFileName(), VMAddress);
-      if (!LineInfo) {
-        handleAllErrors(LineInfo.takeError(), [](const ErrorInfoBase &E) {
-          errs() << "Symbolizer failed to get line: " << E.message() << "\n";
-        });
-        continue;
-      }
-
-      if (LineInfo->FileName == "<invalid>")
-        continue;
-    }
-
     addInstruction(InstrMeta);
 
     if (!ValidInstruction)
@@ -406,6 +391,21 @@ void FileAnalysis::parseSectionContents(
     if (!usesRegisterOperand(InstrMeta))
       continue;
 
+    // Check if this instruction exists in the range of the DWARF metadata.
+    if (!IgnoreDWARFFlag) {
+      auto LineInfo =
+          Symbolizer->symbolizeCode(Object->getFileName(), VMAddress);
+      if (!LineInfo) {
+        handleAllErrors(LineInfo.takeError(), [](const ErrorInfoBase &E) {
+          errs() << "Symbolizer failed to get line: " << E.message() << "\n";
+        });
+        continue;
+      }
+
+      if (LineInfo->FileName == "<invalid>")
+        continue;
+    }
+
     IndirectInstructions.insert(VMAddress);
   }
 }

Modified: llvm/trunk/tools/llvm-cfi-verify/llvm-cfi-verify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cfi-verify/llvm-cfi-verify.cpp?rev=317743&r1=317742&r2=317743&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cfi-verify/llvm-cfi-verify.cpp (original)
+++ llvm/trunk/tools/llvm-cfi-verify/llvm-cfi-verify.cpp Wed Nov  8 16:18:31 2017
@@ -47,6 +47,7 @@ void printIndirectCFInstructions(FileAna
   uint64_t UnexpectedUnprotected = 0;
 
   symbolize::LLVMSymbolizer &Symbolizer = Analysis.getSymbolizer();
+  std::map<unsigned, uint64_t> BlameCounter;
 
   for (uint64_t Address : Analysis.getIndirectInstructions()) {
     const auto &InstrMeta = Analysis.getInstructionOrDie(Address);
@@ -97,20 +98,20 @@ void printIndirectCFInstructions(FileAna
       continue;
     }
 
-    bool MatchesBlacklistRule = false;
-    if (SpecialCaseList->inSection("cfi-icall", "src", LineInfo.FileName) ||
-        SpecialCaseList->inSection("cfi-vcall", "src", LineInfo.FileName)) {
-      outs() << "BLACKLIST MATCH, 'src'\n";
-      MatchesBlacklistRule = true;
+    unsigned BlameLine = 0;
+    for (auto &K : {"cfi-icall", "cfi-vcall"}) {
+      if (!BlameLine)
+        BlameLine =
+            SpecialCaseList->inSectionBlame(K, "src", LineInfo.FileName);
+      if (!BlameLine)
+        BlameLine =
+            SpecialCaseList->inSectionBlame(K, "fun", LineInfo.FunctionName);
     }
 
-    if (SpecialCaseList->inSection("cfi-icall", "fun", LineInfo.FunctionName) ||
-        SpecialCaseList->inSection("cfi-vcall", "fun", LineInfo.FunctionName)) {
-      outs() << "BLACKLIST MATCH, 'fun'\n";
-      MatchesBlacklistRule = true;
-    }
-
-    if (MatchesBlacklistRule) {
+    if (BlameLine) {
+      outs() << "Blacklist Match: " << BlacklistFilename << ":" << BlameLine
+             << "\n";
+      BlameCounter[BlameLine]++;
       if (CFIProtected) {
         UnexpectedProtected++;
         outs() << "====> Unexpected Protected\n";
@@ -149,6 +150,15 @@ void printIndirectCFInstructions(FileAna
                     ((double)ExpectedUnprotected) / IndirectCFInstructions,
                     UnexpectedUnprotected,
                     ((double)UnexpectedUnprotected) / IndirectCFInstructions);
+
+  if (!SpecialCaseList)
+    return;
+
+  outs() << "Blacklist Results:\n";
+  for (const auto &KV : BlameCounter) {
+    outs() << "  " << BlacklistFilename << ":" << KV.first << " affects "
+           << KV.second << " indirect CF instructions.\n";
+  }
 }
 
 int main(int argc, char **argv) {




More information about the llvm-commits mailing list