cargo-fuzz icon indicating copy to clipboard operation
cargo-fuzz copied to clipboard

Using multiple crate types leads to link errors

Open shahn opened this issue 7 years ago • 3 comments

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.

shahn avatar Apr 07 '17 19:04 shahn

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': /checkout/src/libcore/slice/mod.rs:1165: undefined reference to__sanitizer_cov' /checkout/src/libcore/slice/mod.rs:1165: undefined reference to __asan_option_detect_stack_use_after_return' /checkout/src/libcore/slice/mod.rs:1165: undefined reference to__sanitizer_cov' /checkout/src/libcore/slice/mod.rs:1165: undefined reference to __sanitizer_cov' /checkout/src/libcore/slice/mod.rs:1165: undefined reference to__asan_stack_malloc_0' /checkout/src/libcore/slice/mod.rs:1165: undefined reference to __sanitizer_cov' /checkout/src/libcore/slice/mod.rs:1165: undefined reference to__sanitizer_cov' /checkout/src/libcore/slice/mod.rs:1169: undefined reference to __asan_report_load8' /checkout/src/libcore/slice/mod.rs:1168: undefined reference to__sanitizer_cov' /checkout/src/libcore/slice/mod.rs:1170: undefined reference to __asan_report_load8' /checkout/src/libcore/slice/mod.rs:1172: undefined reference to__asan_report_load8' /checkout/src/libcore/slice/mod.rs:1172: undefined reference to `__asan_report_load8' ... another 1.3MB of errors

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

shahn avatar Apr 12 '17 13:04 shahn

Can you please provide a self-contained example? As a zip archive perhaps.

whitequark avatar Oct 05 '17 08:10 whitequark

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"].

laser avatar Jul 27 '18 21:07 laser