Hi,
I'm using afl-fuzz to find bugs in rawspeed[1], a raw loading library.
I wrote a small program[2] to exercise the library and have been
fuzzing that with great success (quite a few issues already fixed). To
make the fuzzing faster I wanted to be able to compile with
afl-clang-fast as rawspeed needs to load a large XML with camera
definitions in the beginning so being able to place __AFL_INIT() after
that should make for a nice speedup. Unfortunately it seems
afl-clang-fast breaks our cmake build (afl-gcc and afl-clang both work
fine).
The cmake run seems to break when trying to compile things. For
example the ABI detection fails with linking issues:
"/usr/bin/ld" -export-dynamic -z relro --hash-style=gnu --build-id
--eh-frame-hdr -m elf_x86_64 -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -o cmTryCompileExec1174673255
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o
-L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
-L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu
-L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../..
-L/usr/lib/llvm-3.6/bin/../lib -L/lib -L/usr/lib
CMakeFiles/cmTryCompileExec1174673255.dir/CMakeCXXCompilerABI.cpp.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/crtend.o
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
CMakeFiles/cmTryCompileExec1174673255.dir/CMakeCXXCompilerABI.cpp.o:
In function `main':
/usr/share/cmake-2.8/Modules/CMakeCXXCompilerABI.cpp:11: undefined
reference to `__afl_prev_loc'
/usr/share/cmake-2.8/Modules/CMakeCXXCompilerABI.cpp:11: undefined
reference to `__afl_area_ptr'
/usr/share/cmake-2.8/Modules/CMakeCXXCompilerABI.cpp:11: undefined
reference to `__afl_prev_loc'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The full log of that error is here:
https://gist.github.com/pedrocr/fda14ef788e673ac6a30
I've googled around for similar issues but couldn't find any. I'm
using Ubuntu 14.04, afl-fuzz 1.96b and have tried this with clang 3.4
and 3.6. Building CMakeCXXCompilerABI.cpp by itself seems to work fine
so I'm guessing there's something strange with the way the compilation
is being run. All those gcc things are also quite strange, so maybe
cmake is misdetecting afl-clang-fast as gcc somehow.
Anyone have any ideas about this?
Cheers,
Pedro
[1]
https://github.com/klauspost/rawspeed
[2]
https://github.com/darktable-org/darktable/blob/master/src/external/rawspeed/rawspeed-identify.cpp