cargo-fuzz
cargo-fuzz copied to clipboard
Using multiple crate types leads to link errors
For fuzzing, I always have to make sure my crate type is set to rlib, or rlib and staticlib. Reversing the order or adding the bin crate type leads to link errors. Is this expected or specific to my setup? Happy to provide a sample if necessary.
More information:
Of course, here we go for the various combinations:
rlib + bin, bin + rlib, staticlib + bin, bin + staticlib:
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/fuzz/target/x86_64-unknown-linux-gnu/debug/deps/consdiff-876121c7e733b4a7.0.o" "-o" "/fuzz/target/x86_64-unknown-linux-gnu/debug/deps/consdiff-876121c7e733b4a7" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/fuzz/target/x86_64-unknown-linux-gnu/debug/deps" "-L" "/fuzz/target/debug/deps" "-L" "../../common" "-L" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l" "or-ctime" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-l" "or-testing" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "/fuzz/target/x86_64-unknown-linux-gnu/debug/deps/liblibc-5dc7b85e748840b4.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-f4594d3e53dcb114.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-1efbcfd8938372b6.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-532a3dbf317eff86.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-cfbd6648f7db2ee5.rlib" "/fuzz/target/x86_64-unknown-linux-gnu/debug/deps/libtiny_keccak-fbf86ba37ae3101c.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-488b4ab4bd53a138.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ca07b617414dd0fa.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-492d8ea7fa3384ff.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_abort-6800222f9a60165a.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-88c194c15fdb6521.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-687e6a964d22cbb4.rlib" "/home/shahn/.rustup/toolchains/nightly-2017-03-28-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-987729be881d4d32.rlib" "-l" "util" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util"
= note: /fuzz/target/x86_64-unknown-linux-gnu/debug/deps/consdiff-876121c7e733b4a7.0.o: In function core::slice::{{impl}}::next_back
staticlib + rlib: Running rustc --crate-name consdiff lib.rs --crate-type staticlib --crate-type rlib --e error: Only executables and rlibs can be compiled with-Z sanitizer`
rlib, rlib + staticlib: works
Can you please provide a self-contained example? As a zip archive perhaps.
I am also seeing this behavior. The archive (.a
) produced when my [lib]
's crate-type
equals ["staticlib"]
is different (and results in errors at link-time) than when crate-type
equals ["staticlib", "lib"]
.