Build issues when trying to use LibFuzzer on Mac OS X

I’m trying to use LibFuzzer on my Mac - following the directions here:

But when I try to link my program and the Fuzzer object code, I get errors.

They appear to be symbols from compiler-rt that are missing.
Do I need a better (i.e, more recent) compiler-rt than the one that Apple ships?

“totclang” → freshly built clang.

$ export FUZZER=$LLVM/llvm/lib/Fuzzer

$ cd ~/fuzz

$ cat regex_fuzz.cpp

extern “C” void LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) {
if (size > 0) {
std::regex re(std::string((const char *)data, size));

$ totclang -c -g -O2 -std=c++11 -I $FUZZER $FUZZER/.cpp
$ totclang -g -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters -c -std=c++11 regex_fuzz.cpp
$ totclang -g -fsanitize=address Fuzzer
.o regex_fuzz.o -Wl

Undefined symbols for architecture x86_64:
“_dfsan_create_label”, referenced from:
fuzzer::TraceState::DFSanCmpCallback(unsigned long, unsigned long, unsigned long, unsigned long long, unsigned long long, unsigned short, unsigned short) in FuzzerTraceState.o
fuzzer::Fuzzer::InitializeTraceState() in FuzzerTraceState.o
“_dfsan_get_label_info”, referenced from:
fuzzer::TraceState::GetLabelRange(unsigned short) in FuzzerTraceState.o
“_dfsan_read_label”, referenced from:
_dfsan_weak_hook_memcmp in FuzzerTraceState.o
“_dfsan_set_label”, referenced from:
fuzzer::Fuzzer::InitializeTraceState() in FuzzerTraceState.o
ld: symbol(s) not found for architecture x86_64
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)

– Marshall

      From cmake/config-ix.cmake in compiler-rt. it appears that the
Fuzzer support may be Linux only at the moment...

    OS_NAME MATCHES "Linux")


As I’ve just replied in another thread:

libFuzzer was also never tested on Mac, but I think it should be trivial to make it work there.
I suspect that the errors you see are caused by the weak function declarations which don’t (???) work on Mac.
You’ll need to #ifdef the weak functions on Mac somehow. Patches and Mac buildbots are welcome :slight_smile: