[llvm] r293125 - [libFuzzer] simplify the code for __sanitizer_cov_trace_pc_guard and make sure it is not asan/msan-instrumented

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 25 17:04:54 PST 2017


Author: kcc
Date: Wed Jan 25 19:04:54 2017
New Revision: 293125

URL: http://llvm.org/viewvc/llvm-project?rev=293125&view=rev
Log:
[libFuzzer] simplify the code for __sanitizer_cov_trace_pc_guard and make sure it is not asan/msan-instrumented

Modified:
    llvm/trunk/lib/Fuzzer/FuzzerDefs.h
    llvm/trunk/lib/Fuzzer/FuzzerIO.h
    llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp
    llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp
    llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp

Modified: llvm/trunk/lib/Fuzzer/FuzzerDefs.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerDefs.h?rev=293125&r1=293124&r2=293125&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerDefs.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerDefs.h Wed Jan 25 19:04:54 2017
@@ -53,6 +53,11 @@
 #  define ALWAYS_INLINE
 #endif // __clang__
 
+#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
+
+#define ATTRIBUTE_NO_SANITIZE_ALL ATTRIBUTE_NO_SANITIZE_ADDRESS ATTRIBUTE_NO_SANITIZE_MEMORY
+
+
 #if LIBFUZZER_WINDOWS
 #define ATTRIBUTE_INTERFACE __declspec(dllexport)
 #else

Modified: llvm/trunk/lib/Fuzzer/FuzzerIO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIO.h?rev=293125&r1=293124&r2=293125&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIO.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIO.h Wed Jan 25 19:04:54 2017
@@ -48,6 +48,9 @@ void CloseStdout();
 
 void Printf(const char *Fmt, ...);
 
+// Print using raw syscalls, useful when printing at early init stages.
+void RawPrint(const char *Str);
+
 // Platform specific functions:
 bool IsFile(const std::string &Path);
 

Modified: llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp?rev=293125&r1=293124&r2=293125&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp Wed Jan 25 19:04:54 2017
@@ -109,6 +109,11 @@ bool IsInterestingCoverageFile(const std
   return true;
 }
 
+
+void RawPrint(const char *Str) {
+  write(2, Str, strlen(Str));
+}
+
 }  // namespace fuzzer
 
 #endif // LIBFUZZER_POSIX

Modified: llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp?rev=293125&r1=293124&r2=293125&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp Wed Jan 25 19:04:54 2017
@@ -299,6 +299,11 @@ bool IsInterestingCoverageFile(const std
   return true;
 }
 
+void RawPrint(const char *Str) {
+  // Not tested, may or may not work. Fix if needed.
+  Printf("%s", Str);
+}
+
 }  // namespace fuzzer
 
 #endif // LIBFUZZER_WINDOWS

Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=293125&r1=293124&r2=293125&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Wed Jan 25 19:04:54 2017
@@ -28,10 +28,10 @@ namespace fuzzer {
 
 TracePC TPC;
 
+ATTRIBUTE_NO_SANITIZE_ALL
 void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) {
   uint32_t Idx = *Guard;
-  if (!Idx) return;
-  PCs[Idx % kNumPCs] = PC;
+  PCs[Idx] = PC;
   Counters[Idx % kNumCounters]++;
 }
 
@@ -46,8 +46,16 @@ size_t TracePC::GetTotalPCCoverage() {
 void TracePC::HandleInit(uint32_t *Start, uint32_t *Stop) {
   if (Start == Stop || *Start) return;
   assert(NumModules < sizeof(Modules) / sizeof(Modules[0]));
-  for (uint32_t *P = Start; P < Stop; P++)
-    *P = ++NumGuards;
+  for (uint32_t *P = Start; P < Stop; P++) {
+    NumGuards++;
+    if (NumGuards == kNumPCs) {
+      RawPrint(
+          "WARNING: The binary has too many instrumented PCs.\n"
+          "         You may want to reduce the size of the binary\n"
+          "         for more efficient fuzzing and precise coverage data\n");
+    }
+    *P = NumGuards % kNumPCs;
+  }
   Modules[NumModules].Start = Start;
   Modules[NumModules].Stop = Stop;
   NumModules++;
@@ -258,6 +266,7 @@ void TracePC::HandleCmp(uintptr_t PC, T
 
 extern "C" {
 ATTRIBUTE_INTERFACE
+ATTRIBUTE_NO_SANITIZE_ALL
 void __sanitizer_cov_trace_pc_guard(uint32_t *Guard) {
   uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
   fuzzer::TPC.HandleTrace(Guard, PC);




More information about the llvm-commits mailing list