[compiler-rt] r312183 - Add preliminary NetBSD support in libfuzzer

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 30 15:44:11 PDT 2017


Author: kamil
Date: Wed Aug 30 15:44:11 2017
New Revision: 312183

URL: http://llvm.org/viewvc/llvm-project?rev=312183&view=rev
Log:
Add preliminary NetBSD support in libfuzzer

Summary:
This code already works and passes some number of tests.

There is need to finish remaining sanitizers to get better coverage.

Many tests fail due to overly long file names of executables (>31).
This is a current shortcoming of the NetBSD 8(beta) kernel, as
certain functions can fail (like retrieving file name of executable).

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, kcc, vitalybuka, george.karpenkov

Reviewed By: kcc

Subscribers: mgorny, llvm-commits, #sanitizers

Tags: #sanitizers

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

Modified:
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/fuzzer/FuzzerDefs.h
    compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctionsWeak.cpp
    compiler-rt/trunk/lib/fuzzer/FuzzerExtraCounters.cpp
    compiler-rt/trunk/lib/fuzzer/FuzzerUtilLinux.cpp
    compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=312183&r1=312182&r2=312183&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Wed Aug 30 15:44:11 2017
@@ -588,7 +588,7 @@ else()
 endif()
 
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND
-      OS_NAME MATCHES "Darwin|Linux")
+      OS_NAME MATCHES "Darwin|Linux|NetBSD")
   set(COMPILER_RT_HAS_FUZZER TRUE)
 else()
   set(COMPILER_RT_HAS_FUZZER FALSE)

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerDefs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerDefs.h?rev=312183&r1=312182&r2=312183&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerDefs.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerDefs.h Wed Aug 30 15:44:11 2017
@@ -25,14 +25,22 @@
 #ifdef __linux__
 #define LIBFUZZER_APPLE 0
 #define LIBFUZZER_LINUX 1
+#define LIBFUZZER_NETBSD 0
 #define LIBFUZZER_WINDOWS 0
 #elif __APPLE__
 #define LIBFUZZER_APPLE 1
 #define LIBFUZZER_LINUX 0
+#define LIBFUZZER_NETBSD 0
+#define LIBFUZZER_WINDOWS 0
+#elif __NetBSD__
+#define LIBFUZZER_APPLE 0
+#define LIBFUZZER_LINUX 0
+#define LIBFUZZER_NETBSD 1
 #define LIBFUZZER_WINDOWS 0
 #elif _WIN32
 #define LIBFUZZER_APPLE 0
 #define LIBFUZZER_LINUX 0
+#define LIBFUZZER_NETBSD 0
 #define LIBFUZZER_WINDOWS 1
 #else
 #error "Support for your platform has not been implemented"
@@ -42,7 +50,7 @@
 #  define __has_attribute(x) 0
 #endif
 
-#define LIBFUZZER_POSIX LIBFUZZER_APPLE || LIBFUZZER_LINUX
+#define LIBFUZZER_POSIX (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD)
 
 #ifdef __x86_64
 #  if __has_attribute(target)

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctionsWeak.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctionsWeak.cpp?rev=312183&r1=312182&r2=312183&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctionsWeak.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerExtFunctionsWeak.cpp Wed Aug 30 15:44:11 2017
@@ -13,7 +13,7 @@
 // to clients right now.
 //===----------------------------------------------------------------------===//
 #include "FuzzerDefs.h"
-#if LIBFUZZER_LINUX
+#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD
 
 #include "FuzzerExtFunctions.h"
 #include "FuzzerIO.h"
@@ -51,4 +51,4 @@ ExternalFunctions::ExternalFunctions() {
 
 } // namespace fuzzer
 
-#endif // LIBFUZZER_LINUX
+#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerExtraCounters.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerExtraCounters.cpp?rev=312183&r1=312182&r2=312183&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerExtraCounters.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerExtraCounters.cpp Wed Aug 30 15:44:11 2017
@@ -11,7 +11,7 @@
 
 #include "FuzzerDefs.h"
 
-#if LIBFUZZER_LINUX
+#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD
 __attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters;
 __attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters;
 

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerUtilLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerUtilLinux.cpp?rev=312183&r1=312182&r2=312183&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerUtilLinux.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerUtilLinux.cpp Wed Aug 30 15:44:11 2017
@@ -9,7 +9,7 @@
 // Misc utils for Linux.
 //===----------------------------------------------------------------------===//
 #include "FuzzerDefs.h"
-#if LIBFUZZER_LINUX
+#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD
 
 #include <stdlib.h>
 
@@ -21,4 +21,4 @@ int ExecuteCommand(const std::string &Co
 
 } // namespace fuzzer
 
-#endif // LIBFUZZER_LINUX
+#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD

Modified: compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp?rev=312183&r1=312182&r2=312183&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp Wed Aug 30 15:44:11 2017
@@ -68,9 +68,15 @@ statistics from the file. If that fails
 #ifdef __linux__
 #define LIBFUZZER_LINUX 1
 #define LIBFUZZER_APPLE 0
+#define LIBFUZZER_NETBSD 0
 #elif __APPLE__
 #define LIBFUZZER_LINUX 0
 #define LIBFUZZER_APPLE 1
+#define LIBFUZZER_NETBSD 0
+#elif __NetBSD__
+#define LIBFUZZER_LINUX 0
+#define LIBFUZZER_APPLE 0
+#define LIBFUZZER_NETBSD 1
 #else
 #error "Support for your platform has not been implemented"
 #endif
@@ -119,7 +125,7 @@ size_t GetPeakRSSMb() {
   struct rusage usage;
   if (getrusage(RUSAGE_SELF, &usage))
     return 0;
-  if (LIBFUZZER_LINUX) {
+  if (LIBFUZZER_LINUX || LIBFUZZER_NETBSD) {
     // ru_maxrss is in KiB
     return usage.ru_maxrss >> 10;
   } else if (LIBFUZZER_APPLE) {




More information about the llvm-commits mailing list