Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18#133463
Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18#133463bors merged 1 commit intorust-lang:masterfrom
Conversation
|
These commits modify compiler targets. Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
a43aa35 to
0c8db6e
Compare
This comment has been minimized.
This comment has been minimized.
0c8db6e to
85b9750
Compare
|
cc @Darksonn (who added -Zfixed-x18 in #124655) |
This comment has been minimized.
This comment has been minimized.
85b9750 to
f4b01b5
Compare
This comment has been minimized.
This comment has been minimized.
f4b01b5 to
687dc19
Compare
| pub(crate) fn target_reserves_x18(target: &Target, target_features: &FxIndexSet<Symbol>) -> bool { | ||
| // See isX18ReservedByDefault in LLVM for targets reserve x18 by default: | ||
| // https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/TargetParser/AArch64TargetParser.cpp#L102-L105 | ||
| // Note that +reserve-x18 is currently not set for the above targets. | ||
| target.os == "android" | ||
| || target.os == "fuchsia" | ||
| || target.env == "ohos" | ||
| || target.is_like_osx | ||
| || target.is_like_windows | ||
| || target_features.contains(&sym::reserve_x18) |
There was a problem hiding this comment.
Is it possible to avoid duplicating this logic? It seems prone to getting out of sync with llvm.
There was a problem hiding this comment.
I can't think of a good way to avoid the duplication unfortunately.
|
This seems correct as far as Trusty is concerned, thanks @taiki-e for addressing this ❤️ I wasn't aware of this when I added the Trusty targets, but as far as I know we don't directly use the |
|
@bors r+ |
…llaumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#133358 (Don't type error if we fail to coerce `Pin<T>` because it doesnt contain a ref) - rust-lang#133422 (Fix clobber_abi in RV32E and RV64E inline assembly) - rust-lang#133452 (Support predicate registers (clobber-only) in Hexagon inline assembly) - rust-lang#133463 (Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18) - rust-lang#133487 (fix confusing diagnostic for reserved `##`) - rust-lang#133557 (Small doc fixes in `rustc_codegen_ssa`) - rust-lang#133560 (Trim extra space in 'repeated `mut`' diagnostic) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#133463 - taiki-e:aarch64-asm-x18, r=Amanieu Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18 Currently AArch64 inline assembly allows using x18 on ohos/trusty or with -Zfixed-x18. https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/compiler/rustc_target/src/asm/aarch64.rs#L74-L76 However, x18 is reserved in these environments and should not be allowed in the input/output operands of inline assemblies as it is in Android, Windows, etc.. https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs#L19 https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/compiler/rustc_target/src/spec/targets/aarch64_unknown_trusty.rs#L18 https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/compiler/rustc_codegen_llvm/src/llvm_util.rs#L764-L771 (As for ohos, +reserve-x18 is [redundant](llvm/llvm-project@c417b7a#diff-0ddf23e0bf2b28b2d05f842f087d1e6f694e8e06d1765e8d0f10d47fddcdff9c) since rust-lang@7a966b9 that starting using llvm's ohos targets. So removed it from target-spec.) This fix may potentially break the code for tier 2 target (aarch64-unknown-linux-ohos). (As for others, aarch64-unknown-trusty is tier 3 and -Zfixed-x18 is unstable so breaking them should be fine.) However, in any case, it seems suspicious that the code that is broken by this was sound. r? `@Amanieu` `@rustbot` label O-AArch64 +A-inline-assembly
Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18 Currently AArch64 inline assembly allows using x18 on ohos/trusty or with -Zfixed-x18. https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/compiler/rustc_target/src/asm/aarch64.rs#L74-L76 However, x18 is reserved in these environments and should not be allowed in the input/output operands of inline assemblies as it is in Android, Windows, etc.. https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs#L19 https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/compiler/rustc_target/src/spec/targets/aarch64_unknown_trusty.rs#L18 https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/compiler/rustc_codegen_llvm/src/llvm_util.rs#L764-L771 (As for ohos, +reserve-x18 is [redundant](llvm/llvm-project@c417b7a#diff-0ddf23e0bf2b28b2d05f842f087d1e6f694e8e06d1765e8d0f10d47fddcdff9c) since rust-lang@7a966b9 that starting using llvm's ohos targets. So removed it from target-spec.) This fix may potentially break the code for tier 2 target (aarch64-unknown-linux-ohos). (As for others, aarch64-unknown-trusty is tier 3 and -Zfixed-x18 is unstable so breaking them should be fine.) However, in any case, it seems suspicious that the code that is broken by this was sound. r? `@Amanieu` `@rustbot` label O-AArch64 +A-inline-assembly
| // #[target_feature]. | ||
| // Note that cfg(target_feature = "reserve-x18") is currently not set for | ||
| // targets that reserve x18 by default. | ||
| ("reserve-x18", Unstable(sym::aarch64_unstable_target_feature), &[]), |
There was a problem hiding this comment.
Is there any cleaner way this could be done? This really should be listed as Forbidden, just like the retpoline flags.
There was a problem hiding this comment.
It seems like it just needs things to be listed in unstable_target_features? That does include "forbidden" target features, so listing it here as forbidden might actually just work.
Currently AArch64 inline assembly allows using x18 on ohos/trusty or with -Zfixed-x18.
rust/compiler/rustc_target/src/asm/aarch64.rs
Lines 74 to 76 in 7db7489
However, x18 is reserved in these environments and should not be allowed in the input/output operands of inline assemblies as it is in Android, Windows, etc..
rust/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs
Line 19 in 7db7489
rust/compiler/rustc_target/src/spec/targets/aarch64_unknown_trusty.rs
Line 18 in 7db7489
rust/compiler/rustc_codegen_llvm/src/llvm_util.rs
Lines 764 to 771 in 7db7489
(As for ohos, +reserve-x18 is redundant since 7a966b9 that starting using llvm's ohos targets. So removed it from target-spec.)
This fix may potentially break the code for tier 2 target (aarch64-unknown-linux-ohos). (As for others, aarch64-unknown-trusty is tier 3 and -Zfixed-x18 is unstable so breaking them should be fine.)
However, in any case, it seems suspicious that the code that is broken by this was sound.
r? @Amanieu
@rustbot label O-AArch64 +A-inline-assembly