LinkerFlavor::Msvc => "link.exe",
LinkerFlavor::Lld(_) => "lld",
LinkerFlavor::PtxLinker => "rust-ptx-linker",
+ LinkerFlavor::BpfLinker => "bpf-linker",
}),
flavor,
)),
LinkerFlavor::Msvc => "link.exe",
LinkerFlavor::Lld(_) => "lld",
LinkerFlavor::PtxLinker => "rust-ptx-linker",
+ LinkerFlavor::BpfLinker => "bpf-linker",
}),
flavor,
)),
LinkerFlavor::PtxLinker => {
Box::new(PtxLinker { cmd, sess, info: self }) as Box<dyn Linker>
}
+ LinkerFlavor::BpfLinker => Box::new(BpfLinker { cmd, sess, info: self }) as Box<dyn Linker>
}
}
}
fn linker_plugin_lto(&mut self) {}
}
+
+pub struct BpfLinker<'a> {
+ cmd: Command,
+ sess: &'a Session,
+ info: &'a LinkerInfo,
+}
+
+impl<'a> Linker for BpfLinker<'a> {
+ fn cmd(&mut self) -> &mut Command {
+ &mut self.cmd
+ }
+
+ fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
+
+ fn link_rlib(&mut self, path: &Path) {
+ self.cmd.arg(path);
+ }
+
+ fn link_whole_rlib(&mut self, path: &Path) {
+ self.cmd.arg(path);
+ }
+
+ fn include_path(&mut self, path: &Path) {
+ self.cmd.arg("-L").arg(path);
+ }
+
+ fn debuginfo(&mut self, _strip: Strip) {
+ self.cmd.arg("--debug");
+ }
+
+ fn add_object(&mut self, path: &Path) {
+ self.cmd.arg(path);
+ }
+
+ fn optimize(&mut self) {
+ self.cmd.arg(match self.sess.opts.optimize {
+ OptLevel::No => "-O0",
+ OptLevel::Less => "-O1",
+ OptLevel::Default => "-O2",
+ OptLevel::Aggressive => "-O3",
+ OptLevel::Size => "-Os",
+ OptLevel::SizeMin => "-Oz",
+ });
+ }
+
+ fn output_filename(&mut self, path: &Path) {
+ self.cmd.arg("-o").arg(path);
+ }
+
+ fn finalize(&mut self) {
+ self.cmd.arg("--cpu").arg(match self.sess.opts.cg.target_cpu {
+ Some(ref s) => s,
+ None => &self.sess.target.options.cpu,
+ });
+ }
+
+ fn link_dylib(&mut self, _lib: Symbol, _verbatim: bool, _as_needed: bool) {
+ panic!("external dylibs not supported")
+ }
+
+ fn link_rust_dylib(&mut self, _lib: Symbol, _path: &Path) {
+ panic!("external dylibs not supported")
+ }
+
+ fn link_staticlib(&mut self, _lib: Symbol, _verbatim: bool) {
+ panic!("staticlibs not supported")
+ }
+
+ fn link_whole_staticlib(&mut self, _lib: Symbol, _verbatim: bool, _search_path: &[PathBuf]) {
+ panic!("staticlibs not supported")
+ }
+
+ fn framework_path(&mut self, _path: &Path) {
+ panic!("frameworks not supported")
+ }
+
+ fn link_framework(&mut self, _framework: Symbol, _as_needed: bool) {
+ panic!("frameworks not supported")
+ }
+
+ fn full_relro(&mut self) {}
+
+ fn partial_relro(&mut self) {}
+
+ fn no_relro(&mut self) {}
+
+ fn gc_sections(&mut self, _keep_metadata: bool) {}
+
+ fn no_gc_sections(&mut self) {}
+
+ fn pgo_gen(&mut self) {}
+
+ fn no_crt_objects(&mut self) {}
+
+ fn no_default_libraries(&mut self) {}
+
+ fn control_flow_guard(&mut self) {}
+
+ fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType) {
+ let path = tmpdir.join("symbols");
+ let res: io::Result<()> = try {
+ let mut f = BufWriter::new(File::create(&path)?);
+ for sym in self.info.exports[&crate_type].iter() {
+ writeln!(f, "{}", sym)?;
+ }
+ };
+ if let Err(e) = res {
+ self.sess.fatal(&format!("failed to write symbols file: {}", e));
+ } else {
+ self.cmd.arg("--export-symbols").arg(&path);
+ }
+ }
+
+ fn subsystem(&mut self, _subsystem: &str) {}
+
+ fn group_start(&mut self) {}
+
+ fn group_end(&mut self) {}
+
+ fn linker_plugin_lto(&mut self) {}
+}
"nvptx",
"hexagon",
"riscv",
+ "bpf",
];
let required_components = &[
LLVMInitializeWebAssemblyAsmPrinter,
LLVMInitializeWebAssemblyAsmParser
);
+ init_target!(
+ llvm_component = "bpf",
+ LLVMInitializeBPFTargetInfo,
+ LLVMInitializeBPFTarget,
+ LLVMInitializeBPFTargetMC,
+ LLVMInitializeBPFAsmPrinter,
+ LLVMInitializeBPFAsmParser
+ );
}
--- /dev/null
+// 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);
+ }
+}
mod amdgpu;
mod arm;
mod avr;
+mod bpf;
mod hexagon;
mod mips;
mod mips64;
}
}
"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)),
}
--- /dev/null
+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()
+ }
+}
--- /dev/null
+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),
+ }
+}
--- /dev/null
+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),
+ }
+}
mod apple_sdk_base;
mod arm_base;
mod avr_gnu_base;
+mod bpf_base;
mod dragonfly_base;
mod freebsd_base;
mod fuchsia_base;
Msvc,
Lld(LldFlavor),
PtxLinker,
+ BpfLinker,
}
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
((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"),
("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.
if builder.no_std(target) == Some(true) {
let mut features = "compiler-builtins-mem".to_string();
- features.push_str(compiler_builtins_c_feature);
+ if !target.starts_with("bpf") {
+ features.push_str(compiler_builtins_c_feature);
+ }
// for no-std targets we only compile a few no_std crates
cargo
Some(s) => s,
None => {
"AArch64;ARM;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;\
- Sparc;SystemZ;WebAssembly;X86"
+ Sparc;SystemZ;WebAssembly;X86;BPF"
}
};
|| target.contains("wasm32")
|| target.contains("nvptx")
|| target.contains("fortanix")
- || target.contains("fuchsia"))
+ || target.contains("fuchsia")
+ || target.contains("bpf"))
}
* `ptx-linker`: use
[`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker) for Nvidia
NVPTX GPGPU support.
+* `bpf-linker`: use
+ [`bpf-linker`](https://github.com/alessandrod/bpf-linker) for eBPF support.
* `wasm-ld`: use the [`wasm-ld`](https://lld.llvm.org/WebAssembly.html)
executable, a port of LLVM `lld` for WebAssembly.
* `ld64.lld`: use the LLVM `lld` executable with the [`-flavor darwin`
"armv7r-none-eabihf",
"armv7s-apple-ios",
"asmjs-unknown-emscripten",
+ "bpfeb-unknown-none",
+ "bpfel-unknown-none",
"i386-apple-ios",
"i586-pc-windows-msvc",
"i586-unknown-linux-gnu",
|| self.config.target.contains("nvptx")
|| self.is_vxworks_pure_static()
|| self.config.target.contains("sgx")
+ || self.config.target.contains("bpf")
{
// We primarily compile all auxiliary libraries as dynamic libraries
// to avoid code size bloat and large binaries as much as possible
// No extra flags needed.
}
+ Some("bpf-linker") => {
+ rustc.arg("-Clink-args=--emit=asm");
+ }
+
Some(_) => self.fatal("unknown 'assembly-output' header"),
None => self.fatal("missing 'assembly-output' header"),
}
("armv7s", "arm"),
("asmjs", "asmjs"),
("avr", "avr"),
+ ("bpfeb", "bpfeb"),
+ ("bpfel", "bpfel"),
("hexagon", "hexagon"),
("i386", "x86"),
("i586", "x86"),