bpf: Remove builtin global functions

This commit removes memset and memcpy, relying instead on
implementations provided by std/compiler-builtins.

This commit adds `#![no_builtins]` to all the BPF programs written in
Rust, and the same should be propagated to aya-template and all examples
in the book and elsewhere before this commit is merged.

It turns out that without the `#![no_builtins]` annotation rustc
generates LLVM IR that calls LLVM intrinsics rather than libcalls. These
may end up as libcalls after lowering, but not before emitting errors in
BPF lowering[0].

This works thanks to https://github.com/rust-lang/rust/pull/113716 which
causes `#![no_builtins]` to behave similarly to `-fno-builtin` in clang,
which was added in https://reviews.llvm.org/D68028 with similar
motivation.

This commit implies that we now require rustc nightly >= 2023-07-20.

[0] https://github.com/llvm/llvm-project/blob/7b2745b/llvm/lib/Target/BPF/BPFISelLowering.cpp#L472-L474
pull/698/head
Tamir Duberstein 2 years ago
parent e68fa14d71
commit e9a099f332

@ -31,7 +31,7 @@ use core::ffi::c_void;
pub use aya_bpf_cty as cty;
pub use aya_bpf_macros as macros;
use cty::{c_int, c_long};
use cty::c_long;
use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid, bpf_get_current_uid_gid};
pub const TASK_COMM_LEN: usize = 16;
@ -61,22 +61,6 @@ pub trait BpfContext {
}
}
#[no_mangle]
pub unsafe extern "C" fn memset(s: *mut u8, c: c_int, n: usize) {
#[allow(clippy::cast_sign_loss)]
let b = c as u8;
for i in 0..n {
*s.add(i) = b;
}
}
#[no_mangle]
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *mut u8, n: usize) {
for i in 0..n {
*dest.add(i) = *src.add(i);
}
}
/// Check if a value is within a range, using conditional forms compatible with
/// the verifier.
#[inline(always)]

@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]
use aya_bpf::{
helpers::{bpf_probe_read_kernel_str_bytes, bpf_probe_read_user_str_bytes},

@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]
use aya_bpf::{macros::uprobe, programs::ProbeContext};
use aya_log_ebpf::{debug, error, info, trace, warn};

@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]
use aya_bpf::{
bindings::xdp_action,

@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]
use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};

@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]
use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};

@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]
use core::hint;

@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]
use aya_bpf::{
bindings::xdp_action,

@ -2587,5 +2587,3 @@ pub fn aya_bpf::programs::tracepoint::TracePointContext::as_ptr(&self) -> *mut c
impl aya_bpf::BpfContext for aya_bpf::programs::xdp::XdpContext
pub fn aya_bpf::programs::xdp::XdpContext::as_ptr(&self) -> *mut core::ffi::c_void
pub fn aya_bpf::check_bounds_signed(value: i64, lower: i64, upper: i64) -> bool
#[no_mangle] pub unsafe c fn aya_bpf::memcpy(dest: *mut u8, src: *mut u8, n: usize)
#[no_mangle] pub unsafe c fn aya_bpf::memset(s: *mut u8, c: aya_bpf_cty::ad::c_int, n: usize)

Loading…
Cancel
Save