rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.76k stars 2.42k forks source link

Cargo incorrectly uses `-C linker-plugin-lto` to request bitcode only crates #14575

Open Zoxc opened 1 month ago

Zoxc commented 1 month ago

Problem

Cargo incorrectly uses -C linker-plugin-lto to request bitcode only crates. That's not what -C linker-plugin-lto is intended for. On Windows it has the additional effect of changing how crates a linked together, making it incorrect to mix crates not built with -C linker-plugin-lto with ones which are.

This is a contributing factor to https://github.com/rust-lang/rust/issues/127979.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

No response

weihanglo commented 1 month ago

Thanks for the report. As I understand it, -C linker-plugin-lto is not compatible with dynamic linking on Windows. Is that what you are describing?

Could you also give a minimal repro of it with the error message, and also the expected behavior?

Zoxc commented 1 month ago

As I understand it, -C linker-plugin-lto is not compatible with dynamic linking on Windows. Is that what you are describing?

Yeah.

Could you also give a minimal repro of it with the error message, and also the expected behavior?

The expected behavior would be for Cargo to never pass -C linker-plugin-lto to rustc, as Cargo doesn't support linker plugin LTO. Currently rustc will just miscompile as it doesn't have proper safeguards in place, so there's no error message.

weihanglo commented 1 month ago

Cargo incorrectly uses -C linker-plugin-lto to request bitcode only crates.

Would you mind sharing an exact setup of the Cargo package, including Cargo.toml, Cargo configuration, and the cargo invocations, so that we can reproduce it correctly?

Zoxc commented 1 month ago

You can use https://github.com/rust-lang/rust/issues/127979 for that.