-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
mitigate MSVC alignment issue on x86-32 #139261
base: master
Are you sure you want to change the base?
Conversation
These commits modify compiler targets. Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
pub fn has_unreliable_alignment(&self) -> bool { | ||
// FIXME(#112480) MSVC on x86-32 is unsound and fails to properly align many types with | ||
// more-than-4-byte-alignment on the stack. | ||
if self.is_like_msvc && self.arch == "x86" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is called a lot during codegen. Should I be worried about the (short) string comparison here?
We can also add a new bool
flag to the target spec that directly controls this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, thinking about this some more it might make sense to make it a part of the target spec so that custom targets can be supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we auto-detect this for custom targets, if we make it part of the spec custom target specs will have to remember to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right but I mean the trade-off is that a potential non-msvc target that's not in-tree will have no way to set this. I don't know how likely that is but you mentioned the possibility earlier. And maybe it's fine in any case if such a targets are likely to have other custom requirements that will necessitate forking.
This will probably be hellish for the codegen test suite since all the |
mitigate MSVC alignment issue on x86-32 This implements mitigation for rust-lang#112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems. Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can. Also add an errata note to the platform support page warning users about this known problem. try-job: `i686-msvc*`
ce44d17
to
66f7993
Compare
Looking at #112480 (comment), I think the only alignment this PR needs to change as it that a type with an alignment of 8 bytes might only have an alignment of 4 bytes. MSVC will always align primitive types with an alignment < 8 bytes correctly, and the only types with an alignment > 8 bytes are SIMD types which MSVC aligns correctly anyway. |
I'd rather not rely on the "> 8" part. But yeah I think changing the logic to "clamp to 4" rather than "skip applying alignment" will probably be better, also to affect fewer tests. |
66f7993
to
ca29777
Compare
@bors try |
mitigate MSVC alignment issue on x86-32 This implements mitigation for rust-lang#112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems. Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can. Also add an errata note to the platform support page warning users about this known problem. try-job: `i686-msvc*`
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
ca29777
to
d4ce381
Compare
@saethlin I adjusted the alignment check so that it is still active on MSVC but only checks an alignment of up to 4. I hope I did this right. :D What would be the best way to test this? An |
178790f
to
df69e5d
Compare
@bors try |
mitigate MSVC alignment issue on x86-32 This implements mitigation for rust-lang#112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems. Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can. Also add an errata note to the platform support page warning users about this known problem. try-job: `i686-msvc*`
☀️ Try build successful - checks-actions |
I think this also needs to be mitigated on the |
I was wondering about that, but the existing logic only kicked in for the MSVC targets. |
I think it's just that no-one noticed as |
Fair. There's also been a proposal to demote that target (rust-lang/rfcs#3771). |
df69e5d
to
82ab25c
Compare
@bors try |
Oh wait there's conflicts, why did bors not post about that? Odd. |
🔒 Merge conflict This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again. How do I rebase?Assuming
You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial. Please avoid the "Resolve conflicts" button on GitHub. It uses Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Error message
|
82ab25c
to
d9b828f
Compare
@bors try |
mitigate MSVC alignment issue on x86-32 This implements mitigation for rust-lang#112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems. Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can. Also add an errata note to the platform support page warning users about this known problem. try-job: `i686-msvc*`
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
…32-msvc targets also mention the MSVC alignment issue in platform-support.md
d9b828f
to
e702f96
Compare
@bors try |
mitigate MSVC alignment issue on x86-32 This implements mitigation for rust-lang#112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems. Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can. Also add an errata note to the platform support page warning users about this known problem. try-job: `i686-msvc*`
☀️ Try build successful - checks-actions |
All right this should be @rustbot ready now. |
This implements mitigation for #112480 by stopping to emit
align
attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly alignu64
and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems.Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can.
Also add an errata note to the platform support page warning users about this known problem.
try-job:
i686-msvc*