From 9802089e13aad3c00d549510a4a85c74f92e13b1 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Mon, 9 Apr 2018 22:38:26 +0000 Subject: [PATCH] libFuzzer, OpenBSD support Summary: - Enabling libfuzzer on OpenBSD - OpenBSD can t support asan, msan ... the tests can t be run. Patch by David CARLIER Reviewers: eugenis, phosek, vitalybuka Reviewed By: vitalybuka Subscribers: srhines, mgorny, krytarowski, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D44877 llvm-svn: 329631 --- compiler-rt/cmake/config-ix.cmake | 2 +- compiler-rt/lib/fuzzer/FuzzerDefs.h | 18 +++++++++++++++++- compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp | 5 +++-- compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp | 3 ++- compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp | 5 +++-- compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp | 3 ++- compiler-rt/lib/fuzzer/afl/afl_driver.cpp | 13 ++++++++++++- compiler-rt/test/CMakeLists.txt | 3 ++- 8 files changed, 42 insertions(+), 10 deletions(-) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index 8d32579..82c3d28 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -613,7 +613,7 @@ else() endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND - OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|Fuchsia") + OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|OpenBSD|Fuchsia") set(COMPILER_RT_HAS_FUZZER TRUE) else() set(COMPILER_RT_HAS_FUZZER FALSE) diff --git a/compiler-rt/lib/fuzzer/FuzzerDefs.h b/compiler-rt/lib/fuzzer/FuzzerDefs.h index 6c53e63..02e25f6 100644 --- a/compiler-rt/lib/fuzzer/FuzzerDefs.h +++ b/compiler-rt/lib/fuzzer/FuzzerDefs.h @@ -28,6 +28,7 @@ #define LIBFUZZER_LINUX 1 #define LIBFUZZER_NETBSD 0 #define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 #elif __APPLE__ #define LIBFUZZER_APPLE 1 @@ -35,6 +36,7 @@ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 0 #define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 #elif __NetBSD__ #define LIBFUZZER_APPLE 0 @@ -42,6 +44,7 @@ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 1 #define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 #elif __FreeBSD__ #define LIBFUZZER_APPLE 0 @@ -49,6 +52,15 @@ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 0 #define LIBFUZZER_FREEBSD 1 +#define LIBFUZZER_OPENBSD 0 +#define LIBFUZZER_WINDOWS 0 +#elif __OpenBSD__ +#define LIBFUZZER_APPLE 0 +#define LIBFUZZER_FUCHSIA 0 +#define LIBFUZZER_LINUX 0 +#define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 1 #define LIBFUZZER_WINDOWS 0 #elif _WIN32 #define LIBFUZZER_APPLE 0 @@ -56,6 +68,7 @@ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 0 #define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 1 #elif __Fuchsia__ #define LIBFUZZER_APPLE 0 @@ -63,6 +76,7 @@ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 0 #define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 #else #error "Support for your platform has not been implemented" @@ -72,7 +86,9 @@ # define __has_attribute(x) 0 #endif -#define LIBFUZZER_POSIX (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD) +#define LIBFUZZER_POSIX \ + (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD || \ + LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD) #ifdef __x86_64 # if __has_attribute(target) diff --git a/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp b/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp index 7c47dfa..a4e56fc 100644 --- a/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp @@ -13,7 +13,8 @@ // to clients right now. //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" -#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUCHSIA || LIBFUZZER_FREEBSD +#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUCHSIA || \ + LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD #include "FuzzerExtFunctions.h" #include "FuzzerIO.h" @@ -51,4 +52,4 @@ ExternalFunctions::ExternalFunctions() { } // namespace fuzzer -#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUSCHIA || LIBFUZZER_FREEBSD +#endif diff --git a/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp b/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp index d98598a..c99cd89 100644 --- a/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp @@ -11,7 +11,8 @@ #include "FuzzerDefs.h" -#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD +#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ + LIBFUZZER_OPENBSD __attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters; __attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters; diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp index f8b5d11..c103fd2 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp @@ -9,7 +9,8 @@ // Misc utils for Linux. //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" -#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD +#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ + LIBFUZZER_OPENBSD #include "FuzzerCommand.h" #include @@ -23,4 +24,4 @@ int ExecuteCommand(const Command &Cmd) { } // namespace fuzzer -#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD +#endif diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp index cef6cec..bc64d32 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp @@ -118,7 +118,8 @@ size_t GetPeakRSSMb() { struct rusage usage; if (getrusage(RUSAGE_SELF, &usage)) return 0; - if (LIBFUZZER_LINUX || LIBFUZZER_FREEBSD || LIBFUZZER_NETBSD) { + if (LIBFUZZER_LINUX || LIBFUZZER_FREEBSD || LIBFUZZER_NETBSD || + LIBFUZZER_OPENBSD) { // ru_maxrss is in KiB return usage.ru_maxrss >> 10; } else if (LIBFUZZER_APPLE) { diff --git a/compiler-rt/lib/fuzzer/afl/afl_driver.cpp b/compiler-rt/lib/fuzzer/afl/afl_driver.cpp index 1d1c16a..9f50ddd 100644 --- a/compiler-rt/lib/fuzzer/afl/afl_driver.cpp +++ b/compiler-rt/lib/fuzzer/afl/afl_driver.cpp @@ -70,21 +70,31 @@ statistics from the file. If that fails then the process will quit. #define LIBFUZZER_APPLE 0 #define LIBFUZZER_NETBSD 0 #define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 #elif __APPLE__ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_APPLE 1 #define LIBFUZZER_NETBSD 0 #define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 #elif __NetBSD__ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_APPLE 0 #define LIBFUZZER_NETBSD 1 #define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 #elif __FreeBSD__ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_APPLE 0 #define LIBFUZZER_NETBSD 0 #define LIBFUZZER_FREEBSD 1 +#define LIBFUZZER_OPENBSD 0 +#elif __OpenBSD__ +#define LIBFUZZER_LINUX 0 +#define LIBFUZZER_APPLE 0 +#define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 1 #else #error "Support for your platform has not been implemented" #endif @@ -133,7 +143,8 @@ size_t GetPeakRSSMb() { struct rusage usage; if (getrusage(RUSAGE_SELF, &usage)) return 0; - if (LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD) { + if (LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || + LIBFUZZER_OPENBSD) { // ru_maxrss is in KiB return usage.ru_maxrss >> 10; } else if (LIBFUZZER_APPLE) { diff --git a/compiler-rt/test/CMakeLists.txt b/compiler-rt/test/CMakeLists.txt index fa2031a..7e8f9ed 100644 --- a/compiler-rt/test/CMakeLists.txt +++ b/compiler-rt/test/CMakeLists.txt @@ -61,7 +61,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS) compiler_rt_test_runtime(ubsan cfi) compiler_rt_test_runtime(sanitizer_common) - if(COMPILER_RT_BUILD_LIBFUZZER) + # OpenBSD not supporting asan, cannot run the tests + if(COMPILER_RT_BUILD_LIBFUZZER AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") compiler_rt_test_runtime(fuzzer) endif() -- 2.7.4