Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo afl test fails linking when encountering doctests #142

Closed
SingingTree opened this issue Oct 18, 2018 · 1 comment
Closed

cargo afl test fails linking when encountering doctests #142

SingingTree opened this issue Oct 18, 2018 · 1 comment

Comments

@SingingTree
Copy link
Contributor

When running cargo afl test doctests result in linking errors. Steps to reproduce:

  1. (Work around Troubleshooting: linking with cc failed #141) export RUSTFLAGS=-Clink-arg=-fuse-ld=gold
  2. Create a minimal lib: cargo new --lib afl_rs_doctest
  3. Set contents of lib.rs to:
//! # Examples
//! ```
//! extern crate afl_rs_doctest;
//! assert_eq!(afl_rs_doctest::foo(), 1);
//! ```


pub fn foo() -> u8 {
    0x01
}
  1. Try and test with afl: cargo afl test

Results in:

b@b-virtual-machine ~/projects/afl_rs_doctest $ cargo afl test
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s                                                                                                                                                 
     Running target/debug/deps/afl_rs_doctest-752d43b7c98a3a98

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests afl_rs_doctest

running 1 test
test src/lib.rs -  (line 2) ... FAILED

failures:

---- src/lib.rs -  (line 2) stdout ----
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/b/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/rustdoctestieMm5E/rust_out.rust_out.7rcbfp3g-cgu.0.rcgu.o" "/tmp/rustdoctestieMm5E/rust_out.rust_out.7rcbfp3g-cgu.1.rcgu.o" "/tmp/rustdoctestieMm5E/rust_out.rust_out.7rcbfp3g-cgu.2.rcgu.o" "/tmp/rustdoctestieMm5E/rust_out.rust_out.7rcbfp3g-cgu.3.rcgu.o" "/tmp/rustdoctestieMm5E/rust_out.rust_out.7rcbfp3g-cgu.4.rcgu.o" "/tmp/rustdoctestieMm5E/rust_out.rust_out.7rcbfp3g-cgu.5.rcgu.o" "/tmp/rustdoctestieMm5E/rust_out.rust_out.7rcbfp3g-cgu.6.rcgu.o" "-o" "/tmp/rustdoctestieMm5E/rust_out" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/b/projects/afl_rs_doctest/target/debug/deps" "-L" "/home/b/projects/afl_rs_doctest/target/debug/deps" "-L" "/home/b/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/b/projects/afl_rs_doctest/target/debug/deps/libafl_rs_doctest-4fc61169c7b196d3.rlib" "-Wl,--start-group" "-L" "/home/b/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lstd-a27f61c2a32117a5" "-Wl,--end-group" "-Wl,-Bstatic" "/home/b/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-f97f39378674ae7b.rlib" "-Wl,-Bdynamic" "-lafl-llvm-rt" "-ldl" "-lrt" "-lpthread" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
  = note: /usr/bin/ld: cannot find -lafl-llvm-rt
          collect2: error: ld returned 1 exit status
          

thread 'src/lib.rs -  (line 2)' panicked at 'couldn't compile the test', librustdoc/test.rs:333:13
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    src/lib.rs -  (line 2)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--doc'
SingingTree added a commit to SingingTree/afl.rs that referenced this issue Oct 21, 2018
Per issue rust-fuzz#142, `cargo afl test` and other commands that would run
doctests would encounter issues with linkage. This commit changes `cargo
afl` to set RUSTDOCFLAGS so rustdoc will be able to find the required
libs. Further options are passed to ensure doctests are built and run in
as similar a fashion to other code. This avoids other gotchas like cfg
fuzzing being set for normal builds, but not for doctests.
frewsxcv pushed a commit that referenced this issue Oct 22, 2018
Per issue #142, `cargo afl test` and other commands that would run
doctests would encounter issues with linkage. This commit changes `cargo
afl` to set RUSTDOCFLAGS so rustdoc will be able to find the required
libs. Further options are passed to ensure doctests are built and run in
as similar a fashion to other code. This avoids other gotchas like cfg
fuzzing being set for normal builds, but not for doctests.
@frewsxcv
Copy link
Member

fixed in #143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants