AFLplusplus / LibAFL

Advanced Fuzzing Library - Slot your Fuzzer together in Rust! Scales across cores and machines. For Windows, Android, MacOS, Linux, no_std, ...
Other
2.05k stars 322 forks source link

Building libfuzzer_stb_image on Windows #1652

Closed mkravchik closed 1 year ago

mkravchik commented 1 year ago

IMPORTANT

  1. You have verified that the issue to be present in the current main branch

Thank you for making LibAFL better!

Describe the bug I'm new to LibAFL and am interested in the Windows setup. I followed the instructions, installed Rust, clang, and LLVM (17.0.4). LLVM's bin directory is in the PATH. Next, I tried to build a fuzzer that is supposed to work on Windows, libfuzzer_stb_image. The build fails. I would appreciate having a short tutorial what can be run on Windows as of now and if there are any additional steps to get it working.

To Reproduce Steps to reproduce the behavior:

  1. Complete all the steps in https://github.com/AFLplusplus/LibAFL/blob/main/docs/src/getting_started/setup.md
  2. cd fuzzers/libfuzzer_stb_image. Run cargo build --release

Expected behavior The fuzzer builds successfully.

Screen output/Screenshots Compiling libfuzzer_stb_image v0.11.1 (C:\LibAFL\fuzzers\libfuzzer_stb_image) error: failed to run custom build command for libafl_targets v0.11.1 (C:\LibAFL\libafl_targets)

Caused by: process didn't exit successfully: C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-0f4bc85774200502\build-script-build (exit code: 1) --- stdout cargo:rerun-if-env-changed=LIBAFL_EDGES_MAP_SIZE cargo:rerun-if-env-changed=LIBAFL_CMP_MAP_SIZE cargo:rerun-if-env-changed=LIBAFL_AFLPP_CMPLOG_MAP_W cargo:rerun-if-env-changed=LIBAFL_AFLPP_CMPLOG_MAP_H cargo:rerun-if-env-changed=LIBAFL_CMPLOG_MAP_W cargo:rerun-if-env-changed=LIBAFL_CMPLOG_MAP_H cargo:rerun-if-env-changed=LIBAFL_ACCOUNTING_MAP_SIZE cargo:rerun-if-changed=src/sancov_cmp.c cargo:rustc-link-arg=--undefined=sanitizer_weak_hook_memcmp cargo:rustc-link-arg=--undefined=__sanitizer_weak_hook_strncmp cargo:rustc-link-arg=--undefined=sanitizer_weak_hook_strncasecmp cargo:rustc-link-arg=--undefined=__sanitizer_weak_hook_strcmp cargo:rustc-link-arg=--undefined=__sanitizer_weak_hook_strcasecmp TARGET = Some("x86_64-pc-windows-msvc") OPT_LEVEL = Some("3") HOST = Some("x86_64-pc-windows-msvc") cargo:rerun-if-env-changed=CC_x86_64-pc-windows-msvc CC_x86_64-pc-windows-msvc = None cargo:rerun-if-env-changed=CC_x86_64_pc_windows_msvc CC_x86_64_pc_windows_msvc = None cargo:rerun-if-env-changed=HOST_CC HOST_CC = None cargo:rerun-if-env-changed=CC CC = None cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2") DEBUG = Some("true") cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-msvc CFLAGS_x86_64-pc-windows-msvc = None cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_msvc CFLAGS_x86_64_pc_windows_msvc = None cargo:rerun-if-env-changed=HOST_CFLAGS HOST_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = Some("") running: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe" "-nologo" "-MD" "-O2" "-Z7" "-Brepro" "-DSANCOV_CMPLOG=1" "-DCMP_MAP_SIZE=65536" "-DAFLPP_CMPLOG_MAP_W=65536" "-DAFLPP_CMPLOG_MAP_H=32" "-DCMPLOG_MAP_W=65536" "-DCMPLOG_MAP_H=32" "-FoC:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out\src\sancov_cmp.o" "-c" "src\sancov_cmp.c" sancov_cmp.c src\sancov_cmp.c(9): fatal error C1083: Cannot open include file: 'sanitizer/common_interface_defs.h': No such file or directory exit code: 2

Additional context Add any other context about the problem here.

mkravchik commented 1 year ago

The problem is in libafl_targets. I get the same problem when I try to build it on its own or when trying to build other crates that depend on it (e.g. libafl_frida)

mkravchik commented 1 year ago

This H file comes from the LLVM includes. By default, they are not added to the INCLUDE path. If I add them using CFLAGS, the compilation fails, as MSVC's cl.exe can't process the LLVM includes. I'd appreciate some help in setting this correctly.

tokatoka commented 1 year ago

yes i know what causes it. i'll quickly fix

tokatoka commented 1 year ago

well, the problem i thought was the cause is not related. how did you install llvm?

mkravchik commented 1 year ago

I downloaded LLVM-17.0.1-win64.exe from Releases. I first installed it in Program Files. Then I saw that the space in the path causes problems in CFLAGS. So I copied it over to c:\LLVM and updated the PATH. How should the integration between msvc and llvm work?

tokatoka commented 1 year ago

it's clang that is called from build.rs to compile the stuff not cl.exe what is the error you saw when you includes the llvm headers?

mkravchik commented 1 year ago

I can clearly see it is cl.exe that is called. Please see the error print above. When I build libafl_targets by itself, it compiles 4 files (common, coverage, libcmp, windows_asan) using cl.exe and they are compiled successfully. When I build libafl_frida, it tries to build sancov_cmp.c using cl.exe. When I add LLVM headers it produces loads of warnings and errors like: CFLAGS = Some("-IC:\LLVM\lib\clang\17\include") running: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe" "-nologo" "-MD" "-O2" "-Z7" "-Brepro" "-IC:\LLVM\lib\clang\17\include" "-DSANCOV_CMPLOG=1" "-DCMP_MAP_SIZE=65536" "-DAFLPP_CMPLOG_MAP_W=65536" "-DAFLPP_CMPLOG_MAP_H=32" "-DCMPLOG_MAP_W=65536" "-DCMPLOG_MAP_H=32" "-FoC:\LibAFL\fuzzers\frida_libpng\target\release\build\libafl_targets-e5d08c87abdadb46\out\src\sancov_cmp.o" "-c" "src\sancov_cmp.c" sancov_cmp.c C:\LLVM\lib\clang\17\include\stdint.h(20): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stdint.h(291): error C2061: syntax error: identifier 'intptr_t' C:\LLVM\lib\clang\17\include\stdint.h(291): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\stdint.h(298): error C2061: syntax error: identifier 'uintptr_t' C:\LLVM\lib\clang\17\include\stdint.h(298): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\stdint.h(304): error C2061: syntax error: identifier 'intmax_t' C:\LLVM\lib\clang\17\include\stdint.h(304): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\stdint.h(305): error C2061: syntax error: identifier 'uintmax_t' C:\LLVM\lib\clang\17\include\stdint.h(305): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\stddef.h(18): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stddef.h(30): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stddef.h(32): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stddef.h(35): error C2061: syntax error: identifier 'ptrdiff_t' C:\LLVM\lib\clang\17\include\stddef.h(35): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\stddef.h(41): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stddef.h(43): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stddef.h(46): error C2054: expected '(' to follow 'SIZE_TYPE' C:\LLVM\lib\clang\17\include\stddef.h(55): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stddef.h(67): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stddef.h(68): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\LLVM\lib\clang\17\include\stddef.h(74): error C2085: 'WCHAR_TYPE': not in formal parameter list C:\LLVM\lib\clang\17\include\stddef.h(74): error C2146: syntax error: missing ',' before identifier 'wchar_t' C:\LibAFL\libafl_targets\src\cmplog.h(23): error C2061: syntax error: identifier 'uint16_t' C:\LibAFL\libafl_targets\src\cmplog.h(24): error C2061: syntax error: identifier 'shape' C:\LibAFL\libafl_targets\src\cmplog.h(24): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(25): error C2061: syntax error: identifier 'kind' C:\LibAFL\libafl_targets\src\cmplog.h(25): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(26): error C2059: syntax error: '}' C:\LibAFL\libafl_targets\src\cmplog.h(52): error C2061: syntax error: identifier 'uint64_t' C:\LibAFL\libafl_targets\src\cmplog.h(53): error C2061: syntax error: identifier 'v1' C:\LibAFL\libafl_targets\src\cmplog.h(53): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(54): error C2059: syntax error: '}' C:\LibAFL\libafl_targets\src\cmplog.h(57): error C2061: syntax error: identifier 'uint8_t' C:\LibAFL\libafl_targets\src\cmplog.h(58): error C2061: syntax error: identifier 'v1' C:\LibAFL\libafl_targets\src\cmplog.h(58): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(58): error C2059: syntax error: '[' C:\LibAFL\libafl_targets\src\cmplog.h(59): error C2059: syntax error: '}' C:\LibAFL\libafl_targets\src\cmplog.h(62): error C2061: syntax error: identifier 'CmpLogHeader' C:\LibAFL\libafl_targets\src\cmplog.h(64): error C2061: syntax error: identifier 'CmpLogInstruction' C:\LibAFL\libafl_targets\src\cmplog.h(65): error C2061: syntax error: identifier 'routines' C:\LibAFL\libafl_targets\src\cmplog.h(65): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(65): error C2059: syntax error: '[' C:\LibAFL\libafl_targets\src\cmplog.h(66): error C2059: syntax error: '}' C:\LibAFL\libafl_targets\src\cmplog.h(67): error C2059: syntax error: '}' C:\LibAFL\libafl_targets\src\cmplog.h(72): error C2061: syntax error: identifier 'CmpLogInstruction' C:\LibAFL\libafl_targets\src\cmplog.h(73): error C2061: syntax error: identifier 'routines' C:\LibAFL\libafl_targets\src\cmplog.h(73): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(73): error C2059: syntax error: '[' C:\LibAFL\libafl_targets\src\cmplog.h(74): error C2059: syntax error: '}' C:\LibAFL\libafl_targets\src\cmplog.h(75): error C2059: syntax error: '}' C:\LibAFL\libafl_targets\src\cmplog.h(77): error C2061: syntax error: identifier 'libafl_cmplog_map' C:\LibAFL\libafl_targets\src\cmplog.h(77): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(78): error C2143: syntax error: missing '{' before '' C:\LibAFL\libafl_targets\src\cmplog.h(80): error C2061: syntax error: identifier 'libafl_cmplog_map_extended' C:\LibAFL\libafl_targets\src\cmplog.h(80): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(81): error C2143: syntax error: missing '{' before '' C:\LibAFL\libafl_targets\src\cmplog.h(83): error C2061: syntax error: identifier 'libafl_cmplog_enabled' C:\LibAFL\libafl_targets\src\cmplog.h(83): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(85): error C2146: syntax error: missing ')' before identifier 'k' C:\LibAFL\libafl_targets\src\cmplog.h(85): error C2061: syntax error: identifier 'k' C:\LibAFL\libafl_targets\src\cmplog.h(85): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(85): error C2059: syntax error: ',' C:\LibAFL\libafl_targets\src\cmplog.h(86): error C2059: syntax error: ')' C:\LibAFL\libafl_targets\src\cmplog.h(88): error C2146: syntax error: missing ')' before identifier 'k' C:\LibAFL\libafl_targets\src\cmplog.h(88): error C2061: syntax error: identifier 'k' C:\LibAFL\libafl_targets\src\cmplog.h(88): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(88): error C2059: syntax error: ',' C:\LibAFL\libafl_targets\src\cmplog.h(89): error C2059: syntax error: ')' C:\LibAFL\libafl_targets\src\cmplog.h(91): error C2146: syntax error: missing ')' before identifier 'k' C:\LibAFL\libafl_targets\src\cmplog.h(91): error C2061: syntax error: identifier 'k' C:\LibAFL\libafl_targets\src\cmplog.h(91): error C2059: syntax error: ';' C:\LibAFL\libafl_targets\src\cmplog.h(91): error C2059: syntax error: ',' C:\LibAFL\libafl_targets\src\cmplog.h(92): error C2059: syntax error: ')' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(33): error C2061: syntax error: identifier 'intptr_t' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(39): error C2059: syntax error: '}' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(53): error C2143: syntax error: missing ')' before '' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(53): error C2143: syntax error: missing '{' before '' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(53): error C2059: syntax error: ')' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(69): error C2061: syntax error: identifier 'sanitizer_unaligned_load16' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(69): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(69): error C2059: syntax error: '' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(76): error C2061: syntax error: identifier 'sanitizer_unaligned_load32' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(76): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(76): error C2059: syntax error: '' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(83): error C2061: syntax error: identifier '__sanitizer_unaligned_load64' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(83): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(83): error C2059: syntax error: '' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(89): error C2146: syntax error: missing ')' before identifier 'x' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(89): error C2081: 'uint16_t': name in formal parameter list illegal C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(89): error C2061: syntax error: identifier 'x' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(89): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(89): error C2059: syntax error: ')' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(95): error C2146: syntax error: missing ')' before identifier 'x' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(95): error C2081: 'uint32_t': name in formal parameter list illegal C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(95): error C2061: syntax error: identifier 'x' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(95): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(95): error C2059: syntax error: ')' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(101): error C2146: syntax error: missing ')' before identifier 'x' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(101): error C2081: 'uint64_t': name in formal parameter list illegal C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(101): error C2061: syntax error: identifier 'x' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(101): error C2059: syntax error: ';' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(101): error C2059: syntax error: ')' C:\LLVM\lib\clang\17\include\sanitizer/common_interface_defs.h(289): error C2059: syntax error: 'string' src\sancov_cmp.c(12): error C2146: syntax error: missing ')' before identifier 'arg1' src\sancov_cmp.c(12): error C2061: syntax error: identifier 'arg1' src\sancov_cmp.c(12): error C2059: syntax error: ';' src\sancov_cmp.c(12): error C2059: syntax error: ',' src\sancov_cmp.c(12): error C2059: syntax error: ')' src\sancov_cmp.c(26): error C2146: syntax error: missing ')' before identifier 'arg1' src\sancov_cmp.c(26): error C2061: syntax error: identifier 'arg1' src\sancov_cmp.c(26): fatal error C1003: error count exceeds 100; stopping compilation exit code: 2

--- stderr

error occurred: Command "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe" "-nologo" "-MD" "-O2" "-Z7" "-Brepro" "-IC:\LLVM\lib\clang\17\include" "-DSANCOV_CMPLOG=1" "-DCMP_MAP_SIZE=65536" "-DAFLPP_CMPLOG_MAP_W=65536" "-DAFLPP_CMPLOG_MAP_H=32" "-DCMPLOG_MAP_W=65536" "-DCMPLOG_MAP_H=32" "-FoC:\LibAFL\fuzzers\frida_libpng\target\release\build\libafl_targets-e5d08c87abdadb46\out\src\sancov_cmp.o" "-c" "src\sancov_cmp.c" with args "cl.exe" did not execute successfully (status code exit code: 2).

mkravchik commented 1 year ago

I ran unix2dos on all H files in the LLVM include

tokatoka commented 1 year ago

i think the problem comes from unix2dos. why do you need it?

mkravchik commented 1 year ago

I thought it was needed because of the newlines. But I have reinstalled LLVM and now it has Linux end of lines. Regardless, I see the same behavior - cl.exe is run and not clang. And cl.exe does not like clang's headers. How is it supposed to work? Where should the compiler be selected? Maybe I need to reinstall the cc crate of something like this?

tokatoka commented 1 year ago

cl.exe is used to compile the llvm pass into a dll

then clang is used to compile the fuzzer libfuzzer_stb_image which uses the dll that was compiled before.

tokatoka commented 1 year ago

cl.exe is run and not clang. And cl.exe does not like clang's headers.

if the failure is in libafl_targets then yes it's all about cl.exe

And cl.exe does not like clang's headers.

what's the error if you don't use dos2unix? are you perhaps using cygwin or msys2? If so you should try this with powershell because i never tested this on cygwin or msys2

mkravchik commented 1 year ago

I'm using the original (not converted) LLVM headers now. They only have \n. I was indeed compiling in Git Bash. I tried now in Powershell and get exactly the same behavior (not finding the LLVM headers without CFLAGS and failing cl.exe on compiling LLVM headers with CFLAGS): image

tokatoka commented 1 year ago

honestly i don't know what is the cause. libafl_targets is building in our CI so i think it's something with your setup.

tokatoka commented 1 year ago

how did you install cl.exe

mkravchik commented 1 year ago

cl.exe comes from Visual Studio I had installed before installing LLVM. I want to stress: libaft_targets builds when I build it on its own. Only when I build libafl_frida, it builds more files from libaft_targets and these require LLVM headers

tokatoka commented 1 year ago

Only when I build libafl_frida, it builds more files from libaft_targets and these require LLVM headers

yes because of common_interface_defs.h which is required by frida build. but that one also works in windows CI.

tokatoka commented 1 year ago

can you update your visual studio to 2022 and see if it fixes it?

mkravchik commented 1 year ago

I confirm that installing VS 2022 resolves the compilation issue. VS2022 comes with the required files and we don't need to add external LLVM.

mkravchik commented 1 year ago
Unfortunately, not everything has been resolved. After updating to VS 2022 libafl_frida is being built correctly, but libfuzzer_stb_image is not: warning: __sanitizer_set_death_callback redeclared with a different signature --> C:\LibAFL\libafl_targets\src\windows_asan.rs:15:5 15 fn __sanitizer_set_death_callback(cb: CB); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
::: C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out/sanitizer_interfaces.rs:260:5 260 pub fn __sanitizer_set_death_callback(callback: ::core::option::Option<unsafe extern "C" fn()>); ----------------------------------------------------------------------------------------------- __sanitizer_set_death_callback previously declared here
= note: expected `unsafe extern "C" fn(core::option::Option<unsafe extern "C" fn()>)`
           found `unsafe extern "C" fn(unsafe extern "C" fn())`
= note: `#[warn(clashing_extern_declarations)]` on by default

warning: libafl_targets (lib) generated 1 warning warning: libafl (lib) generated 1 warning error: linking with link.exe failed: exit code: 1120 | = note: "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\link.exe" "/NOLOGO" "C:\Users\mkrav\AppData\Local\Temp\rustc2tUhqP\symbols.o" "C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\deps\libfuzzer_stb_image.libfuzzer_stb_image.50629f7fe474387d-cgu.0.rcgu.o" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\deps" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libfuzzer_stb_image-0e5ba3b9e0cd37eb\out" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libfuzzer_stb_image-0e5ba3b9e0cd37eb\out" "/LIBPATH:C:\Users\mkrav\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_msvc-0.48.5\lib" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\atlmfc\lib\x64" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\atlmfc\lib\x64" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\atlmfc\lib\x64" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\atlmfc\lib\x64" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\atlmfc\lib\x64" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\atlmfc\lib\x64" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libafl_targets-796f3221e0432581\out" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.37.32822\atlmfc\lib\x64" "/LIBPATH:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\build\libmimalloc-sys-912fc62ed971a7b8\out" "/LIBPATH:C:\Users\mkrav\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib" "harness.lib" "C:\Users\mkrav\AppData\Local\Temp\rustc2tUhqP\liblibafl_targets-29d57f53f0080807.rlib" "C:\Users\mkrav\AppData\Local\Temp\rustc2tUhqP\liblibmimalloc_sys-493a7050e04f4994.rlib" "C:\Users\mkrav\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcompiler_builtins-9dbc16e13c04d841.rlib" "kernel32.lib" "windows.0.48.5.lib" "advapi32.lib" "cfgmgr32.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "opengl32.lib" "synchronization.lib" "user32.lib" "winspool.lib" "windows.0.48.5.lib" "windows.0.48.5.lib" "bcrypt.lib" "advapi32.lib" "legacy_stdio_definitions.lib" "kernel32.lib" "advapi32.lib" "bcrypt.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "kernel32.lib" "ws2_32.lib" "kernel32.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\Users\mkrav\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib" "/OUT:C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\deps\libfuzzer_stb_image.exe" "/OPT:REF,ICF" "/DEBUG" "/NATVIS:C:\Users\mkrav\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\etc\intrinsic.natvis" "/NATVIS:C:\Users\mkrav\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\etc\liballoc.natvis" "/NATVIS:C:\Users\mkrav\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\etc\libcore.natvis" "/NATVIS:C:\Users\mkrav\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\etc\libstd.natvis" = note: liblibafl_targets-29d57f53f0080807.rlib(libfuzzer.o) : error LNK2005: main already defined in libfuzzer_stb_image.libfuzzer_stb_image.50629f7fe474387d-cgu.0.rcgu.o Creating library C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\deps\libfuzzer_stb_image.lib and object C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\deps\libfuzzer_stb_image.exp liblibafl_targets-29d57f53f0080807.rlib(libfuzzer.o) : error LNK2019: unresolved external symbol LLVMFuzzerRunDriver referenced in function main C:\LibAFL\fuzzers\libfuzzer_stb_image\target\release\deps\libfuzzer_stb_image.exe : fatal error LNK1120: 1 unresolved externals

The following warnings were emitted during compilation:

warning: In file included from ./harness.c:10: warning: ./stb_image.h:7307:15: warning: variable 'out_size' set but not used [-Wunused-but-set-variable] warning: 7307 | int out_size = 0; warning: | ^ warning: ./stb_image.h:7308:15: warning: variable 'delays_size' set but not used [-Wunused-but-set-variable] warning: 7308 | int delays_size = 0; warning: | ^ warning: 2 warnings generated.

error: could not compile libfuzzer_stb_image (bin "libfuzzer_stb_image") due to previous error

tokatoka commented 1 year ago

i think #981 broke it

tokatoka commented 1 year ago

can you add "libfuzzer_define_run_driver" to libafl_target's feature in libfuzzer_stb_image/Cargo.toml to see if it is fixed?

mkravchik commented 1 year ago

Added, but it did not resolve the issue. When I look at the code, I see no implementation of LLVMFuzzerRunDriver in libfuzzer.c of libafl_targets, just its declaration. The linker can't find a library where the function is implemented.

tokatoka commented 1 year ago

i got it. to stb_image/Cargo.toml add libfuzzer_no_link_main feature to libafl_targets then it will work