Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -604,7 +604,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND - OS_NAME MATCHES "Android|Darwin|Linux|NetBSD") + OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD") set(COMPILER_RT_HAS_FUZZER TRUE) else() set(COMPILER_RT_HAS_FUZZER FALSE) Index: lib/fuzzer/FuzzerDefs.h =================================================================== --- lib/fuzzer/FuzzerDefs.h +++ lib/fuzzer/FuzzerDefs.h @@ -27,6 +27,7 @@ #define LIBFUZZER_FUCHSIA 0 #define LIBFUZZER_LINUX 1 #define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_WINDOWS 0 #elif __APPLE__ #define LIBFUZZER_APPLE 1 @@ -33,6 +34,7 @@ #define LIBFUZZER_FUCHSIA 0 #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_WINDOWS 0 #elif __NetBSD__ #define LIBFUZZER_APPLE 0 @@ -39,12 +41,21 @@ #define LIBFUZZER_FUCHSIA 0 #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 1 +#define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_WINDOWS 0 +#elif __FreeBSD__ +#define LIBFUZZER_APPLE 0 +#define LIBFUZZER_FUCHSIA 0 +#define LIBFUZZER_LINUX 0 +#define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 1 +#define LIBFUZZER_WINDOWS 0 #elif _WIN32 #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_WINDOWS 1 #elif __Fuchsia__ #define LIBFUZZER_APPLE 0 @@ -51,6 +62,7 @@ #define LIBFUZZER_FUCHSIA 1 #define LIBFUZZER_LINUX 0 #define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_WINDOWS 0 #else #error "Support for your platform has not been implemented" @@ -60,7 +72,7 @@ # define __has_attribute(x) 0 #endif -#define LIBFUZZER_POSIX (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD) +#define LIBFUZZER_POSIX (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD) #ifdef __x86_64 # if __has_attribute(target) Index: lib/fuzzer/FuzzerExtFunctionsWeak.cpp =================================================================== --- lib/fuzzer/FuzzerExtFunctionsWeak.cpp +++ lib/fuzzer/FuzzerExtFunctionsWeak.cpp @@ -13,7 +13,7 @@ // to clients right now. //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" -#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUCHSIA +#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUCHSIA || LIBFUZZER_FREEBSD #include "FuzzerExtFunctions.h" #include "FuzzerIO.h" @@ -51,4 +51,4 @@ } // namespace fuzzer -#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD +#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUSCHIA || LIBFUZZER_FREEBSD Index: lib/fuzzer/FuzzerExtraCounters.cpp =================================================================== --- lib/fuzzer/FuzzerExtraCounters.cpp +++ lib/fuzzer/FuzzerExtraCounters.cpp @@ -11,7 +11,7 @@ #include "FuzzerDefs.h" -#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD +#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD __attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters; __attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters; Index: lib/fuzzer/FuzzerUtilLinux.cpp =================================================================== --- lib/fuzzer/FuzzerUtilLinux.cpp +++ lib/fuzzer/FuzzerUtilLinux.cpp @@ -9,7 +9,7 @@ // Misc utils for Linux. //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" -#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD +#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD #include "FuzzerCommand.h" #include @@ -23,4 +23,4 @@ } // namespace fuzzer -#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD +#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD Index: lib/fuzzer/FuzzerUtilPosix.cpp =================================================================== --- lib/fuzzer/FuzzerUtilPosix.cpp +++ lib/fuzzer/FuzzerUtilPosix.cpp @@ -118,7 +118,7 @@ struct rusage usage; if (getrusage(RUSAGE_SELF, &usage)) return 0; - if (LIBFUZZER_LINUX) { + if (LIBFUZZER_LINUX || LIBFUZZER_FREEBSD || LIBFUZZER_NETBSD) { // ru_maxrss is in KiB return usage.ru_maxrss >> 10; } else if (LIBFUZZER_APPLE) { Index: lib/fuzzer/afl/afl_driver.cpp =================================================================== --- lib/fuzzer/afl/afl_driver.cpp +++ lib/fuzzer/afl/afl_driver.cpp @@ -69,14 +69,22 @@ #define LIBFUZZER_LINUX 1 #define LIBFUZZER_APPLE 0 #define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 #elif __APPLE__ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_APPLE 1 #define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 #elif __NetBSD__ #define LIBFUZZER_LINUX 0 #define LIBFUZZER_APPLE 0 #define LIBFUZZER_NETBSD 1 +#define LIBFUZZER_FREEBSD 0 +#elif __FreeBSD__ +#define LIBFUZZER_LINUX 0 +#define LIBFUZZER_APPLE 0 +#define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 1 #else #error "Support for your platform has not been implemented" #endif @@ -125,7 +133,7 @@ struct rusage usage; if (getrusage(RUSAGE_SELF, &usage)) return 0; - if (LIBFUZZER_LINUX || LIBFUZZER_NETBSD) { + if (LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD) { // ru_maxrss is in KiB return usage.ru_maxrss >> 10; } else if (LIBFUZZER_APPLE) { Index: lib/fuzzer/build.sh =================================================================== --- lib/fuzzer/build.sh +++ lib/fuzzer/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash LIBFUZZER_SRC_DIR=$(dirname $0) CXX="${CXX:-clang}" for f in $LIBFUZZER_SRC_DIR/*.cpp; do Index: lib/fuzzer/tests/CMakeLists.txt =================================================================== --- lib/fuzzer/tests/CMakeLists.txt +++ lib/fuzzer/tests/CMakeLists.txt @@ -12,8 +12,8 @@ set(LIBFUZZER_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS}) list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS --driver-mode=g++) -if(APPLE) - list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -lc++) +if(APPLE OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -lc++ -lpthread) else() list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -lstdc++ -lpthread) endif() Index: lib/sanitizer_common/sanitizer_internal_defs.h =================================================================== --- lib/sanitizer_common/sanitizer_internal_defs.h +++ lib/sanitizer_common/sanitizer_internal_defs.h @@ -36,7 +36,7 @@ #endif // TLS is handled differently on different platforms -#if SANITIZER_LINUX || SANITIZER_NETBSD +#if SANITIZER_LINUX || SANITIZER_NETBSD || SANITIZER_FREEBSD # define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE \ __attribute__((tls_model("initial-exec"))) thread_local #else Index: test/fuzzer/TraceMallocThreadedTest.cpp =================================================================== --- test/fuzzer/TraceMallocThreadedTest.cpp +++ test/fuzzer/TraceMallocThreadedTest.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { Index: test/fuzzer/afl-driver-stderr.test =================================================================== --- test/fuzzer/afl-driver-stderr.test +++ test/fuzzer/afl-driver-stderr.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %no_fuzzer_cpp_compiler -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters,trace-pc-guard %S/AFLDriverTest.cpp %libfuzzer_src/afl/afl_driver.cpp -o %t-AFLDriverTest ; Test that not specifying a stderr file isn't broken. Index: test/fuzzer/caller-callee.test =================================================================== --- test/fuzzer/caller-callee.test +++ test/fuzzer/caller-callee.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/CallerCalleeTest.cpp -o %t-CallerCalleeTest CHECK: BINGO RUN: not %t-CallerCalleeTest -use_value_profile=1 -cross_over=0 -seed=1 -runs=10000000 2>&1 | FileCheck %s Index: test/fuzzer/cxxstring.test =================================================================== --- test/fuzzer/cxxstring.test +++ test/fuzzer/cxxstring.test @@ -1,4 +1,4 @@ -UNSUPPORTED: windows +UNSUPPORTED: windows,freebsd RUN: %cpp_compiler %S/CxxStringEqTest.cpp -o %t-CxxStringEqTest Index: test/fuzzer/dump_coverage.test =================================================================== --- test/fuzzer/dump_coverage.test +++ test/fuzzer/dump_coverage.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSO1.cpp -fPIC -shared -o %t-DSO1.so RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSO2.cpp -fPIC -shared -o %t-DSO2.so RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSOTestMain.cpp %S/DSOTestExtra.cpp -L. %t-DSO1.so %t-DSO2.so -o %t-DSOTest Index: test/fuzzer/equivalence-signals.test =================================================================== --- test/fuzzer/equivalence-signals.test +++ test/fuzzer/equivalence-signals.test @@ -1,6 +1,7 @@ # Run EquivalenceATest against itself with a small timeout # to stress the signal handling and ensure that shmem doesn't mind # the signals. +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/EquivalenceATest.cpp -o %t-EquivalenceATest RUN: %t-EquivalenceATest -timeout=1 -run_equivalence_server=EQUIV_SIG_TEST & export APID=$! Index: test/fuzzer/equivalence.test =================================================================== --- test/fuzzer/equivalence.test +++ test/fuzzer/equivalence.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/EquivalenceATest.cpp -o %t-EquivalenceATest RUN: %cpp_compiler %S/EquivalenceBTest.cpp -o %t-EquivalenceBTest Index: test/fuzzer/lit.cfg =================================================================== --- test/fuzzer/lit.cfg +++ test/fuzzer/lit.cfg @@ -25,7 +25,7 @@ config.test_format = lit.formats.ShTest(execute_external) # LeakSanitizer is not supported on OSX right now. -if sys.platform.startswith('darwin'): +if sys.platform.startswith('darwin') or sys.platform.startswith('freebsd'): lit_config.note('lsan feature unavailable') else: lit_config.note('lsan feature available') @@ -51,7 +51,7 @@ def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True): compiler_cmd = config.c_compiler - link_cmd = '-lc++' if 'darwin' in config.target_triple else '-lstdc++' + link_cmd = '-lc++' if 'darwin' or 'freebsd' in config.target_triple else '-lstdc++' std_cmd = '-std=c++11' if is_cpp else '' sanitizers = ['address'] if fuzzer_enabled: Index: test/fuzzer/memcmp.test =================================================================== --- test/fuzzer/memcmp.test +++ test/fuzzer/memcmp.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/MemcmpTest.cpp -o %t-MemcmpTest RUN: not %t-MemcmpTest -seed=1 -runs=10000000 2>&1 | FileCheck %s CHECK: BINGO Index: test/fuzzer/memcmp64.test =================================================================== --- test/fuzzer/memcmp64.test +++ test/fuzzer/memcmp64.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/Memcmp64BytesTest.cpp -o %t-Memcmp64BytesTest RUN: not %t-Memcmp64BytesTest -seed=1 -runs=1000000 2>&1 | FileCheck %s CHECK: BINGO Index: test/fuzzer/minimize_two_crashes.test =================================================================== --- test/fuzzer/minimize_two_crashes.test +++ test/fuzzer/minimize_two_crashes.test @@ -1,4 +1,5 @@ # Test that the minimizer stops when it sees a differe bug. +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/TwoDifferentBugsTest.cpp -o %t-TwoDifferentBugsTest Index: test/fuzzer/recommended-dictionary.test =================================================================== --- test/fuzzer/recommended-dictionary.test +++ test/fuzzer/recommended-dictionary.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/RepeatedMemcmp.cpp -o %t-RepeatedMemcmp RUN: %t-RepeatedMemcmp -seed=11 -runs=100000 -max_len=20 2>&1 | FileCheck %s --check-prefix=RECOMMENDED_DICT RECOMMENDED_DICT:###### Recommended dictionary. ###### Index: test/fuzzer/strcmp.test =================================================================== --- test/fuzzer/strcmp.test +++ test/fuzzer/strcmp.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/StrcmpTest.cpp -o %t-StrcmpTest RUN: not %t-StrcmpTest -seed=1 -runs=2000000 2>&1 | FileCheck %s CHECK: BINGO Index: test/fuzzer/strncmp.test =================================================================== --- test/fuzzer/strncmp.test +++ test/fuzzer/strncmp.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/StrncmpTest.cpp -o %t-StrncmpTest RUN: not %t-StrncmpTest -seed=2 -runs=10000000 2>&1 | FileCheck %s CHECK: BINGO Index: test/fuzzer/strstr.test =================================================================== --- test/fuzzer/strstr.test +++ test/fuzzer/strstr.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd RUN: %cpp_compiler %S/StrstrTest.cpp -o %t-StrstrTest RUN: not %t-StrstrTest -seed=1 -runs=2000000 2>&1 | FileCheck %s CHECK: BINGO Index: test/fuzzer/value-profile-mem.test =================================================================== --- test/fuzzer/value-profile-mem.test +++ test/fuzzer/value-profile-mem.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd CHECK: BINGO RUN: %cpp_compiler %S/SingleMemcmpTest.cpp -o %t-SingleMemcmpTest RUN: not %t-SingleMemcmpTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=10000000 2>&1 | FileCheck %s Index: test/fuzzer/value-profile-strcmp.test =================================================================== --- test/fuzzer/value-profile-strcmp.test +++ test/fuzzer/value-profile-strcmp.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd CHECK: BINGO RUN: %cpp_compiler %S/SingleStrcmpTest.cpp -o %t-SingleStrcmpTest RUN: not %t-SingleStrcmpTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=10000000 2>&1 | FileCheck %s Index: test/fuzzer/value-profile-strncmp.test =================================================================== --- test/fuzzer/value-profile-strncmp.test +++ test/fuzzer/value-profile-strncmp.test @@ -1,3 +1,4 @@ +UNSUPPORTED: freebsd CHECK: BINGO RUN: %cpp_compiler %S/SingleStrncmpTest.cpp -o %t-SingleStrncmpTest RUN: not %t-SingleStrncmpTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s