-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Incompatibility using both -Zinstrument-coverage
and -Z build-std
#79401
Comments
By the way, there is a current PR OISF/suricata#5582 with a fix : not using |
@catenacyber - Thanks for the bug report! I did some experimenting (briefly), and I can repro this issue, for instance, with: RUSTFLAGS="-Zinstrument-coverage" cargo build --release -Z build-std --target x86_64-unknown-linux-gnu I don't fully understand how One copy loads the standard (This is a minimually-educated guess, from the error messages.) Anyhow, I don't think So I tried: RUSTFLAGS="-Zprofile" cargo build --release -Z build-std --target x86_64-unknown-linux-gnu Sure enough, I get the same errors. Since Note, both |
Indeed, I do not know which experimental feature should fix this. |
@alexcrichton - Is |
I believe the |
@catenacyber - Would you mind copy/pasting your issue into that list (perhaps just linking back to here for context if helpful)? Thanks! |
@rustbot label +A-code-coverage |
…age, r=jieyouxu inject_panic_runtime(): Avoid double negation for 'any non rlib' <details> <summary>This PR originally did more things .Click to expand to see.</summary> By not trying to inject a profiler runtime when only building an rlib. This logic already exists for the panic runtime. This makes RUSTFLAGS="-Cinstrument-coverage" cargo build -Zbuild-std=std,profiler_builtins work. Note that you probably also need `RUST_COMPILER_RT_FOR_PROFILER=$src/llvm-project/compiler-rt` in your environment. cc rust-lang#79401 # Demonstration Before this fix you get these errors: ```console $ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +nightly build --release -Zbuild-std=std,profiler_builtins error: `profiler_builtins` crate (required by compiler options) is not compatible with crate attribute `#![no_core]` error[E0152]: found duplicate lang item `manually_drop` = note: first definition in `core` loaded from /home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-d453bab70303062c.rlib = note: second definition in the local crate (`core`) ``` With the fix the build succeeds: ```console $ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +stage1 build --release -Zbuild-std=std,profiler_builtins Finished `release` profile [optimized] target(s) in 45.57s ``` And we can check code coverage. My example program looks like this: ```rs fn main() { if std::env::args_os().nth(1) == Some("write-file".into()) { std::fs::write("hello.txt", "Hello, world!").unwrap(); } else { println!("Hello, world!"); } } ``` when the program prints to stdout: ``` $ LLVM_PROFILE_FILE=stdout.profraw ./target/release/hello-world Hello, world! ``` we can see that `fs::write()` is not being used (note the `0`'s): ```console $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse stdout.profraw -o stdout.profdata $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/release/hello-world --sources /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/fs.rs --instr-profile stdout.profdata --color | grep -A 3 'pub fn write(&mut self, write: b ool) -> &mut Self {' 1357| 0| pub fn write(&mut self, write: bool) -> &mut Self { 1358| 0| self.0.write(write); 1359| 0| self 1360| 0| } ``` but when we print to a file: ```console $ LLVM_PROFILE_FILE=file.profraw ./target/release/hello-world write-file ``` the code coverage shows `fs::write()` as being used (note the `1`'s): ```console $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse file.profraw -o file.profdata $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/release/hello-world --sources /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/fs.rs --instr-profile file.profdata --color | grep -A 3 'pub fn write(&mut self, write: bool) -> &mut Self {' 1357| 1| pub fn write(&mut self, write: bool) -> &mut Self { 1358| 1| self.0.write(write); 1359| 1| self 1360| 1| } ``` </summary>
Rollup merge of rust-lang#133300 - Enselic:build-std-instrument-coverage, r=jieyouxu inject_panic_runtime(): Avoid double negation for 'any non rlib' <details> <summary>This PR originally did more things .Click to expand to see.</summary> By not trying to inject a profiler runtime when only building an rlib. This logic already exists for the panic runtime. This makes RUSTFLAGS="-Cinstrument-coverage" cargo build -Zbuild-std=std,profiler_builtins work. Note that you probably also need `RUST_COMPILER_RT_FOR_PROFILER=$src/llvm-project/compiler-rt` in your environment. cc rust-lang#79401 # Demonstration Before this fix you get these errors: ```console $ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +nightly build --release -Zbuild-std=std,profiler_builtins error: `profiler_builtins` crate (required by compiler options) is not compatible with crate attribute `#![no_core]` error[E0152]: found duplicate lang item `manually_drop` = note: first definition in `core` loaded from /home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-d453bab70303062c.rlib = note: second definition in the local crate (`core`) ``` With the fix the build succeeds: ```console $ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +stage1 build --release -Zbuild-std=std,profiler_builtins Finished `release` profile [optimized] target(s) in 45.57s ``` And we can check code coverage. My example program looks like this: ```rs fn main() { if std::env::args_os().nth(1) == Some("write-file".into()) { std::fs::write("hello.txt", "Hello, world!").unwrap(); } else { println!("Hello, world!"); } } ``` when the program prints to stdout: ``` $ LLVM_PROFILE_FILE=stdout.profraw ./target/release/hello-world Hello, world! ``` we can see that `fs::write()` is not being used (note the `0`'s): ```console $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse stdout.profraw -o stdout.profdata $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/release/hello-world --sources /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/fs.rs --instr-profile stdout.profdata --color | grep -A 3 'pub fn write(&mut self, write: b ool) -> &mut Self {' 1357| 0| pub fn write(&mut self, write: bool) -> &mut Self { 1358| 0| self.0.write(write); 1359| 0| self 1360| 0| } ``` but when we print to a file: ```console $ LLVM_PROFILE_FILE=file.profraw ./target/release/hello-world write-file ``` the code coverage shows `fs::write()` as being used (note the `1`'s): ```console $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse file.profraw -o file.profdata $ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/release/hello-world --sources /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/fs.rs --instr-profile file.profdata --color | grep -A 3 'pub fn write(&mut self, write: bool) -> &mut Self {' 1357| 1| pub fn write(&mut self, write: bool) -> &mut Self { 1358| 1| self.0.write(write); 1359| 1| self 1360| 1| } ``` </summary>
I tried this code:
This ends up running
cargo build --release -Z build-std
I expected to see this happen:
Compilation succeeds
Instead, this happened:
Compilation failed with
and many more errors about other duplicate items
Meta
This is part of #34701 cc @richkadel
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: