You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -132,9 +132,13 @@ fn prefix_and_suffix<'tcx>(
132
132
133
133
let attrs = tcx.codegen_fn_attrs(instance.def_id());
134
134
let link_section = attrs.link_section.map(|symbol| symbol.as_str().to_string());
135
-
let align = attrs.alignment.map(|a| a.bytes()).unwrap_or(4);
136
135
137
-
// See https://sourceware.org/binutils/docs/as/ARM-Directives.html for info on these directives.
136
+
// function alignment can be set globally with the `-Zmin-function-alignment=<n>` flag;
137
+
// the alignment from a `#[repr(align(<n>))]` is used if it specifies a higher alignment.
138
+
// if no alignment is specified, an alignment of 4 bytes is used.
139
+
let min_function_alignment = tcx.sess.opts.unstable_opts.min_function_alignment;
140
+
let align = Ord::max(min_function_alignment, attrs.alignment).map(|a| a.bytes()).unwrap_or(4);
141
+
138
142
// In particular, `.arm` can also be written `.code 32` and `.thumb` as `.code 16`.
The tracking issue for this feature is: https://github.com/rust-lang/rust/issues/82232.
4
+
5
+
------------------------
6
+
7
+
The `-Zmin-function-alignment=<align>` flag specifies the minimum alignment of functions for which code is generated.
8
+
The `align` value must be a power of 2, other values are rejected.
9
+
10
+
Note that `-Zbuild-std` (or similar) is required to apply this minimum alignment to standard library functions.
11
+
By default, these functions come precompiled and their alignments won't respect the `min-function-alignment` flag.
12
+
13
+
This flag is equivalent to:
14
+
15
+
-`-fmin-function-alignment` for [GCC](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fmin-function-alignment_003dn)
16
+
-`-falign-functions` for [Clang](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang1-falign-functions)
17
+
18
+
The specified alignment is a minimum. A higher alignment can be specified for specific functions by using the [`repr(align(...))`](https://github.com/rust-lang/rust/issues/82232) feature and annotating the function with a `#[repr(align(<align>))]` attribute. The attribute's value is ignored when it is lower than the value passed to `min-function-alignment`.
19
+
20
+
There are two additional edge cases for this flag:
21
+
22
+
- targets have a minimum alignment for functions (e.g. on x86_64 the lowest that LLVM generates is 16 bytes).
23
+
A `min-function-alignment` value lower than the target's minimum has no effect.
24
+
- the maximum alignment supported by rust (and LLVM) is `2^29`. Trying to set a higher value results in an error.
0 commit comments