diff --git a/compiler-rt/lib/fuzzer/FuzzerDefs.h b/compiler-rt/lib/fuzzer/FuzzerDefs.h --- a/compiler-rt/lib/fuzzer/FuzzerDefs.h +++ b/compiler-rt/lib/fuzzer/FuzzerDefs.h @@ -30,6 +30,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __APPLE__ #define LIBFUZZER_APPLE 1 #define LIBFUZZER_FUCHSIA 0 @@ -38,6 +39,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __NetBSD__ #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 @@ -46,6 +48,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __FreeBSD__ #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 @@ -54,6 +57,7 @@ #define LIBFUZZER_FREEBSD 1 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __OpenBSD__ #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 @@ -62,6 +66,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 1 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif _WIN32 #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 @@ -70,6 +75,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 1 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __Fuchsia__ #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 1 @@ -78,6 +84,16 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 +#elif __EMSCRIPTEN__ +#define LIBFUZZER_APPLE 0 +#define LIBFUZZER_FUCHSIA 0 +#define LIBFUZZER_LINUX 0 +#define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 +#define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 1 #else #error "Support for your platform has not been implemented" #endif @@ -95,7 +111,7 @@ #define LIBFUZZER_POSIX \ (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD || \ - LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD) + LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN) #ifdef __x86_64 # if __has_attribute(target) diff --git a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp --- a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp @@ -280,7 +280,11 @@ } static void StartRssThread(Fuzzer *F, size_t RssLimitMb) { - if (!RssLimitMb) return; + if (!RssLimitMb) + return; + // Threads are only supported by Chrome. Don't use them for now. + if (LIBFUZZER_EMSCRIPTEN) + return; std::thread T(RssThread, F, RssLimitMb); T.detach(); } diff --git a/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp b/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp --- a/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUCHSIA || \ - LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD + LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN #include "FuzzerExtFunctions.h" #include "FuzzerIO.h" diff --git a/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp b/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp --- a/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp @@ -11,7 +11,7 @@ #include "FuzzerDefs.h" #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ - LIBFUZZER_OPENBSD || LIBFUZZER_FUCHSIA + LIBFUZZER_OPENBSD || LIBFUZZER_FUCHSIA || LIBFUZZER_EMSCRIPTEN __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 --- a/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp @@ -9,7 +9,7 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ - LIBFUZZER_OPENBSD + LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN #include "FuzzerCommand.h" #include diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp --- a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp @@ -98,7 +98,8 @@ } void SetSignalHandler(const FuzzingOptions& Options) { - if (Options.UnitTimeoutSec > 0) + // settimer is not implemented in emscripten. + if (Options.UnitTimeoutSec > 0 && !LIBFUZZER_EMSCRIPTEN) SetTimer(Options.UnitTimeoutSec / 2 + 1); if (Options.HandleInt) SetSigaction(SIGINT, InterruptHandler); @@ -133,7 +134,7 @@ if (getrusage(RUSAGE_SELF, &usage)) return 0; if (LIBFUZZER_LINUX || LIBFUZZER_FREEBSD || LIBFUZZER_NETBSD || - LIBFUZZER_OPENBSD) { + LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN) { // ru_maxrss is in KiB return usage.ru_maxrss >> 10; } else if (LIBFUZZER_APPLE) {