[compiler-rt] r336234 - [libFuzzer] add one more value profile metric, under a flag (experimental)

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 3 15:33:09 PDT 2018


Author: kcc
Date: Tue Jul  3 15:33:09 2018
New Revision: 336234

URL: http://llvm.org/viewvc/llvm-project?rev=336234&view=rev
Log:
[libFuzzer] add one more value profile metric, under a flag (experimental)

Added:
    compiler-rt/trunk/test/fuzzer/three-bytes.test
Modified:
    compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp
    compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h
    compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp
    compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h
    compiler-rt/trunk/test/fuzzer/ShrinkValueProfileTest.cpp

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp?rev=336234&r1=336233&r2=336234&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp Tue Jul  3 15:33:09 2018
@@ -148,7 +148,7 @@ Fuzzer::Fuzzer(UserCallback CB, InputCor
   if (Options.DetectLeaks && EF->__sanitizer_install_malloc_and_free_hooks)
     EF->__sanitizer_install_malloc_and_free_hooks(MallocHook, FreeHook);
   TPC.SetUseCounters(Options.UseCounters);
-  TPC.SetUseValueProfile(Options.UseValueProfile);
+  TPC.SetUseValueProfileMask(Options.UseValueProfile);
 
   if (Options.Verbosity)
     TPC.PrintModuleInfo();

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h?rev=336234&r1=336233&r2=336234&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerOptions.h Tue Jul  3 15:33:09 2018
@@ -31,7 +31,7 @@ struct FuzzingOptions {
   bool UseCounters = false;
   bool UseMemmem = true;
   bool UseCmp = false;
-  bool UseValueProfile = false;
+  int UseValueProfile = false;
   bool Shrink = false;
   bool ReduceInputs = false;
   int ReloadIntervalSec = 1;

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp?rev=336234&r1=336233&r2=336234&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp Tue Jul  3 15:33:09 2018
@@ -356,7 +356,14 @@ void TracePC::HandleCmp(uintptr_t PC, T
       TORC4.Insert(ArgXor, Arg1, Arg2);
   else if (sizeof(T) == 8)
       TORC8.Insert(ArgXor, Arg1, Arg2);
-  ValueProfileMap.AddValue(Idx);
+  // TODO: remove these flags and instead use all metrics at once.
+  if (UseValueProfileMask & 1)
+    ValueProfileMap.AddValue(Idx);
+  if (UseValueProfileMask & 2)
+    ValueProfileMap.AddValue(
+        PC * 64 + (Arg1 == Arg2 ? 0 : __builtin_clzll(Arg1 - Arg2) + 1));
+  if (UseValueProfileMask & 4)  // alternative way to use the hamming distance
+    ValueProfileMap.AddValue(PC * 64 + ArgDistance);
 }
 
 static size_t InternalStrnlen(const char *S, size_t MaxLen) {

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h?rev=336234&r1=336233&r2=336234&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h Tue Jul  3 15:33:09 2018
@@ -80,7 +80,7 @@ class TracePC {
   template <class T> void HandleCmp(uintptr_t PC, T Arg1, T Arg2);
   size_t GetTotalPCCoverage();
   void SetUseCounters(bool UC) { UseCounters = UC; }
-  void SetUseValueProfile(bool VP) { UseValueProfile = VP; }
+  void SetUseValueProfileMask(uint32_t VPMask) { UseValueProfileMask = VPMask; }
   void SetPrintNewPCs(bool P) { DoPrintNewPCs = P; }
   void SetPrintNewFuncs(size_t P) { NumPrintNewFuncs = P; }
   void UpdateObservedPCs();
@@ -137,7 +137,7 @@ class TracePC {
 
 private:
   bool UseCounters = false;
-  bool UseValueProfile = false;
+  uint32_t UseValueProfileMask = false;
   bool DoPrintNewPCs = false;
   size_t NumPrintNewFuncs = 0;
 
@@ -260,7 +260,7 @@ void TracePC::CollectFeatures(Callback H
                      Handle8bitCounter);
   FirstFeature += (ExtraCountersEnd() - ExtraCountersBegin()) * 8;
 
-  if (UseValueProfile) {
+  if (UseValueProfileMask) {
     ValueProfileMap.ForEach([&](size_t Idx) {
       HandleFeature(FirstFeature + Idx);
     });

Modified: compiler-rt/trunk/test/fuzzer/ShrinkValueProfileTest.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/ShrinkValueProfileTest.cpp?rev=336234&r1=336233&r2=336234&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/ShrinkValueProfileTest.cpp (original)
+++ compiler-rt/trunk/test/fuzzer/ShrinkValueProfileTest.cpp Tue Jul  3 15:33:09 2018
@@ -1,7 +1,7 @@
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 
-// Test that we can find the minimal item in the corpus (3 bytes: "FUZ").
+// Test that we can find the minimal item in the corpus (4 bytes: "FUZZ").
 #include <cstddef>
 #include <cstdint>
 #include <cstdio>

Added: compiler-rt/trunk/test/fuzzer/three-bytes.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/three-bytes.test?rev=336234&view=auto
==============================================================================
--- compiler-rt/trunk/test/fuzzer/three-bytes.test (added)
+++ compiler-rt/trunk/test/fuzzer/three-bytes.test Tue Jul  3 15:33:09 2018
@@ -0,0 +1,8 @@
+Tests -use_value_profile=2 (alternative VP metric).
+RUN: %cpp_compiler %S/ThreeBytes.cpp -o %t
+
+RUN:     %run %t -seed=1 -runs=100000
+RUN:     %run %t -seed=1 -runs=100000 -use_value_profile=1
+RUN: not %run %t -seed=1 -runs=100000 -use_value_profile=2 2>&1 | FileCheck %s
+
+CHECK: Test unit written




More information about the llvm-commits mailing list