Skip to content

Commit 7de7563

Browse files
committed
make -Zmin-function-alignment a target modifier
1 parent f46ce66 commit 7de7563

File tree

8 files changed

+72
-7
lines changed

8 files changed

+72
-7
lines changed

compiler/rustc_session/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ options! {
23402340
"gather metadata statistics (default: no)"),
23412341
metrics_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
23422342
"the directory metrics emitted by rustc are dumped into (implicitly enables default set of metrics)"),
2343-
min_function_alignment: Option<Align> = (None, parse_align, [TRACKED],
2343+
min_function_alignment: Option<Align> = (None, parse_align, [TRACKED TARGET_MODIFIER],
23442344
"align all functions to at least this many bytes. Must be a power of 2"),
23452345
mir_emit_retag: bool = (false, parse_bool, [TRACKED],
23462346
"emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \

src/tools/miri/tests/pass/fn_align.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@compile-flags: -Zmin-function-alignment=8
1+
//@compile-flags: -Zmin-function-alignment=8 -Cunsafe-allow-abi-mismatch=min-function-alignment
22
#![feature(fn_align)]
33

44
// When a function uses `align(N)`, the function address should be a multiple of `N`.

tests/codegen/min-function-alignment.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
//@ add-core-stubs
12
//@ revisions: align16 align1024
23
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 -Clink-dead-code
34
//@ [align16] compile-flags: -Zmin-function-alignment=16
45
//@ [align1024] compile-flags: -Zmin-function-alignment=1024
56

6-
#![crate_type = "lib"]
7+
#![feature(no_core)]
78
#![feature(fn_align)]
9+
#![crate_type = "lib"]
10+
#![no_std]
11+
#![no_core]
12+
13+
extern crate minicore;
14+
use minicore::*;
815

916
// Functions without explicit alignment use the global minimum.
1017
//

tests/codegen/naked-fn/min-function-alignment.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1+
//@ add-core-stubs
12
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0 -Zmin-function-alignment=16
23
//@ needs-asm-support
34
//@ ignore-arm no "ret" mnemonic
45

6+
#![feature(no_core)]
57
#![feature(fn_align)]
68
#![crate_type = "lib"]
9+
#![no_std]
10+
#![no_core]
11+
12+
extern crate minicore;
13+
use minicore::*;
714

815
// functions without explicit alignment use the global minimum
916
//
1017
// CHECK: .balign 16
1118
#[no_mangle]
1219
#[unsafe(naked)]
1320
pub extern "C" fn naked_no_explicit_align() {
14-
core::arch::naked_asm!("ret")
21+
naked_asm!("ret")
1522
}
1623

1724
// CHECK: .balign 16
1825
#[no_mangle]
1926
#[align(8)]
2027
#[unsafe(naked)]
2128
pub extern "C" fn naked_lower_align() {
22-
core::arch::naked_asm!("ret")
29+
naked_asm!("ret")
2330
}
2431

2532
// CHECK: .balign 32
2633
#[no_mangle]
2734
#[align(32)]
2835
#[unsafe(naked)]
2936
pub extern "C" fn naked_higher_align() {
30-
core::arch::naked_asm!("ret")
37+
naked_asm!("ret")
3138
}
3239

3340
// cold functions follow the same rules as other functions
@@ -40,5 +47,5 @@ pub extern "C" fn naked_higher_align() {
4047
#[cold]
4148
#[unsafe(naked)]
4249
pub extern "C" fn no_explicit_align_cold() {
43-
core::arch::naked_asm!("ret")
50+
naked_asm!("ret")
4451
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ no-prefer-dynamic
2+
//@ compile-flags: --target aarch64-unknown-none -Zmin-function-alignment=32
3+
//@ needs-llvm-components: aarch64
4+
5+
#![feature(no_core)]
6+
#![crate_type = "rlib"]
7+
#![no_core]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: mixing `-Zmin-function-alignment` will cause an ABI mismatch in crate `incompatible_min_function_alignment`
2+
--> $DIR/incompatible_min_function_alignment.rs:13:1
3+
|
4+
LL | #![feature(no_core)]
5+
| ^
6+
|
7+
= help: the `-Zmin-function-alignment` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
8+
= note: `-Zmin-function-alignment=4` in this crate is incompatible with `-Zmin-function-alignment=32` in dependency `min_function_alignment`
9+
= help: set `-Zmin-function-alignment=32` in this crate or `-Zmin-function-alignment=4` in `min_function_alignment`
10+
= help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=min-function-alignment` to silence this error
11+
12+
error: aborting due to 1 previous error
13+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: mixing `-Zmin-function-alignment` will cause an ABI mismatch in crate `incompatible_min_function_alignment`
2+
--> $DIR/incompatible_min_function_alignment.rs:13:1
3+
|
4+
LL | #![feature(no_core)]
5+
| ^
6+
|
7+
= help: the `-Zmin-function-alignment` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
8+
= note: unset `-Zmin-function-alignment` in this crate is incompatible with `-Zmin-function-alignment=32` in dependency `min_function_alignment`
9+
= help: set `-Zmin-function-alignment=32` in this crate or unset `-Zmin-function-alignment` in `min_function_alignment`
10+
= help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=min-function-alignment` to silence this error
11+
12+
error: aborting due to 1 previous error
13+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ aux-build:min_function_alignment.rs
2+
//@ compile-flags: --target aarch64-unknown-none
3+
//@ needs-llvm-components: aarch64
4+
5+
//@ revisions:allow_match allow_mismatch error_mismatch error_omitted
6+
//@[allow_match] compile-flags: -Zmin-function-alignment=32
7+
//@[allow_mismatch] compile-flags: -Cunsafe-allow-abi-mismatch=min-function-alignment
8+
//@[error_mismatch] compile-flags: -Zmin-function-alignment=4
9+
//@[error_omitted] compile-flags:
10+
//@[allow_mismatch] check-pass
11+
//@[allow_match] check-pass
12+
13+
#![feature(no_core)]
14+
//[error_mismatch,error_omitted]~^ ERROR mixing `-Zmin-function-alignment` will cause an ABI mismatch in crate `incompatible_min_function_alignment`
15+
#![crate_type = "rlib"]
16+
#![no_core]
17+
18+
extern crate min_function_alignment;

0 commit comments

Comments
 (0)