-
Notifications
You must be signed in to change notification settings - Fork 13k
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
add -Zmin-function-alignment
#134030
add -Zmin-function-alignment
#134030
Conversation
Yes, the 2^29 alignment is a limit imposed by LLVM. |
497794d
to
488f710
Compare
Yeah what I can't quite figure out is when targets actually support that (e.g. on embedded targets, you probably don't have enough space for Also I just added support for |
Yeah, I don't think we need to worry about that. Using broken alignments on targets without virtual memory mapping is already deeply incorrect. If we figure out how we want to fix that, the fix for |
So, then, is there anything else that needs to happen here? |
☔ The latest upstream changes (presumably #134243) made this pull request unmergeable. Please resolve the merge conflicts. |
488f710
to
4c31e5e
Compare
Some changes occurred in src/tools/cargo cc @ehuss |
4c31e5e
to
544eb0e
Compare
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.
Mostly for me to have more bandwidth for doing reviews, apparently!
I suppose this should be added to the "unstable book"? src/doc/unstable-book
544eb0e
to
7b9d306
Compare
@rustbot ready |
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 documentation seems to be incorrect.
I'd also just like to see something higher than 16 and 32 for a test (or test revision). Let's get sillier. Have one of the values be outside the range of a u8, say.
src/doc/unstable-book/src/compiler-flags/min-function-alignment.md
Outdated
Show resolved
Hide resolved
7b9d306
to
47573bf
Compare
@rustbot ready
|
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.
Much better!
@bors r+ |
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#134030 (add `-Zmin-function-alignment`) - rust-lang#134776 (Avoid ICE: Account for `for<'a>` types when checking for non-structural type in constant as pattern) - rust-lang#135205 (Rename `BitSet` to `DenseBitSet`) - rust-lang#135314 (Eagerly collect mono items for non-generic closures) r? `@ghost` `@rustbot` modify labels: rollup
To be clear, there's no problem linking two crates that use different values for this? The compiler will not assume that all function pointers it sees are sufficiently aligned; it will merely decide to align the functions emitted in this particular session in the described way? |
Yes that's right. You can think of this flag as annotating all functions for which code is generated with #[repr(align<value>))] No assumptions are made about code from other crates, |
Rollup merge of rust-lang#134030 - folkertdev:min-fn-align, r=workingjubilee add `-Zmin-function-alignment` tracking issue: rust-lang#82232 This PR adds the `-Zmin-function-alignment=<align>` flag, that specifies a minimum alignment for all* functions. ### Motivation This feature is requested by RfL [here](rust-lang#128830): > i.e. the equivalents of `-fmin-function-alignment` ([GCC](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fmin-function-alignment_003dn), Clang does not support it) / `-falign-functions` ([GCC](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-falign-functions), [Clang](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang1-falign-functions)). > > For the Linux kernel, the behavior wanted is that of GCC's `-fmin-function-alignment` and Clang's `-falign-functions`, i.e. align all functions, including cold functions. > > There is [`feature(fn_align)`](rust-lang#82232), but we need to do it globally. ### Behavior The `fn_align` feature does not have an RFC. It was decided at the time that it would not be necessary, but maybe we feel differently about that now? In any case, here are the semantics of this flag: - `-Zmin-function-alignment=<align>` specifies the minimum alignment of all* functions - the `#[repr(align(<align>))]` attribute can be used to override the function alignment on a per-function basis: when `-Zmin-function-alignment` is specified, the attribute's value is only used when it is higher than the value passed to `-Zmin-function-alignment`. - the target may decide to use a higher value (e.g. on x86_64 the minimum that LLVM generates is 16) - The highest supported alignment in rust is `2^29`: I checked a bunch of targets, and they all emit the `.p2align 29` directive for targets that align functions at all (some GPU stuff does not have function alignment). *: Only with `build-std` would the minimum alignment also be applied to `std` functions. --- cc `@ojeda` r? `@workingjubilee` you were active on the tracking issue
tracking issue: #82232
This PR adds the
-Zmin-function-alignment=<align>
flag, that specifies a minimum alignment for all* functions.Motivation
This feature is requested by RfL here:
Behavior
The
fn_align
feature does not have an RFC. It was decided at the time that it would not be necessary, but maybe we feel differently about that now? In any case, here are the semantics of this flag:-Zmin-function-alignment=<align>
specifies the minimum alignment of all* functions#[repr(align(<align>))]
attribute can be used to override the function alignment on a per-function basis: when-Zmin-function-alignment
is specified, the attribute's value is only used when it is higher than the value passed to-Zmin-function-alignment
.2^29
: I checked a bunch of targets, and they all emit the.p2align 29
directive for targets that align functions at all (some GPU stuff does not have function alignment).*: Only with
build-std
would the minimum alignment also be applied tostd
functions.cc @ojeda
r? @workingjubilee you were active on the tracking issue