Add BPF target
This change adds the bpfel-unknown-none and bpfeb-unknown-none targets which can be used to generate little endian and big endian BPF
This commit is contained in:
parent
92418ce65a
commit
12e70929d6
18 changed files with 250 additions and 3 deletions
31
compiler/rustc_target/src/abi/call/bpf.rs
Normal file
31
compiler/rustc_target/src/abi/call/bpf.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
// see BPFCallingConv.td
|
||||
use crate::abi::call::{ArgAbi, FnAbi};
|
||||
|
||||
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
|
||||
if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 {
|
||||
ret.make_indirect();
|
||||
} else {
|
||||
ret.extend_integer_width_to(64);
|
||||
}
|
||||
}
|
||||
|
||||
fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
|
||||
if arg.layout.is_aggregate() || arg.layout.size.bits() > 64 {
|
||||
arg.make_indirect();
|
||||
} else {
|
||||
arg.extend_integer_width_to(64);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
|
||||
if !fn_abi.ret.is_ignore() {
|
||||
classify_ret(&mut fn_abi.ret);
|
||||
}
|
||||
|
||||
for arg in &mut fn_abi.args {
|
||||
if arg.is_ignore() {
|
||||
continue;
|
||||
}
|
||||
classify_arg(arg);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ mod aarch64;
|
|||
mod amdgpu;
|
||||
mod arm;
|
||||
mod avr;
|
||||
mod bpf;
|
||||
mod hexagon;
|
||||
mod mips;
|
||||
mod mips64;
|
||||
|
@ -654,6 +655,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
|
|||
}
|
||||
}
|
||||
"asmjs" => wasm::compute_c_abi_info(cx, self),
|
||||
"bpfel" | "bpfeb" => bpf::compute_abi_info(self),
|
||||
a => return Err(format!("unrecognized arch \"{}\" in target specification", a)),
|
||||
}
|
||||
|
||||
|
|
37
compiler/rustc_target/src/spec/bpf_base.rs
Normal file
37
compiler/rustc_target/src/spec/bpf_base.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use crate::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, TargetOptions};
|
||||
use crate::{abi::Endian, spec::abi::Abi};
|
||||
|
||||
pub fn opts(endian: Endian) -> TargetOptions {
|
||||
TargetOptions {
|
||||
endian,
|
||||
linker_flavor: LinkerFlavor::BpfLinker,
|
||||
atomic_cas: false,
|
||||
executables: true,
|
||||
dynamic_linking: true,
|
||||
no_builtins: true,
|
||||
panic_strategy: PanicStrategy::Abort,
|
||||
position_independent_executables: true,
|
||||
merge_functions: MergeFunctions::Disabled,
|
||||
obj_is_bitcode: true,
|
||||
requires_lto: false,
|
||||
singlethread: true,
|
||||
max_atomic_width: Some(64),
|
||||
unsupported_abis: vec![
|
||||
Abi::Cdecl,
|
||||
Abi::Stdcall { unwind: false },
|
||||
Abi::Stdcall { unwind: true },
|
||||
Abi::Fastcall,
|
||||
Abi::Vectorcall,
|
||||
Abi::Thiscall { unwind: false },
|
||||
Abi::Thiscall { unwind: true },
|
||||
Abi::Aapcs,
|
||||
Abi::Win64,
|
||||
Abi::SysV64,
|
||||
Abi::PtxKernel,
|
||||
Abi::Msp430Interrupt,
|
||||
Abi::X86Interrupt,
|
||||
Abi::AmdGpuKernel,
|
||||
],
|
||||
..Default::default()
|
||||
}
|
||||
}
|
12
compiler/rustc_target/src/spec/bpfeb_unknown_none.rs
Normal file
12
compiler/rustc_target/src/spec/bpfeb_unknown_none.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::spec::Target;
|
||||
use crate::{abi::Endian, spec::bpf_base};
|
||||
|
||||
pub fn target() -> Target {
|
||||
Target {
|
||||
llvm_target: "bpfeb".to_string(),
|
||||
data_layout: "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128".to_string(),
|
||||
pointer_width: 64,
|
||||
arch: "bpfeb".to_string(),
|
||||
options: bpf_base::opts(Endian::Big),
|
||||
}
|
||||
}
|
12
compiler/rustc_target/src/spec/bpfel_unknown_none.rs
Normal file
12
compiler/rustc_target/src/spec/bpfel_unknown_none.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::spec::Target;
|
||||
use crate::{abi::Endian, spec::bpf_base};
|
||||
|
||||
pub fn target() -> Target {
|
||||
Target {
|
||||
llvm_target: "bpfel".to_string(),
|
||||
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".to_string(),
|
||||
pointer_width: 64,
|
||||
arch: "bpfel".to_string(),
|
||||
options: bpf_base::opts(Endian::Little),
|
||||
}
|
||||
}
|
|
@ -57,6 +57,7 @@ mod apple_base;
|
|||
mod apple_sdk_base;
|
||||
mod arm_base;
|
||||
mod avr_gnu_base;
|
||||
mod bpf_base;
|
||||
mod dragonfly_base;
|
||||
mod freebsd_base;
|
||||
mod fuchsia_base;
|
||||
|
@ -93,6 +94,7 @@ pub enum LinkerFlavor {
|
|||
Msvc,
|
||||
Lld(LldFlavor),
|
||||
PtxLinker,
|
||||
BpfLinker,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
|
@ -161,6 +163,7 @@ flavor_mappings! {
|
|||
((LinkerFlavor::Ld), "ld"),
|
||||
((LinkerFlavor::Msvc), "msvc"),
|
||||
((LinkerFlavor::PtxLinker), "ptx-linker"),
|
||||
((LinkerFlavor::BpfLinker), "bpf-linker"),
|
||||
((LinkerFlavor::Lld(LldFlavor::Wasm)), "wasm-ld"),
|
||||
((LinkerFlavor::Lld(LldFlavor::Ld64)), "ld64.lld"),
|
||||
((LinkerFlavor::Lld(LldFlavor::Ld)), "ld.lld"),
|
||||
|
@ -897,6 +900,9 @@ supported_targets! {
|
|||
("aarch64_be-unknown-linux-gnu", aarch64_be_unknown_linux_gnu),
|
||||
("aarch64-unknown-linux-gnu_ilp32", aarch64_unknown_linux_gnu_ilp32),
|
||||
("aarch64_be-unknown-linux-gnu_ilp32", aarch64_be_unknown_linux_gnu_ilp32),
|
||||
|
||||
("bpfeb-unknown-none", bpfeb_unknown_none),
|
||||
("bpfel-unknown-none", bpfel_unknown_none),
|
||||
}
|
||||
|
||||
/// Everything `rustc` knows about how to compile for a specific target.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue