From a07bd236bdb47d165c9c7f62e35e2a9a3d773ad6 Mon Sep 17 00:00:00 2001 From: WANG Rui Date: Thu, 13 Nov 2025 23:51:01 +0800 Subject: [PATCH] rustc_target: Add `efiapi` ABI support for LoongArch This commit adds basic `efiapi` ABI support for LoongArch by recognizing `extern "efiapi"` in the ABI map and inline asm clobber handling, and mapping it to the C calling convention. This change is intentionally submitted ahead of the full LoongArch UEFI target support. While UEFI binaries are ultimately produced as PE images, LoongArch UEFI applications can already be developed by building ELF objects, applying relocation fixups, and converting them to PE in a later step. For such workflows, having `efiapi` properly recognized by the compiler is a prerequisite, even without a dedicated UEFI target. Landing this ABI support early helps unblock LoongArch UEFI application and driver development, and allows the remaining UEFI-specific pieces to be introduced incrementally in follow-up patches. MCP: https://github.com/rust-lang/compiler-team/issues/953 --- compiler/rustc_target/src/asm/mod.rs | 4 ++-- compiler/rustc_target/src/spec/abi_map.rs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 05b24d7109481..0078866ab9503 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -997,8 +997,8 @@ impl InlineAsmClobberAbi { _ => Err(&["C", "system"]), }, InlineAsmArch::LoongArch32 | InlineAsmArch::LoongArch64 => match name { - "C" | "system" => Ok(InlineAsmClobberAbi::LoongArch), - _ => Err(&["C", "system"]), + "C" | "system" | "efiapi" => Ok(InlineAsmClobberAbi::LoongArch), + _ => Err(&["C", "system", "efiapi"]), }, InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => match name { "C" | "system" => Ok(if target.abi == Abi::Spe { diff --git a/compiler/rustc_target/src/spec/abi_map.rs b/compiler/rustc_target/src/spec/abi_map.rs index 8126227d80e48..d7fc18cd3761e 100644 --- a/compiler/rustc_target/src/spec/abi_map.rs +++ b/compiler/rustc_target/src/spec/abi_map.rs @@ -56,6 +56,7 @@ impl AbiMap { ArmVer::Other }), Arch::Avr => ArchKind::Avr, + Arch::LoongArch32 | Arch::LoongArch64 => ArchKind::LoongArch, Arch::Msp430 => ArchKind::Msp430, Arch::Nvptx64 => ArchKind::Nvptx, Arch::RiscV32 | Arch::RiscV64 => ArchKind::Riscv, @@ -108,7 +109,10 @@ impl AbiMap { (ExternAbi::EfiApi, ArchKind::Arm(..)) => CanonAbi::Arm(ArmCall::Aapcs), (ExternAbi::EfiApi, ArchKind::X86_64) => CanonAbi::X86(X86Call::Win64), - (ExternAbi::EfiApi, ArchKind::Aarch64 | ArchKind::Riscv | ArchKind::X86) => CanonAbi::C, + ( + ExternAbi::EfiApi, + ArchKind::Aarch64 | ArchKind::LoongArch | ArchKind::Riscv | ArchKind::X86, + ) => CanonAbi::C, (ExternAbi::EfiApi, _) => return AbiMapping::Invalid, /* arm */ @@ -196,6 +200,7 @@ enum ArchKind { Amdgpu, Arm(ArmVer), Avr, + LoongArch, Msp430, Nvptx, Riscv,