mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 06:26:55 +00:00
Support clobber_abi in BPF inline assembly
This commit is contained in:
parent
aa6f5ab18e
commit
e586382feb
@ -934,6 +934,7 @@ pub enum InlineAsmClobberAbi {
|
||||
LoongArch,
|
||||
PowerPC,
|
||||
S390x,
|
||||
Bpf,
|
||||
Msp430,
|
||||
}
|
||||
|
||||
@ -1003,6 +1004,10 @@ impl InlineAsmClobberAbi {
|
||||
"C" | "system" => Ok(InlineAsmClobberAbi::S390x),
|
||||
_ => Err(&["C", "system"]),
|
||||
},
|
||||
InlineAsmArch::Bpf => match name {
|
||||
"C" | "system" => Ok(InlineAsmClobberAbi::Bpf),
|
||||
_ => Err(&["C", "system"]),
|
||||
},
|
||||
InlineAsmArch::Msp430 => match name {
|
||||
"C" | "system" => Ok(InlineAsmClobberAbi::Msp430),
|
||||
_ => Err(&["C", "system"]),
|
||||
@ -1278,6 +1283,14 @@ impl InlineAsmClobberAbi {
|
||||
a8, a9, a10, a11, a12, a13, a14, a15,
|
||||
}
|
||||
},
|
||||
InlineAsmClobberAbi::Bpf => clobbered_regs! {
|
||||
Bpf BpfInlineAsmReg {
|
||||
// Refs: Section 1.1 "Registers and calling convention" in BPF ABI Recommended Conventions and Guidelines v1.0
|
||||
// https://www.kernel.org/doc/html/latest/bpf/standardization/abi.html#registers-and-calling-convention
|
||||
|
||||
r0, r1, r2, r3, r4, r5,
|
||||
}
|
||||
},
|
||||
InlineAsmClobberAbi::Msp430 => clobbered_regs! {
|
||||
Msp430 Msp430InlineAsmReg {
|
||||
r11, r12, r13, r14, r15,
|
||||
|
31
tests/codegen/asm/bpf-clobbers.rs
Normal file
31
tests/codegen/asm/bpf-clobbers.rs
Normal file
@ -0,0 +1,31 @@
|
||||
//@ add-core-stubs
|
||||
//@ compile-flags: --target bpfel-unknown-none
|
||||
//@ needs-llvm-components: bpf
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
#![feature(no_core, asm_experimental_arch)]
|
||||
#![no_core]
|
||||
|
||||
extern crate minicore;
|
||||
use minicore::*;
|
||||
|
||||
// CHECK-LABEL: @flags_clobber
|
||||
// CHECK: call void asm sideeffect "", ""()
|
||||
#[no_mangle]
|
||||
pub unsafe fn flags_clobber() {
|
||||
asm!("", options(nostack, nomem));
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @no_clobber
|
||||
// CHECK: call void asm sideeffect "", ""()
|
||||
#[no_mangle]
|
||||
pub unsafe fn no_clobber() {
|
||||
asm!("", options(nostack, nomem, preserves_flags));
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @clobber_abi
|
||||
// CHECK: asm sideeffect "", "={r0},={r1},={r2},={r3},={r4},={r5}"()
|
||||
#[no_mangle]
|
||||
pub unsafe fn clobber_abi() {
|
||||
asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags));
|
||||
}
|
Loading…
Reference in New Issue
Block a user