Hi,
I’m trying to use libFuzzer as a library as stated in the documentation https://llvm.org/docs/LibFuzzer.html#using-libfuzzer-as-a-library. However, when linking my binary against the no-main version of libFuzzer with
clang -o main main.o -fsanitize=fuzzer-no-link -L /usr/lib/llvm-10/lib/clang/10.0.0/lib/linux -l clang_rt.fuzzer_no_main-x86_64
I get the following error
/usr/bin/ld: /tmp/main-8122ac.o: in function `main':
main.c:(.text.main[main]+0x6f): undefined reference to `LLVMFuzzerRunDriver'
As the documentation states, I’m passing the -fsanitize=fuzzer-no-link argument during both compilation and linking. I’ll add below the content of the main.c file that I’m using where inside the main function I’m calling LLVMFuzzerRunDriver passing argc, argv and a callback function as parameters.
According to the documentation the LLVMFuzzerRunDriver function should be included in the no-main version of libFuzzer, which for me is located at /usr/lib/llvm-10/lib/clang/10.0.0/lib/linux/libclang_rt.fuzzer_no_main-x86_64.a in a clean Ubuntu 20.04 installation.
It’s important to note that this file doesn’t seem to contain any reference of ‘LLVMFuzzerRunDriver’ which I checked with nm libclang_rt.fuzzer_no_main-x86_64.a | grep LLVMFuzzerRunDriver.
At this point I decided to give a try to the other alternative, building libFuzzer from source and access to the no-main version which according to the documentation should be located at the following path in the build output directory: lib/linux/libclang_rt.fuzzer_no_main-<architecture>.a.
I followed the steps shown in https://clang.llvm.org/get_started.html (Building Clang and Working with the Code > On Unix-like Systems) however when running the `make` step I got the following error:
[ 61%] Built target LTO_exports
[ 61%] Linking CXX shared library ../../lib/libLTO.so
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
make[2]: *** [tools/lto/CMakeFiles/LTO.dir/build.make:258: lib/libLTO.so.14git] Error 1
make[2]: *** Deleting file 'lib/libLTO.so.14git'
make[1]: *** [CMakeFiles/Makefile2:31459: tools/lto/CMakeFiles/LTO.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
#include <stdint.h>
#include <stddef.h>
int LLVMFuzzerRunDriver(int *argc, char ***argv, int (*UserCb)(const uint8_t *Data, size_t Size));
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size > 0 && data[0] == 'H') {
if (size > 1 && data[1] == 'I') {
if (size > 2 && data[2] == '!') {
__builtin_trap();
}
}
}
return 0;
}
int main(int argc, char *argv[]) {
return LLVMFuzzerRunDriver(&argc, &argv, &LLVMFuzzerTestOneInput);
}
Will be grateful for any help and suggestions,
Kind Regards,
Alvaro Lopez.
--
You received this message because you are subscribed to the Google Groups "libfuzzer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libfuzzer+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/libfuzzer/6463b3e4-3017-4c0d-8ba6-8e10f9c391d7n%40googlegroups.com.