[llvm] r309646 - [libFuzzer] enable -fsanitize-coverage=pc-table for all tests

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 17:48:44 PDT 2017


Author: kcc
Date: Mon Jul 31 17:48:44 2017
New Revision: 309646

URL: http://llvm.org/viewvc/llvm-project?rev=309646&view=rev
Log:
[libFuzzer] enable -fsanitize-coverage=pc-table for all tests

Modified:
    llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
    llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
    llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/inline-8bit-counters.test

Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=309646&r1=309645&r2=309646&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Mon Jul 31 17:48:44 2017
@@ -72,7 +72,7 @@ void TracePC::HandlePCsInit(const uint8_
   if (NumPCTables && ModulePCTable[NumPCTables - 1].Start == B) return;
   assert(NumPCTables < sizeof(ModulePCTable) / sizeof(ModulePCTable[0]));
   ModulePCTable[NumPCTables++] = {B, E};
-  NumPCsInPCTables = E - B;
+  NumPCsInPCTables += E - B;
 }
 
 void TracePC::HandleInit(uint32_t *Start, uint32_t *Stop) {
@@ -95,26 +95,36 @@ void TracePC::HandleInit(uint32_t *Start
 
 void TracePC::PrintModuleInfo() {
   if (NumGuards) {
-    Printf("INFO: Loaded %zd modules (%zd guards): ", NumModules, NumGuards);
+    Printf("INFO: Loaded %zd modules   (%zd guards): ", NumModules, NumGuards);
     for (size_t i = 0; i < NumModules; i++)
-      Printf("[%p, %p), ", Modules[i].Start, Modules[i].Stop);
+      Printf("%zd [%p, %p), ", Modules[i].Stop - Modules[i].Start,
+             Modules[i].Start, Modules[i].Stop);
     Printf("\n");
   }
   if (NumModulesWithInline8bitCounters) {
-    Printf("INFO: Loaded %zd modules with %zd inline 8-bit counters: ",
+    Printf("INFO: Loaded %zd modules   (%zd inline 8-bit counters): ",
            NumModulesWithInline8bitCounters, NumInline8bitCounters);
     for (size_t i = 0; i < NumModulesWithInline8bitCounters; i++)
-      Printf("[%p, %p), ", ModuleCounters[i].Start, ModuleCounters[i].Stop);
+      Printf("%zd [%p, %p), ", ModuleCounters[i].Stop - ModuleCounters[i].Start,
+             ModuleCounters[i].Start, ModuleCounters[i].Stop);
     Printf("\n");
   }
   if (NumPCTables) {
-    Printf("INFO: Loaded %zd PC tables,   %zd PCs: ", NumPCTables,
+    Printf("INFO: Loaded %zd PC tables (%zd PCs): ", NumPCTables,
            NumPCsInPCTables);
     for (size_t i = 0; i < NumPCTables; i++) {
-      Printf("[%p,%p), ", ModulePCTable[i].Start, ModulePCTable[i].Stop,
-             ModulePCTable[i].Stop - ModulePCTable[i].Start);
+      Printf("%zd [%p,%p), ", ModulePCTable[i].Stop - ModulePCTable[i].Start,
+             ModulePCTable[i].Start, ModulePCTable[i].Stop);
     }
     Printf("\n");
+
+    if ((NumGuards && NumGuards != NumPCsInPCTables) ||
+        (NumInline8bitCounters && NumInline8bitCounters != NumPCsInPCTables)) {
+      Printf("ERROR: The size of coverage PC tables does not match the"
+             " number of instrumented PCs. This might be a bug in the compiler,"
+             " please contact the libFuzzer developers.\n");
+      _Exit(1);
+    }
   }
 }
 

Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=309646&r1=309645&r2=309646&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Mon Jul 31 17:48:44 2017
@@ -86,7 +86,8 @@ class TracePC {
 
   void ResetMaps() {
     ValueProfileMap.Reset();
-    memset(Counters(), 0, GetNumPCs());
+    if (NumModules)
+      memset(Counters(), 0, GetNumPCs());
     ClearExtraCounters();
     ClearInlineCounters();
   }

Modified: llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/CMakeLists.txt?rev=309646&r1=309645&r2=309646&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/CMakeLists.txt Mon Jul 31 17:48:44 2017
@@ -15,7 +15,7 @@ foreach (VARNAME ${variables_to_filter})
 endforeach()
 
 # Enable the coverage instrumentation (it is disabled for the Fuzzer lib).
-set(CMAKE_CXX_FLAGS "${LIBFUZZER_FLAGS_BASE} -fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp,trace-div,trace-gep -gline-tables-only")
+set(CMAKE_CXX_FLAGS "${LIBFUZZER_FLAGS_BASE} -fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp,trace-div,trace-gep,pc-table -gline-tables-only")
 
 if(MSVC)
   # For tests use the CRT specified for release build

Modified: llvm/trunk/lib/Fuzzer/test/inline-8bit-counters.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/inline-8bit-counters.test?rev=309646&r1=309645&r2=309646&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/inline-8bit-counters.test (original)
+++ llvm/trunk/lib/Fuzzer/test/inline-8bit-counters.test Mon Jul 31 17:48:44 2017
@@ -1,4 +1,4 @@
 REQUIRES: linux
-CHECK: INFO: Loaded 1 modules with {{.*}} inline 8-bit counters
+CHECK: INFO: Loaded 1 modules ({{.*}} inline 8-bit counters)
 CHECK: BINGO
 RUN: not LLVMFuzzer-SimpleTest-Inline8bitCounters -runs=1000000 -seed=1 2>&1 | FileCheck %s




More information about the llvm-commits mailing list