-
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
Regression in #[used]
attribute on Windows msvc
#127052
Comments
To elaborate, the difference is in symbols.o. Here's a dump of symbols.o before the change:
And here's after:
Spot the difference. Spoiler: |
So is that right or wrong? The static is "used" so marking it exported to ensure it does not get optimized away seems to make sense?
I don't understand why this is a problem only on Windows.
|
Well that's not a problem per se but if we want to do that then we have to do it properly. The only issue is that |
I don't understand any part of that.^^
Should my PR get reverted or is there a better way to fix this regression? If there is a better way, I am afraid I lack the knowledge to implement and test it. I don't understand symbol handling on Linux, let alone on Windows.
|
I don't know enough about the Rust compiler to say. My complete guess would be that |
Hm, who would understand our Windows linking story? @bjorn3 ? |
After CGU partitioning, we try to internalize symbols when possible. What is surprising to me is that this process only looks at export level, ignoring used attribute (in the contrast to say the internalization during fat LTO). Consequently we have a situation where synthetic object file references a symbol that is no longer exported (on Linux that does not result in a linking error, even though reference is unresolved). Anyway, if the consequence of #126938 would be to export those symbols for no reason, that seems rather counter productive to me. |
Ah, the behaviour was working to spec before: https://doc.rust-lang.org/reference/abi.html?highlight=Used#the-used-attribute
So I think I'd agree that #126938 is the wrong approach and should be reverted because this currently ends up conflating different things. Maybe changes elsewhere would fix this but I don't want to speculate. |
@ChrisDenton the separate issue you pointed out earlier in #127052 (comment) is presumably still relevant for |
Could this explain recent CI flakiness? The failure at #127066 (comment) and a couple other failed merges (linked on that thread, also the retries) have been msvc linker errors. |
That's unfortunate. :/ Our reachable symbol code is such a spaghetti mess... I guess I'll just have to copy-paste more things into Miri then. 🤷 I am traveling right now, I'd appreciate if someone else could do the revert. |
The following patch should fix the incorrect internalization I mentioned earlier: diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
index 6abe4fa1c38..71b8cb9c559 100644
--- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
+++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
@@ -159,7 +159,7 @@ fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: LocalDefId)
let export_threshold = threshold(tcx);
if let Some(&info) = tcx.reachable_non_generics(LOCAL_CRATE).get(&def_id.to_def_id()) {
- info.level.is_below_threshold(export_threshold)
+ info.level.is_below_threshold(export_threshold) || info.used
} else {
false
} As for the question whether those symbols should be exported in the first place, it might be necessary for COFF and I don't have access to windows environment at the moment to verify that, so I don't plan to work on this myself. |
Revert "miri: make sure we can find link_section statics even for the local crate" This PR reverts rust-lang#126938 as [requested by its author](rust-lang#127052 (comment)), to fix the rust-lang#127052 regression. r? ghost fixes rust-lang#127052 We should probably improve the [`used` rmake test(s)](https://github.com/rust-lang/rust/blob/57931e50409f9365791f7923a68f9ae1ec301c4c/tests/run-make/used/rmake.rs#L7) in the future, though this should do for now. (Opening as draft to run tests on a windows env) try-job: x86_64-msvc
Ooh this is also the stuff that also broke several ci-runs already ... |
Revert "miri: make sure we can find link_section statics even for the local crate" This PR reverts #126938 as [requested by its author](rust-lang/rust#127052 (comment)), to fix the #127052 regression. Fixes #127052 We should probably improve the [`used` rmake test(s)](https://github.com/rust-lang/rust/blob/57931e50409f9365791f7923a68f9ae1ec301c4c/tests/run-make/used/rmake.rs#L7) in the future, but this should do for now.
Looks like this did not fully fix the ci failures 🫠 |
Makes sense: some CI failures look non-deterministic, while we'd expect this error not to be. |
Alternative approach for Miri: rust-lang/miri#3723 |
Code
I tried this code:
I expected to see this happen: Compiles successfully.
Instead, this happened: Fails with this error:
Version it worked on
nightly-2024-06-26 and earlier.
Version with regression
nightly-2024-06-27 and later, starting with #126938.
See #126938 (comment) for a discussion of the issue.
rustc --version --verbose
:cc @RalfJung @ChrisDenton
The text was updated successfully, but these errors were encountered: