-
Notifications
You must be signed in to change notification settings - Fork 13.5k
centralize -Zmin-function-alignment
logic
#142854
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
centralize -Zmin-function-alignment
logic
#142854
Conversation
Some changes occurred to the CTFE machinery Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs |
r? codegen |
This looks good to me. r? workingjubilee |
…-alignment, r=workingjubilee centralize `-Zmin-function-alignment` logic tracking issue: rust-lang#82232 discussed in: rust-lang#142824 (comment) Apply the `-Zmin-function-alignment` value to the alignment field of the function attributes when those are created, so that individual backends don't need to consider it. The one exception right now is cranelift, because it can't yet set the alignment for individual functions, but it can (and does) set the global minimum function alignment. cc `@RalfJung` I think this is an improvement regardless, is there anything else that should be done for miri?
Rollup of 6 pull requests Successful merges: - #140136 (Add an aarch64-msvc build running on ARM64 Windows) - #141597 (Document subdirectories of UI tests with README files) - #142823 (Port `#[no_mangle]` to new attribute parsing infrastructure) - #142828 (1.88.0 release notes) - #142854 (centralize `-Zmin-function-alignment` logic) - #142875 (Check rustdoc-json-types FORMAT_VERSION is correctly updated) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 5 pull requests Successful merges: - #141597 (Document subdirectories of UI tests with README files) - #142823 (Port `#[no_mangle]` to new attribute parsing infrastructure) - #142828 (1.88.0 release notes) - #142854 (centralize `-Zmin-function-alignment` logic) - #142875 (Check rustdoc-json-types FORMAT_VERSION is correctly updated) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #142854 - folkertdev:centralize-min-function-alignment, r=workingjubilee centralize `-Zmin-function-alignment` logic tracking issue: #82232 discussed in: #142824 (comment) Apply the `-Zmin-function-alignment` value to the alignment field of the function attributes when those are created, so that individual backends don't need to consider it. The one exception right now is cranelift, because it can't yet set the alignment for individual functions, but it can (and does) set the global minimum function alignment. cc ``@RalfJung`` I think this is an improvement regardless, is there anything else that should be done for miri?
…no-attributes, r=workingjubilee fix `-Zmin-function-alignment` on functions without attributes tracking issue: rust-lang#82232 related: rust-lang#142854 The minimum function alignment was skipped on functions without attributes (because the logic was in a loop that only runs if there is at least one attribute). The underlying reason we didn't catch this before is that in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes. r? `@workingjubilee`
Rollup merge of #142923 - folkertdev:min-function-alignment-no-attributes, r=workingjubilee fix `-Zmin-function-alignment` on functions without attributes tracking issue: #82232 related: #142854 The minimum function alignment was skipped on functions without attributes (because the logic was in a loop that only runs if there is at least one attribute). The underlying reason we didn't catch this before is that in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes. r? `@workingjubilee`
@@ -126,6 +126,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { | |||
} | |||
} | |||
|
|||
// Apply the minimum function alignment here, so that individual backends don't have to. |
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.
It's actually more important than that, if you consider that -C
flags can differ between translation units.
This ensures functions defined in a crate compiled with -Cmin-function-alignment
get that alignment independent of the crate they are codegen'd in.
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.
If a function from crate A is generated in another crate B compiled with -Zmin-function-alignment=B
, I would expect the alignment to be at least B.
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.
We don't say anything about which function is generated where, so I don't see how such a guarantee could be practically useful?
From a const-eval perspective, doing this would be just unsound as it means the result of "which alignment does this function have" could be different in different parts of the program.
// Function alignment can be set globally with the `-Zmin-function-alignment=<n>` flag; | ||
// the alignment from a `#[repr(align(<n>))]` is used if it specifies a higher alignment. | ||
let fn_align = self.tcx.codegen_fn_attrs(instance.def_id()).alignment; | ||
let global_align = self.tcx.sess.opts.unstable_opts.min_function_alignment; |
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.
Is there any way we can have a lint against accessing tcx.sess.opts
in the interpreter? Or is there some way the query machinery could help us ensure this? This is a soundness bug waiting to happen. :/ And it can't be just the interpreter, right? Other queries also must be cross-crate-stable in the same way?
codegen_fn_attrs: make comment more precise Follow-up to rust-lang#142854. r? `@oli-obk` or `@workingjubilee`
Rollup of 5 pull requests Successful merges: - rust-lang/rust#141597 (Document subdirectories of UI tests with README files) - rust-lang/rust#142823 (Port `#[no_mangle]` to new attribute parsing infrastructure) - rust-lang/rust#142828 (1.88.0 release notes) - rust-lang/rust#142854 (centralize `-Zmin-function-alignment` logic) - rust-lang/rust#142875 (Check rustdoc-json-types FORMAT_VERSION is correctly updated) r? `@ghost` `@rustbot` modify labels: rollup
codegen_fn_attrs: make comment more precise Follow-up to rust-lang#142854. r? ``@oli-obk`` or ``@workingjubilee``
codegen_fn_attrs: make comment more precise Follow-up to rust-lang#142854. r? ```@oli-obk``` or ```@workingjubilee```
codegen_fn_attrs: make comment more precise Follow-up to rust-lang#142854. r? ````@oli-obk```` or ````@workingjubilee````
tracking issue: #82232
discussed in: #142824 (comment)
Apply the
-Zmin-function-alignment
value to the alignment field of the function attributes when those are created, so that individual backends don't need to consider it.The one exception right now is cranelift, because it can't yet set the alignment for individual functions, but it can (and does) set the global minimum function alignment.
cc @RalfJung I think this is an improvement regardless, is there anything else that should be done for miri?