You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aya/aya-obj
Michal R 5f2fb90f38 aya-obj: Sanitize type names
Rust emits characters like `<` and `>` in name types with generics, that
are not accepted by the Linux kernel.

In theory, the correct place to fix that would be the Linux kernel, but
given that we have to support old kernels and that such change would be
controversial, it's better to fix it up on our side, at least for now.

We used to rely on bpf-linker to fix that up, but given that we want to
support binutils at some point, we need to do it in Aya during the load.
4 days ago
..
include codegen: tidy up 9 months ago
src aya-obj: Sanitize type names 4 days ago
CHANGELOG.md Release aya-obj v0.2.1 1 year ago
Cargo.toml aya-obj: Sanitize type names 4 days ago
README.md aya-obj: update documentation and versioning info 3 years ago

README.md

aya-obj

Status

This crate includes code that started as internal API used by the aya crate. It has been split out so that it can be used by other projects that deal with eBPF object files. Unless you're writing low level eBPF plumbing tools, you should not need to use this crate but see the aya crate instead.

The API as it is today has a few rough edges and is generally not as polished nor stable as the main aya crate API. As always, improvements welcome!

Overview

eBPF programs written with libbpf or aya-bpf are usually compiled into an ELF object file, using various sections to store information about the eBPF programs.

aya-obj is a library for parsing such eBPF object files, with BTF and relocation support.

Example

This example loads a simple eBPF program and runs it with rbpf.

use aya_obj::{generated::bpf_insn, Object};

// Parse the object file
let bytes = std::fs::read("program.o").unwrap();
let mut object = Object::parse(&bytes).unwrap();
// Relocate the programs
object.relocate_calls().unwrap();
object.relocate_maps(std::iter::empty()).unwrap();

// Run with rbpf
let instructions = &object.programs["prog_name"].function.instructions;
let data = unsafe {
    core::slice::from_raw_parts(
        instructions.as_ptr() as *const u8,
        instructions.len() * core::mem::size_of::<bpf_insn>(),
    )
};
let vm = rbpf::EbpfVmNoData::new(Some(data)).unwrap();
let _return = vm.execute_program().unwrap();