-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustc_const_eval
: respect target.min_global_align
#142198
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
base: master
Are you sure you want to change the base?
Conversation
The Miri subtree was changed cc @rust-lang/miri These commits modify compiler targets. Some changes occurred to the CTFE machinery Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
c87f1ba
to
21aae4d
Compare
@@ -0,0 +1,50 @@ | |||
// Test that miri respects the `target.min_global_align` value for the target. | |||
// E.g. on s390x, statics have, in practice, a minimum alignment of 2. |
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.
"in practice" seems like unnecessarily wobbly language here. Can we say something more concrete, or if the answer is complicated point to where the full answer is?
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.
the actual answer is "LLVM and some other compilers generate incorrect code if globals have an alignment less than 2, as they generate accesses to globals using LALR, which requires alignment to even addresses in order to work".
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.
Yeah, the situation here is a confusing
- technically, miri does not need to enforce this alignment of 2, because it does not actually emit the
larl
instruction that would behave incorrectly - but in practice, both
gcc
,clang
andrustc
do respect this alignment - intuitively
miri
should respecttarget.min_global_align
- the only way to observe its effect right now is to test the alignment of statics on s390x
Anyway I've updated the comment with why this test was written.
21aae4d
to
7b8bcdd
Compare
7b8bcdd
to
553ae22
Compare
This PR builds on #142179 (which will be merged soon), so ignore the first commit here.
Issue #44411 describes a correctness problem on s390x, where a static is not sufficiently aligned: the
larl
instruction that LLVM generates assumes an even address, but e.g. a static containing abool
may have an odd address.Because miri is an interpreter, it is not actually behaving incorrectly in this case. Currently, the only LLVM target that also specifies a
min_global_align
islarai
, which rust does not support. Thenvptx
targets inherit the alignment from their host, butnvptx
+s390x
seems unlikely. Nevertheless, miri should probably respect the target'smin_global_align
.The solution here is really hard to test: it's kind of a numbers game. The test I added at least fails on current miri (and should now succeed on CI). We'll likely soon have
#[align]
on statics (rust-lang/rfcs#3806 is in FCP), so then we can have some more extensive static alignment checks. I'm assuming the tests are executed for a variety of targets, includings390x
?See also #miri > alignment of globals on s390x
r? @RalfJung