summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerLoop.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2015-11-09 23:17:45 +0000
committerKostya Serebryany <kcc@google.com>2015-11-09 23:17:45 +0000
commit5eab74e9bc730fa5682324de9b9abb0c0a4b52a4 (patch)
tree17a44bd637dfcab96c0131f80246103801a73eb6 /llvm/lib/Fuzzer/FuzzerLoop.cpp
parent72303a243687c0474c7076d9174f4f2fa111c38f (diff)
downloadbcm5719-llvm-5eab74e9bc730fa5682324de9b9abb0c0a4b52a4.tar.gz
bcm5719-llvm-5eab74e9bc730fa5682324de9b9abb0c0a4b52a4.zip
[libFuzzer] make libFuzzer link if there is no sanitizer coverage instrumentation (it will fail at start-up time)
llvm-svn: 252533
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerLoop.cpp')
-rw-r--r--llvm/lib/Fuzzer/FuzzerLoop.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp
index 22876232f8b..e206fcc9796 100644
--- a/llvm/lib/Fuzzer/FuzzerLoop.cpp
+++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp
@@ -14,13 +14,34 @@
#include <algorithm>
extern "C" {
+// Re-declare some of the sanitizer functions as "weak" so that
+// libFuzzer can be linked w/o the sanitizers and sanitizer-coveragte
+// (in which case it will complain at start-up time).
__attribute__((weak)) void __sanitizer_print_stack_trace();
__attribute__((weak)) size_t __sanitizer_get_total_unique_caller_callee_pairs();
+__attribute__((weak)) size_t __sanitizer_get_total_unique_coverage();
+__attribute__((weak))
+void __sanitizer_set_death_callback(void (*callback)(void));
+__attribute__((weak)) size_t __sanitizer_get_number_of_counters();
+__attribute__((weak))
+uintptr_t __sanitizer_update_counter_bitset_and_clear_counters(uint8_t *bitset);
}
namespace fuzzer {
static const size_t kMaxUnitSizeToPrint = 256;
+static void MissingWeakApiFunction(const char *FnName) {
+ Printf("ERROR: %s is not defined. Exiting.\n"
+ "Did you use -fsanitize-coverage=... to build your code?\n", FnName);
+ exit(1);
+}
+
+#define CHECK_WEAK_API_FUNCTION(fn) \
+ do { \
+ if (!fn) \
+ MissingWeakApiFunction(#fn); \
+ } while (false)
+
// Only one Fuzzer per process.
static Fuzzer *F;
@@ -33,6 +54,7 @@ Fuzzer::Fuzzer(UserSuppliedFuzzer &USF, FuzzingOptions Options)
}
void Fuzzer::SetDeathCallback() {
+ CHECK_WEAK_API_FUNCTION(__sanitizer_set_death_callback);
__sanitizer_set_death_callback(StaticDeathCallback);
}
@@ -204,6 +226,7 @@ void Fuzzer::ExecuteCallback(const Unit &U) {
}
size_t Fuzzer::RecordBlockCoverage() {
+ CHECK_WEAK_API_FUNCTION(__sanitizer_get_total_unique_coverage);
return LastRecordedBlockCoverage = __sanitizer_get_total_unique_coverage();
}
OpenPOWER on IntegriCloud