Linking error when trying out "-C instrument-coverage"

I wanted to try out the Source-based Code Coverage that landed in 1.60 stable, but unfortunately keep running in to the following linking issue.

[hello_world]$ RUSTFLAGS="-C instrument-coverage" cargo  build

   Compiling hello_world v0.1.0 (/home/user/hello_world)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.1dbgi0hg218ce05g.rcgu.o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.25sb1kmiq3x0ri3w.rcgu.o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.3m88nn80cdqf6ikc.rcgu.o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.3t99f1n3qetw4447.rcgu.o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.4ggpncviy3cxwepw.rcgu.o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.4pjj0ikp25l2lw8r.rcgu.o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.4xgalkh9n7u7k2ee.rcgu.o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.5aqmq1on0hf8t0az.rcgu.o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e.2g2tcfy0gnfmk43k.rcgu.o" "-Wl,--as-needed" "-L" "/home/user/hello_world/target/debug/deps" "-L" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libprofiler_builtins-66194a1bb0f372d0.rlib" "-Wl,--start-group" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f2400674c7513725.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-605c3a7d1a5d300d.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-3d4fb4efa907e4e8.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-65207f030ab23308.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-76ca199cb0186109.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-1e3e01ed4f561dc1.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-dd8dddcba7c13fee.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-00b13d31c3420656.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e4c8460b81557bd5.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-600d46e5f0005455.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-e4a08a2585b62d37.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fbc21ec567cb9dc7.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-10b3fa8e49bd978f.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-64625b73694ffce7.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-fb6b78ac543a58ee.rlib" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-1d1f2d1bec6f51b8.rlib" "-Wl,--end-group" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-acf5ff6e9595d982.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/user/hello_world/target/debug/deps/hello_world-7e1388466052de4e" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs" "-u" "__llvm_profile_runtime"
  = note: /usr/bin/ld: /home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libprofiler_builtins-66194a1bb0f372d0.rlib(InstrProfilingFile.o): unrecognized relocation (0x2a) in section `.text.parseAndSetFilename'
          /usr/bin/ld: final link failed: Bad value
          collect2: error: ld returned 1 exit status
          
error: could not compile `hello_world` due to previous error

below is my Rust version info:

rustc --verbose --version
rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-unknown-linux-gnu
release: 1.60.0
LLVM version: 14.0.0

I've also done
rustup component add llvm-tools-preview
but that didn't seem to change anything?

Any insight would be great, thanks!

What version of binutils do you have? (for /usr/bin/ld)

Not related to the issue at hand, but I recommend you check out cargo-llvm-cov. It makes it far easier to generate coverage reports.

Its fairly old... 2.25 so that may be the issue

thanks, I'll check it out!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.