Skip to content

Commit 8da2722

Browse files
committedAug 30, 2017
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 llvm-svn: 312183
1 parent 76794da commit 8da2722

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed
 

‎compiler-rt/cmake/config-ix.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ else()
588588
endif()
589589

590590
if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND
591-
OS_NAME MATCHES "Darwin|Linux")
591+
OS_NAME MATCHES "Darwin|Linux|NetBSD")
592592
set(COMPILER_RT_HAS_FUZZER TRUE)
593593
else()
594594
set(COMPILER_RT_HAS_FUZZER FALSE)

‎compiler-rt/lib/fuzzer/FuzzerDefs.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@
2525
#ifdef __linux__
2626
#define LIBFUZZER_APPLE 0
2727
#define LIBFUZZER_LINUX 1
28+
#define LIBFUZZER_NETBSD 0
2829
#define LIBFUZZER_WINDOWS 0
2930
#elif __APPLE__
3031
#define LIBFUZZER_APPLE 1
3132
#define LIBFUZZER_LINUX 0
33+
#define LIBFUZZER_NETBSD 0
34+
#define LIBFUZZER_WINDOWS 0
35+
#elif __NetBSD__
36+
#define LIBFUZZER_APPLE 0
37+
#define LIBFUZZER_LINUX 0
38+
#define LIBFUZZER_NETBSD 1
3239
#define LIBFUZZER_WINDOWS 0
3340
#elif _WIN32
3441
#define LIBFUZZER_APPLE 0
3542
#define LIBFUZZER_LINUX 0
43+
#define LIBFUZZER_NETBSD 0
3644
#define LIBFUZZER_WINDOWS 1
3745
#else
3846
#error "Support for your platform has not been implemented"
@@ -42,7 +50,7 @@
4250
# define __has_attribute(x) 0
4351
#endif
4452

45-
#define LIBFUZZER_POSIX LIBFUZZER_APPLE || LIBFUZZER_LINUX
53+
#define LIBFUZZER_POSIX (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD)
4654

4755
#ifdef __x86_64
4856
# if __has_attribute(target)

‎compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// to clients right now.
1414
//===----------------------------------------------------------------------===//
1515
#include "FuzzerDefs.h"
16-
#if LIBFUZZER_LINUX
16+
#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD
1717

1818
#include "FuzzerExtFunctions.h"
1919
#include "FuzzerIO.h"
@@ -51,4 +51,4 @@ ExternalFunctions::ExternalFunctions() {
5151

5252
} // namespace fuzzer
5353

54-
#endif // LIBFUZZER_LINUX
54+
#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD

‎compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "FuzzerDefs.h"
1313

14-
#if LIBFUZZER_LINUX
14+
#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD
1515
__attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters;
1616
__attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters;
1717

‎compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Misc utils for Linux.
1010
//===----------------------------------------------------------------------===//
1111
#include "FuzzerDefs.h"
12-
#if LIBFUZZER_LINUX
12+
#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD
1313

1414
#include <stdlib.h>
1515

@@ -21,4 +21,4 @@ int ExecuteCommand(const std::string &Command) {
2121

2222
} // namespace fuzzer
2323

24-
#endif // LIBFUZZER_LINUX
24+
#endif // LIBFUZZER_LINUX || LIBFUZZER_NETBSD

‎compiler-rt/lib/fuzzer/afl/afl_driver.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ statistics from the file. If that fails then the process will quit.
6868
#ifdef __linux__
6969
#define LIBFUZZER_LINUX 1
7070
#define LIBFUZZER_APPLE 0
71+
#define LIBFUZZER_NETBSD 0
7172
#elif __APPLE__
7273
#define LIBFUZZER_LINUX 0
7374
#define LIBFUZZER_APPLE 1
75+
#define LIBFUZZER_NETBSD 0
76+
#elif __NetBSD__
77+
#define LIBFUZZER_LINUX 0
78+
#define LIBFUZZER_APPLE 0
79+
#define LIBFUZZER_NETBSD 1
7480
#else
7581
#error "Support for your platform has not been implemented"
7682
#endif
@@ -119,7 +125,7 @@ size_t GetPeakRSSMb() {
119125
struct rusage usage;
120126
if (getrusage(RUSAGE_SELF, &usage))
121127
return 0;
122-
if (LIBFUZZER_LINUX) {
128+
if (LIBFUZZER_LINUX || LIBFUZZER_NETBSD) {
123129
// ru_maxrss is in KiB
124130
return usage.ru_maxrss >> 10;
125131
} else if (LIBFUZZER_APPLE) {

0 commit comments

Comments
 (0)