rust-fuzz / afl.rs

🐇 Fuzzing Rust code with American Fuzzy Lop

Home Page:https://rust-fuzz.github.io/book/afl.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"error: linking with `cc` failed: exit code: 1" when "cargo build"

sunchao opened this issue · comments

Sorry if there's already existing issue on this. I got this error while trying to compile:

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-arch" "x86_64" "-L" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.1qgdhmtsn5lnkv8j.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.2b5bdv1nfvan5wo1.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.2e6k6gzldepotkkr.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.2ehepex52twnu29.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.2feok7tp98zmgnqx.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.2xychraeh90cfvyi.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.35lh099spuo5afzi.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.39x11e5urcm3fll7.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.3cwyegk8qfy8j9jr.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.3hqbpq0vwailyg85.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.3llgle4mcv2gsa8b.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.3p3yr63cr3hnokmk.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.3yd6zwrr772y1jzg.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.4dx3ey5bw6285rcm.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.4tni8ozdhyumrdhl.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.4vjfltybq1x8h34a.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.5ar2ow9e817hmgli.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.cmoranf19ulut71.rcgu.o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.nb1d4f5id06cart.rcgu.o" "-o" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz" "/Users/foo/git/arrow/rust/target/debug/deps/parquet_fuzz.4t3yyk0lw5pr4p91.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/foo/git/arrow/rust/target/debug/deps" "-L" "/Users/foo/git/arrow/rust/target/debug/build/lz4-sys-75d1bf02c2659833/out" "-L" "/Users/foo/git/arrow/rust/target/debug/build/zstd-sys-54febe6eaf3ed3ea/out" "-L" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/foo/git/arrow/rust/target/debug/deps/libparquet-dc1bc7c62a38f07b.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libzstd-bb1c774ed3e9942a.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libzstd_safe-b3e0044f7a0b5401.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libzstd_sys-69b9b529b1294ea6.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/liblz4-f501a4c7a334df1f.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/liblz4_sys-9a84dee256a4b44a.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libbrotli-1b30fa1df8665d36.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libbrotli_decompressor-4a7720cd6922da57.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/liballoc_stdlib-cfc5257f59cf3a1e.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/liballoc_no_stdlib-f9b3124ebb1dbce0.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libbase64-6311ec00b7b3977f.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libflate2-c20ff256eb27ff2b.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libminiz_oxide-ed164e4d0059b7e7.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libadler-8a38c70c610d06bc.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libcrc32fast-14eca9e7134413d4.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libsnap-68ed89cd7a5a711f.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libparquet_format-3a03737573551aba.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libthrift-fcc8521cf5af0bef.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/liblog-a6baae9ff904adf7.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libthreadpool-4673b2b86b28a1ea.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libnum_cpus-bd5321ee38bd1d4d.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libinteger_encoding-99848279688d9dc1.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libordered_float-c5b63c753198dec8.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libarrow-c417cd30044805b5.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/liblexical_core-777fb7f94d521d2e.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libarrayvec-1a2eb6ba941e8301.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libstatic_assertions-f673896ca1b11add.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libcfg_if-50ed2fa15d067a29.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/librand-cd4a016769cf4943.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/librand_chacha-30b3e8dca27e5717.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libppv_lite86-e7bf5096a91c4751.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/librand_core-335ed890ef5bd0b6.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libgetrandom-bcbfc405de14b233.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libcfg_if-5440abaea1237bb7.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libflatbuffers-ec15b358a3b4cfd7.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libbitflags-41b8f8950e56a876.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libthiserror-c027f5b2cdd1f0bf.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libsmallvec-b2502309bd852f94.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libcsv-5fd93316bdda9d8c.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libcsv_core-69a12f11a329f151.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libbstr-a772769fb47f1424.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libregex_automata-d5a4ca174ae8ca28.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libbyteorder-8236ddd56c636592.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libregex-d1bd746e9d1e441a.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libthread_local-6fa356fc31fa5bcd.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/liblazy_static-9ef0ede18009bf0a.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libregex_syntax-ab13614efcfda18b.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libaho_corasick-fe82c42f86435c80.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libmemchr-12e438b079a3d1cb.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libserde_json-0656961d3dd5315a.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libryu-4636ec5641c33604.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libitoa-ebc28a1bf7410a52.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libindexmap-b7e44a71ecc17e2e.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libhashbrown-db7623be31193963.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libserde-d0bcddd6f89be62e.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libhex-8cdd8a8bec38bbe7.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libchrono-d909d761917eb7d4.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libtime-6fd8ab3934559031.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/liblibc-c4eb520d4d45515d.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libnum-7a6182b3b6760294.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libnum_iter-dc81085593559119.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libnum_rational-6c493fdd57fe6e0d.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libnum_complex-af1a67dad41e6d69.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libnum_bigint-907febf61642fa6f.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libnum_integer-d5413210bc4b167e.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libnum_traits-b6dd246bb4489433.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libafl-fae3892c7875ba66.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/librustc_version-c7df901fbdf57663.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libsemver-a70ef56560fee6a4.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libsemver_parser-a18caa8df7bbf9cf.rlib" "/Users/foo/git/arrow/rust/target/debug/deps/libxdg-e224ec04d8010fc4.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-518979da66993550.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-f52081aedccc205f.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-bad1c02788187328.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-6375d8dbf53aee9d.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-0ea8539778b0c0ab.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-64f30c6d69babb18.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-e27428d997fd2532.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-f02467a76e5a8054.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-9536efad7116d828.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-5ca171f6ec11d7a5.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-14b621861b38e51f.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-38f4a0c206512fa5.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-99bca6ace58141c5.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-72a66f4c97a4c0c8.rlib" "/Users/foo/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-e7cd9f0beed2fc0f.rlib" "-lSystem" "-lresolv" "-lc" "-lm"
  = note: Undefined symbols for architecture x86_64:
            "___afl_manual_init", referenced from:
                afl::fuzz::hb9502a6cad08967e in parquet_fuzz.4dx3ey5bw6285rcm.rcgu.o
            "___afl_persistent_loop", referenced from:
                afl::fuzz::hb9502a6cad08967e in parquet_fuzz.4dx3ey5bw6285rcm.rcgu.o
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: aborting due to previous error

error: could not compile `parquet_fuzz`

I'm on Mac OS and Clang info below:

Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

also rustc version:

rustc 1.49.0 (e1884a8e3 2020-12-29)

Anyone knows a workaround? thanks!

I am also experiencing this. Any help on this would be great! Thank you!

@mrthankyou Could you provide rustc --vesion and cargo afl --version? Also, what operating system are you using?

@smoelius - I'm also experiencing this. I'm on macOS.

$> uname -vrs
Darwin 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000

$> cargo --version
cargo 1.62.0 (a748cf5a3 2022-06-08)

$> rustc --version
rustc 1.62.0 (a8314ef7d 2022-06-27)

I'm building with the following:

$> cargo install afl --force --target=x86_64-apple-darwin
... snip, succeeds ...
$> cargo build --target=x86_64-apple-darwin
... snip, fails...
   Compiling trees v0.1.0 (/Users/dymk/code/rust/trees)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "-arch" "x86_64" (rest of command)
... snip ...
  = note: Undefined symbols for architecture x86_64:
            "___afl_manual_init", referenced from:
                afl::fuzz::h5911c415b0bde1e1 in trees-24efffd506f49991.45ov7a6lrmjkqhaf.rcgu.o
            "___afl_persistent_loop", referenced from:
                afl::fuzz::h5911c415b0bde1e1 in trees-24efffd506f49991.45ov7a6lrmjkqhaf.rcgu.o
            "___afl_fuzz_len", referenced from:
                afl::fuzz::h5911c415b0bde1e1 in trees-24efffd506f49991.45ov7a6lrmjkqhaf.rcgu.o
            "___afl_fuzz_ptr", referenced from:
                afl::fuzz::h5911c415b0bde1e1 in trees-24efffd506f49991.45ov7a6lrmjkqhaf.rcgu.o
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Thanks for the detailed output, @dymk.

I think I see the problem. One has to use cargo afl build, not cargo build. (The former tells rustc where to find the AFL libraries.)

I'm sorry I didn't spot this sooner. I'm such a moron.

Thank you! This fixed the issue for me.

@sunchao @mrthankyou Does this fix this issue for you as well? Could we possibly close this issue?

@smoelius let me try it and reply here, thanks

any chance we can get this added to the help printed for cargo afl just spent last 3h trying to figure out how to reproduce a test case Or (nvm I saw the cargo command oneliner at the top) but it would be great to get a step in the documentation on how to reproduce crashes for debugging?

it would be great to get a step in the documentation on how to reproduce crashes for debugging?

Do you mean how to rerun the target on an entry in the crashes or hangs directory?

I think the user has to do this themselves. I don't think AFLplusplus provides a solution for this. (I'd be happy to be corrected.)

At the risk of seeming self-promoting, this was one of the reasons why I created test-fuzz.

Do you mean how to rerun the target on an entry in the crashes or hangs directory?

I think the user has to do this themselves. I don't think AFLplusplus provides a solution for this. (I'd be happy to be corrected.)

If you can find cargo afl run then you can just pass the test case back in via stdin

Huh, I guess that will work in most situations.

Would you like to propose a change to the documentation?

Huh, I guess that will work in most situations.

Would you like to propose a change to the documentation?

Sure i will try and send a PR tomorrow