Skip to content

Commit e25a70b

Browse files
authored
Unrolled build for rust-lang#140661
Rollup merge of rust-lang#140661 - Darksonn:fixedx18-tm, r=wesleywiser Make `-Zfixed-x18` into a target modifier As part of rust-lang#136966, the `-Zfixed-x18` flag should be turned into a target modifier. This is a blocker to stabilization of the flag. The flag was originally added in rust-lang#124655 and the MCP for its addition is [MCP#748](rust-lang/compiler-team#748). On some aarch64 targets, the x18 register is used as a temporary caller-saved register by default. When the `-Zfixed-x18` flag is passed, this is turned off so that the compiler doesn't use the x18 register. This allows end-users to use the x18 register for other purposes. For example, by accessing it with inline asm you can use the register as a very efficient thread-local variable. Another common use-case is to store the stack pointer needed by the shadow-call-stack sanitizer. There are also some aarch64 targets where not using x18 is the default – in those cases the flag is a no-op. Note that this flag does not *on its own* cause an ABI mismatch. What actually causes an ABI mismatch is when you have different compilation units that *disagree* on what it should be used for. But having a CU that uses it and another CU that doesn't normally isn't enough to trigger an ABI problem. However, we still consider the flag to be a target modifier in all cases, since it is assumed that you are passing the flag because you intend to assign some other meaning to the register. Rejecting all flag mismatches even if not all are unsound is consistent with [RFC#3716](https://rust-lang.github.io/rfcs/3716-target-modifiers.html). See the headings "not all mismatches are unsound" and "cases that are not caught" for additional discussion of this. On aarch64 targets where `-Zfixed-x18` is not a no-op, it is an error to pass `-Zsanitizer=shadow-call-stack` without also passing `-Zfixed-x18`.
2 parents 2e6882a + 4b58c50 commit e25a70b

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ options! {
22102210
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
22112211
"reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
22122212
(default: no)"),
2213-
fixed_x18: bool = (false, parse_bool, [TRACKED],
2213+
fixed_x18: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
22142214
"make the x18 register reserved on AArch64 (default: no)"),
22152215
flatten_format_args: bool = (true, parse_bool, [TRACKED],
22162216
"flatten nested format_args!() and literals into a simplified format_args!() call \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ no-prefer-dynamic
2+
//@ compile-flags: --target aarch64-unknown-none -Zfixed-x18
3+
//@ needs-llvm-components: aarch64
4+
5+
#![feature(no_core)]
6+
#![crate_type = "rlib"]
7+
#![no_core]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: mixing `-Zfixed-x18` will cause an ABI mismatch in crate `incompatible_fixedx18`
2+
--> $DIR/incompatible_fixedx18.rs:12:1
3+
|
4+
LL | #![feature(no_core)]
5+
| ^
6+
|
7+
= help: the `-Zfixed-x18` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
8+
= note: unset `-Zfixed-x18` in this crate is incompatible with `-Zfixed-x18=` in dependency `fixed_x18`
9+
= help: set `-Zfixed-x18=` in this crate or unset `-Zfixed-x18` in `fixed_x18`
10+
= help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=fixed-x18` to silence this error
11+
12+
error: aborting due to 1 previous error
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ aux-build:fixed_x18.rs
2+
//@ compile-flags: --target aarch64-unknown-none
3+
//@ needs-llvm-components: aarch64
4+
5+
//@ revisions:allow_match allow_mismatch error_generated
6+
//@[allow_match] compile-flags: -Zfixed-x18
7+
//@[allow_mismatch] compile-flags: -Cunsafe-allow-abi-mismatch=fixed-x18
8+
//@[error_generated] compile-flags:
9+
//@[allow_mismatch] check-pass
10+
//@[allow_match] check-pass
11+
12+
#![feature(no_core)]
13+
//[error_generated]~^ ERROR mixing `-Zfixed-x18` will cause an ABI mismatch in crate `incompatible_fixedx18`
14+
#![crate_type = "rlib"]
15+
#![no_core]
16+
17+
extern crate fixed_x18;

0 commit comments

Comments
 (0)