Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18

This commit is contained in:
Taiki Endo
2024-11-26 03:10:22 +09:00
parent 7db7489f9b
commit 687dc19cb6
11 changed files with 95 additions and 53 deletions

View File

@@ -1,7 +1,7 @@
use std::fmt;
use rustc_data_structures::fx::FxIndexSet;
use rustc_span::Symbol;
use rustc_span::{Symbol, sym};
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
use crate::spec::{RelocModel, Target};
@@ -71,18 +71,26 @@ impl AArch64InlineAsmRegClass {
}
}
pub(crate) fn target_reserves_x18(target: &Target) -> bool {
target.os == "android" || target.os == "fuchsia" || target.is_like_osx || target.is_like_windows
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)
}
fn reserved_x18(
_arch: InlineAsmArch,
_reloc_model: RelocModel,
_target_features: &FxIndexSet<Symbol>,
target_features: &FxIndexSet<Symbol>,
target: &Target,
_is_clobber: bool,
) -> Result<(), &'static str> {
if target_reserves_x18(target) {
if target_reserves_x18(target, target_features) {
Err("x18 is a reserved register on this target")
} else {
Ok(())

View File

@@ -941,6 +941,7 @@ impl InlineAsmClobberAbi {
pub fn parse(
arch: InlineAsmArch,
target: &Target,
target_features: &FxIndexSet<Symbol>,
name: Symbol,
) -> Result<Self, &'static [&'static str]> {
let name = name.as_str();
@@ -963,11 +964,13 @@ impl InlineAsmClobberAbi {
_ => Err(&["C", "system", "efiapi", "aapcs"]),
},
InlineAsmArch::AArch64 => match name {
"C" | "system" | "efiapi" => Ok(if aarch64::target_reserves_x18(target) {
InlineAsmClobberAbi::AArch64NoX18
} else {
InlineAsmClobberAbi::AArch64
}),
"C" | "system" | "efiapi" => {
Ok(if aarch64::target_reserves_x18(target, target_features) {
InlineAsmClobberAbi::AArch64NoX18
} else {
InlineAsmClobberAbi::AArch64
})
}
_ => Err(&["C", "system", "efiapi"]),
},
InlineAsmArch::Arm64EC => match name {