-
Notifications
You must be signed in to change notification settings - Fork 348
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
Tracking issue for enabling field retagging by default #2528
Comments
I updated https://miri.saethlin.dev/ub to use field retagging a week or two ago. Generally, it looks like the ecosystem impact is minimal. |
So for now the primary blocker is rust-lang/rust#60076. |
miri-test-libstd now runs the libcore tests with liballoc fails due to rust-lang/rust#60076:
|
Interestingly a scope thread doctest also fails:
The failing push is this one. The "is this argument" looks rather strange... |
Ah, I think I know what happens... the spawned threads actually keep running after However when we create a mutable reference to |
Blocked on rust-lang/rust#101983 |
Now that rust-lang/rust#101983 is resolved -- should we enable field retagging by default? @saethlin probably has the best idea of how bad the fallout from what will be. We will certainly have a flag to opt-out of this. |
"shockingly not very bad" is my extremely qualitative current answer. Give me about 7 hours and I'll have a better answer. (I realize that if I had started this when I first read your comment I'd probably have the answer by now, ah well) |
There should probably be a release for |
Here is what I currently think is a reasonably complete list of crates which report UB with field retagging on, but do not report UB with it off (sorted by recent downloads): https://gist.github.com/saethlin/7337b32a82d352659ed758a0ecded69d There are 312 crates in that list, of the ~4400 crates which report UB. I think that number is high enough to be concerning but not a blocker, and I would like to know what it looks like with field retagging for newtypes only (which I believe is what rustc implements?). I'll admit my methodology here leaves something to be desired, I'm in the middle of migrating my whole setup to use nextest (finally). |
I think it's not just newtypes, |
Are you sure about the patch? scopeguard already does not use |
I was probably just being lazy, I have gotten too used to some maintainers like dtolnay aggressively releasing every PR. |
miri-test-libstd now enables full field retagging on all its tests, and things are passing. :) In terms of the wider ecosystem, #2613 adds an option to do field retagging only for cases where we would emit |
Yes. I'm ~vacation at the moment but I'll punch in that crate list above with the new option and we will see what comes up. But honestly I can't imagine what I would come back with that I would think is a compelling argument to not make this new option the default. |
The list above contains 311 crates. Of those, only 70 report UB with From #2613
So my initial impression is that this is not accurate, but it could be if the are one or two dependencies causing the UB reports with full field retagging. |
I'll need to take a look at those cases -- it might also be that they just happen to use the structs containing references in ways that they don't have ScalarPair ABI, but users could pick other generic type instances that do lead to a ScalarPair and thus still cause the UB. (IOW, it might remove some UB, but not actually help with soundness.) |
Stacked Borrows: make scalar field retagging the default I think it is time to finally close this soundness gap. Any objections? :) Unfortunately the latest released versions of hashbrown and scopeguard can fail under full field retagging. The fixes have landed in the git repos but have not been released yet. I don't know if scalar field retagging as enabled by this PR is sufficient to cause problems with these crates, but it seems likely that this would be the case -- e.g. if both `value` and `dropfn` are scalars, the entire scopeguard struct will be a `ScalarPair` and thus get field retagging. However, given that we actually generate LLVM `noalias` for these cases, it seems prudent to inform users of this risk. They can easily set `-Zmiri-field-retag=none` to opt-out of this change. Cc #2528
Stacked Borrows: make scalar field retagging the default I think it is time to finally close this soundness gap. Any objections? :) Unfortunately the latest released versions of hashbrown and scopeguard can fail under full field retagging. The fixes have landed in the git repos but have not been released yet. I don't know if scalar field retagging as enabled by this PR is sufficient to cause problems with these crates, but it seems likely that this would be the case -- e.g. if both `value` and `dropfn` are scalars, the entire scopeguard struct will be a `ScalarPair` and thus get field retagging. However, given that we actually generate LLVM `noalias` for these cases, it seems prudent to inform users of this risk. They can easily set `-Zmiri-field-retag=none` to opt-out of this change. Cc rust-lang/miri#2528
make full field retagging the default The 'scalar' field retagging mode is clearly a hack -- it mirrors details of the codegen backend and how various structs are represented in LLVM. This means whether code has UB or not depends on surprising aspects, such as whether a struct has 2 or 3 (non-zero-sized) fields. Now that both hashbrown and scopeguard have released fixes to be compatible with field retagging, I think it is time to enable full field retagging by default. `@saethlin` do you have an idea of how much fallout enabling full field retagging by default will cause? Do you have objections to enabling it by default? Fixes rust-lang/miri#2528
What has to happen for us to enable
-Zmiri-retag-fields
by default? LLVM already does optimizations that can only be explained on the Rust level if we do field retagging. This is the last case I am aware of of Rust code that has LLVM UB but is not considered UB by Miri. (There are other differences between Miri and the Reference, but none of those are LLVM UB -- all that extra UB is wiggle room for future optimizations, but not exploited yet.)@saethlin has been doing some experiments here I think, but I am no aware of the current status. As a start, we should probably get miri-test-libstd to pass with field retagging.
Related issues:
The text was updated successfully, but these errors were encountered: