Repository navigation
Closed
Labels
A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-macosOperating system: macOS
Description
I'm integrating grcov and have macOS build failures with a linkage error while both -Zprofile and -Clink-dead-code flags enabled.
Consider a cargo project with the following manifest:
[package]
name = "foo"
version = "0.1.0"
authors = ["me"]
edition = "2018"
[dependencies]
core-foundation = "0.6.4"and the src/main.rs file:
use core_foundation::dictionary::CFMutableDictionary;
use core_foundation::number::CFNumber;
fn main() {
let mut dict = CFMutableDictionary::new();
let key = CFNumber::from(1);
let value = CFNumber::from(2);
dict.add(&key, &value);
dbg!(dict.len());
}Plain cargo run successfully compiles and run the binary (no additional env vars set):
$ cargo run
Compiling foo v0.1.0 (/Users/apple/Desktop/foo)
Finished dev [unoptimized + debuginfo] target(s) in 0.41s
Running `target/debug/foo`
[src/main.rs:10] dict.len() = 1
Now, as described in the gcov readme I add the necessary flags:
$ cargo clean
$ CARGO_INCREMENTAL=0 RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads" cargo run
Compiling libc v0.2.60
Compiling core-foundation-sys v0.6.2
Compiling core-foundation v0.6.4
Compiling foo v0.1.0 (/Users/apple/Desktop/foo)
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-m64" "-L" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/apple/Desktop/foo/target/debug/deps/foo-43971b11e9fc60ca.foo.ayycu2cz-cgu.0.rcgu.o" "-o" "/Users/apple/Desktop/foo/target/debug/deps/foo-43971b11e9fc60ca" "/Users/apple/Desktop/foo/target/debug/deps/foo-43971b11e9fc60ca.8f4xgbrv4jev7ka.rcgu.o" "-nodefaultlibs" "-L" "/Users/apple/Desktop/foo/target/debug/deps" "-L" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libtest-2f2c545f20952714.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libterm-d31c4cfba4ff2a7a.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgetopts-2b60fe103d1e455e.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunicode_width-7d268ed1d33eabb7.rlib" "/Users/apple/Desktop/foo/target/debug/deps/libcore_foundation-19ef10f3e7242abe.rlib" "/Users/apple/Desktop/foo/target/debug/deps/liblibc-5e68c041a34d0eed.rlib" "/Users/apple/Desktop/foo/target/debug/deps/libcore_foundation_sys-6d86f6aead90fb35.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libprofiler_builtins-f8dafa01db4dca39.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-292d8bc6470467ba.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-912dbe632ba1cbae.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace-ba5714b629684fb4.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace_sys-eac4a78ff89c6e87.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-ef9b06bfe5cc2531.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-3b7d42ffe20649f3.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-4ad9bb4642dcbb0e.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-2705756291291215.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-4b3e65f59d0d2bb7.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-654bf98555d844ff.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-46c32f2ea46d194a.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-ce3fd965850830d8.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-46c797561289aff0.rlib" "/Users/apple/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-974d425bd7750373.rlib" "-framework" "CoreFoundation" "-lSystem" "-lresolv" "-lc" "-lm"
= note: Undefined symbols for architecture x86_64:
"_CFMutableAttributedStringGetTypeID", referenced from:
_$LT$core_foundation..attributed_string..CFMutableAttributedString$u20$as$u20$core_foundation..base..TCFType$GT$::type_id::h9cd95ae9d283ffee in libcore_foundation-19ef10f3e7242abe.rlib(core_foundation-19ef10f3e7242abe.core_foundation.bhl000vu-cgu.0.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)
With a -Clink-dead-code flag removed from RUSTFLAGS build successfully compiles:
$ cargo clean
$ CARGO_INCREMENTAL=0 RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Coverflow-checks=off -Zno-landing-pads" cargo run
Compiling libc v0.2.60
Compiling core-foundation-sys v0.6.2
Compiling core-foundation v0.6.4
Compiling foo v0.1.0 (/Users/apple/Desktop/foo)
Finished dev [unoptimized + debuginfo] target(s) in 3.76s
Running `target/debug/foo`
[src/main.rs:10] dict.len() = 1
The same behavior applies to cargo test command.
Meta
$ rustc --version --verbose
rustc 1.38.0-nightly (a7f28678b 2019-07-23)
binary: rustc
commit-hash: a7f28678bbf4e16893bb6a718e427504167a9494
commit-date: 2019-07-23
host: x86_64-apple-darwin
release: 1.38.0-nightly
LLVM version: 9.0
$ xcrun --show-sdk-version
10.14.1
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.13.6
BuildVersion: 17G65
Reacted by Paul Saunders, Diego, Christian, Y.Matsuda, Fangsong Long and Miroslav Kovář
Metadata
Metadata
Assignees
Labels
A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-macosOperating system: macOS
Activity
wagenet commentedon Oct 9, 2019
I'm seeing this issue except I get:
Unlike in sagebind/curl-rust#279 I only get it when trying to build for grcov with
-Zprofile -Clink-dead-code.jduan commentedon Dec 7, 2019
I'm getting the same error
and I'm on nightly as well:
wagenet commentedon Jan 24, 2020
I'm also seeing a similar issue in an Ubuntu-based Docker container:
gilescope commentedon Feb 18, 2020
Interesting. Is there an example project that this fails for? It just works for me on a 2017 mbp with latest nightly (I'm using it on a small project though..).
wagenet commentedon Feb 18, 2020
@gilescope unfortunately, I don't currently have a simplified project. I suspect it may be related to some of the way curl-rust is set up. But I can't say for certain.
gilescope commentedon Feb 18, 2020
Ok so this could be a somewhat idiosyncratic error rather than being a general error affecting all osx users of grcov...
Sent with GitHawk
wagenet commentedon Feb 18, 2020
@gilescope definitely not unique to macOS since I saw something very similar in an Ubuntu Docker container.
Auto merge of #357 - vbadanov:hotfix/fix-mutable-attributed-string-ge…
vbadanov commentedon Feb 21, 2020
This issue was fixed in servo/core-foundation-rs#357 so now we should wait for a new release of
core-foundationcrate and all dependent crates tree (security-framework,native-tls, etc)jduan commentedon Feb 21, 2020
@vbadanov that's great news. Thanks for the fix!
test: Fuzz testing RPC (#2740)
avnerbarr commentedon Nov 2, 2020
I'm getting this issue now as well
active toolchain
stable-x86_64-apple-darwin (default)
rustc 1.46.0 (04488af 2020-08-24)
dupu222 commentedon Jan 5, 2021
Environment
macOS Big Sur 11.1
stable-x86_64-apple-darwin (default)
rustc 1.49.0 (e1884a8 2020-12-29)
vbadanov commentedon May 15, 2021
There are still a lot of crates which depend on older version of core-foundation (e.g. 0.7).
Test code (see above) with core-foundation = "0.9.1" and rustc 1.54.0-nightly works as expected without errors, coverage report is generated successfully.
If you see errors, please check your crates dependencies, there should be an old core-foundation version somewhere in the tree.
seanpianka commentedon May 15, 2021
@vbadanov Does this mean that crates which depend on core-foundation should upgrade to the latest now? I imagine the situation will be similar to when Tokio went from 0.3 to 1.0, and it took a while for crates to upgrade.
vbadanov commentedon May 15, 2021
@seanpianka Yes.
madsmtm commentedon Oct 10, 2024
Triage: This was a bug in the
core-foundationcrate that was fixed years ago, so I believe this can be closed.