Skip to content

Commit 8a8fc0f

Browse files
authored
Unrolled build for rust-lang#136194
Rollup merge of rust-lang#136194 - taiki-e:bpf-clobber-abi, r=amanieu Support clobber_abi in BPF inline assembly This supports [`clobber_abi`](https://doc.rust-lang.org/nightly/reference/inline-assembly.html#abi-clobbers) which is one of the requirements of stabilization mentioned in the tracking Issue for `asm_experimental_arch` (rust-lang#93335). Refs: [Section 1.1 "Registers and calling convention" in BPF ABI Recommended Conventions and Guidelines v1.0](https://github.com/torvalds/linux/blob/v6.13/Documentation/bpf/standardization/abi.rst#11registers-and-calling-convention) > R0 - R5 are scratch registers and BPF programs needs to spill/fill them if necessary across calls. cc `@alessandrod` `@dave-tucker` `@tamird` `@vadorovsky` (target maintainers mentioned in platform support document which will be added by rust-lang#135107) r? `@Amanieu` `@rustbot` label +O-eBPF +A-inline-assembly
2 parents aa4cfd0 + e586382 commit 8a8fc0f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

compiler/rustc_target/src/asm/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ pub enum InlineAsmClobberAbi {
934934
LoongArch,
935935
PowerPC,
936936
S390x,
937+
Bpf,
937938
Msp430,
938939
}
939940

@@ -1003,6 +1004,10 @@ impl InlineAsmClobberAbi {
10031004
"C" | "system" => Ok(InlineAsmClobberAbi::S390x),
10041005
_ => Err(&["C", "system"]),
10051006
},
1007+
InlineAsmArch::Bpf => match name {
1008+
"C" | "system" => Ok(InlineAsmClobberAbi::Bpf),
1009+
_ => Err(&["C", "system"]),
1010+
},
10061011
InlineAsmArch::Msp430 => match name {
10071012
"C" | "system" => Ok(InlineAsmClobberAbi::Msp430),
10081013
_ => Err(&["C", "system"]),
@@ -1278,6 +1283,14 @@ impl InlineAsmClobberAbi {
12781283
a8, a9, a10, a11, a12, a13, a14, a15,
12791284
}
12801285
},
1286+
InlineAsmClobberAbi::Bpf => clobbered_regs! {
1287+
Bpf BpfInlineAsmReg {
1288+
// Refs: Section 1.1 "Registers and calling convention" in BPF ABI Recommended Conventions and Guidelines v1.0
1289+
// https://www.kernel.org/doc/html/latest/bpf/standardization/abi.html#registers-and-calling-convention
1290+
1291+
r0, r1, r2, r3, r4, r5,
1292+
}
1293+
},
12811294
InlineAsmClobberAbi::Msp430 => clobbered_regs! {
12821295
Msp430 Msp430InlineAsmReg {
12831296
r11, r12, r13, r14, r15,

tests/codegen/asm/bpf-clobbers.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: --target bpfel-unknown-none
3+
//@ needs-llvm-components: bpf
4+
5+
#![crate_type = "rlib"]
6+
#![feature(no_core, asm_experimental_arch)]
7+
#![no_core]
8+
9+
extern crate minicore;
10+
use minicore::*;
11+
12+
// CHECK-LABEL: @flags_clobber
13+
// CHECK: call void asm sideeffect "", ""()
14+
#[no_mangle]
15+
pub unsafe fn flags_clobber() {
16+
asm!("", options(nostack, nomem));
17+
}
18+
19+
// CHECK-LABEL: @no_clobber
20+
// CHECK: call void asm sideeffect "", ""()
21+
#[no_mangle]
22+
pub unsafe fn no_clobber() {
23+
asm!("", options(nostack, nomem, preserves_flags));
24+
}
25+
26+
// CHECK-LABEL: @clobber_abi
27+
// CHECK: asm sideeffect "", "={r0},={r1},={r2},={r3},={r4},={r5}"()
28+
#[no_mangle]
29+
pub unsafe fn clobber_abi() {
30+
asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags));
31+
}

0 commit comments

Comments
 (0)