Skip to content

rustc -Clink-dead-code causes MSVC linker to produce invalid binaries with 'found invalid metadata files for crate' error #92141

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

Closed
fadeevab opened this issue Dec 20, 2021 · 1 comment

Comments

@fadeevab
Copy link

Error: error[E0786]: found invalid metadata files for crate ....
MSVC: Visual Studio 2019, Visual Studio 2022.
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"

The flag -Clink-dead-code is used with -Zprofile to produce a code coverage using nightly-msvc toolchain.

I get the following error on random crates during cargo build:

error[E0786]: found invalid metadata files for crate `serde_derive`
   --> ~\.cargo\registry\src\github.com-1ecc6299db9ec823\serde-1.0.118\src\lib.rs:286:1
    |
286 | extern crate serde_derive;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: failed to decompress metadata: \\?\<my local dir>\target\debug\deps\serde_derive-961e5eaa49da36c1.dll   

error[E0432]: unresolved import `ser`
  --> ~\.cargo\registry\src\github.com-1ecc6299db9ec823\serde-1.0.118\src\de\value.rs:29:5
   |
29 | use ser;
   |     ^^^

Some errors have detailed explanations: E0432, E0786.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `serde` due to 2 previous errors

The error is not reproduced with the GNU toolchain.

@ehuss
Copy link
Contributor

ehuss commented Jan 9, 2022

Thanks for the report! This is a duplicate of #90056, so closing in favor of that.

@ehuss ehuss closed this as completed Jan 9, 2022
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