MCPcopy Index your code
hub / github.com/aya-rs/bpf-linker

github.com/aya-rs/bpf-linker @v0.10.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.10.4 ↗ · + Follow
240 symbols 445 edges 37 files 53 documented · 22% updated 1d agov0.10.4 · 2026-06-17★ 2869 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

BPF Linker 🔗

bpf-linker aims to simplify building modern BPF programs while still supporting older, more restrictive kernels.

Build status

Overview

bpf-linker can be used to statically link multiple BPF object files together and optionally perform optimizations needed to target older kernels. It operates on LLVM bitcode, so the inputs can be bitcode files (.bc), LLVM IR files (.ll), or object files with embedded bitcode (.o), optionally stored inside ar archives (.a).

Installation

cargo-binstall

The recommended installation method is via cargo-binstall. Install cargo-binstall first, then run:

cargo binstall bpf-linker

Manual download

Download the tarball from the releases page that matches your Rust target triple. The published binaries currently use *-apple-darwin for macOS and *-unknown-linux-musl for Linux, and *-pc-windows-gnullvm for Windows.

After downloading, unpack the archive into a directory that is included in your PATH.

Example:

# Linux ARM64
curl -LO https://github.com/aya-rs/bpf-linker/releases/latest/download/bpf-linker-aarch64-unknown-linux-musl.tar.zst
# Linux x86_64
curl -LO https://github.com/aya-rs/bpf-linker/releases/latest/download/bpf-linker-x86_64-unknown-linux-musl.tar.zst
# macOS ARM64
curl -LO https://github.com/aya-rs/bpf-linker/releases/latest/download/bpf-linker-aarch64-apple-darwin.tar.zst
# macOS x86_64
curl -LO https://github.com/aya-rs/bpf-linker/releases/latest/download/bpf-linker-x86_64-apple-darwin.tar.zst
# Windows ARM64
curl -LO https://github.com/aya-rs/bpf-linker/releases/latest/download/bpf-linker-aarch64-pc-windows-gnullvm.tar.zst
# Windows x86_64
curl -LO https://github.com/aya-rs/bpf-linker/releases/latest/download/bpf-linker-x86_64-pc-windows-gnullvm.tar.zst

mkdir -p "$HOME/.local/bin"
tar -xpf bpf-linker-*.tar.zst -C "$HOME/.local/bin"
# Add this line to your shell startup file. If you use a different shell,
# refer to its documentation for adding directories to PATH.
export PATH="$HOME/.local/bin:$PATH"

Packages

bpf-linker may also be available through your operating system's package repositories. In general, packaged builds are expected to work with Rust toolchains provided by the same package manager. If you use Rust via rustup, prefer installing bpf-linker with cargo-binstall or from the release tarballs instead.

Current packaging status:

Packaging status

Building from source

Building from source, including even a plain cargo install bpf-linker invocation, is not recommended for regular users due to dependency on specific LLVM version, system libraries and overall complexity of getting the setup right.

If you're interested in packaging or contributing to bpf-linker, you're welcome to check the build instructions in BUILDING.md.

Usage

Rust

Nightly

To compile your eBPF crate just run:

cargo +nightly build --target=bpfel-unknown-none -Z build-std=core --release

If you don't want to have to pass the target and build-std options every time, you can put them in .cargo/config.toml under the crate's root folder:

[build]
target = "bpfel-unknown-none"

[unstable]
build-std = ["core"]
(Experimental) BTF support

To emit BTF debug information, set the following rustflags:

-C debuginfo=2 -C link-arg=--btf

These flags will work only for the eBPF targets (bpfeb-unknown-none, bpfel-unknown-none). Make sure you are specifying them only for eBPF crates, not for the user-space ones!

When compiling an eBPF crate directly with cargo +nightly build, they can be defined through the RUSTFLAGS environment variable:

RUSTFLAGS="-C debuginfo=2 -C link-arg=--btf" cargo +nightly build --target=bpfel-unknown-none -Z build-std=core --release

To avoid specifying them manually, you can put them in .cargo/config.toml:

[build]
target = "bpfel-unknown-none"
rustflags = "-C debuginfo=2 -C link-arg=--btf"

[unstable]
build-std = ["core"]

After that, the BPF object file present in target/bpfel-unknown-none/release should contain a BTF section.

Clang

For a simple example of how to use the linker with clang see this gist. In the example lib.c is compiled as a static library which is then linked by program.c. The Makefile shows how to compile the C code and then link it.

CLI syntax

bpf-linker

USAGE:
    bpf-linker [FLAGS] [OPTIONS] --output <output> [--] [inputs]...

FLAGS:
        --disable-expand-memcpy-in-order    Disable passing --bpf-expand-memcpy-in-order to LLVM
        --disable-memory-builtins           Disble exporting memcpy, memmove, memset, memcmp and bcmp. Exporting those
                                            is commonly needed when LLVM does not manage to expand memory intrinsics to
                                            a sequence of loads and stores
    -h, --help                              Prints help information
        --ignore-inline-never               Ignore `noinline`/`#[inline(never)]`. Useful when targeting kernels that
                                            don't support function calls
        --unroll-loops                      Try hard to unroll loops. Useful when targeting kernels that don't support
                                            loops
    -V, --version                           Prints version information

OPTIONS:
        --cpu <cpu>                  Target BPF processor. Can be one of `generic`, `probe`, `v1`, `v2`, `v3` [default:
                                     generic]
        --cpu-features <features>    Enable or disable CPU features. The available features are: alu32, dummy, dwarfris.
                                     LLVM 22 builds also support allows-misaligned-mem-access. Use +feature to
                                     enable a feature, or -feature to disable it. For example --cpu-features=+allows-
                                     misaligned-mem-access,+alu32,-dwarfris [default: ]
        --dump-module <path>         Dump the final IR module to the given `path` before generating the code
        --emit <emit>                Output type. Can be one of `llvm-bc`, `asm`, `llvm-ir`, `obj` [default: obj]
        --export <symbols>...        Comma separated list of symbols to export. See also `--export-symbols`
        --export-symbols <path>      Export the symbols specified in the file `path`. The symbols must be separated by
                                     new lines
    -L <libs>...                     Add a directory to the library search path
        --llvm-args <args>...        Extra command line arguments to pass to LLVM
        --log-file <path>            Output logs to the given `path`
        --log-level <level>          Set the log level. Can be one of `off`, `info`, `warn`, `debug`, `trace`
    -O <optimize>...                 Optimization level. 0-3, s, or z [default: 2]
    -o, --output <output>            Write output to <output>
        --target <target>            LLVM target triple. When not provided, the target is inferred from the inputs

ARGS:
    <inputs>...    Input files. Can be object files or static libraries

License

bpf-linker is licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Extension points exported contracts — how you extend this code

LLVMDiagnosticHandler (Interface)
(no doc) [1 implementers]
src/llvm/mod.rs
Add (Interface)
(no doc) [1 implementers]
tests/assembly/di_generics.rs

Core symbols most depended-on inside this repo

as_mut_ptr
called by 29
src/llvm/types/module.rs
add
called by 13
tests/assembly/di_generics.rs
as_ref
called by 12
src/linker.rs
as_string_lossy
called by 8
src/llvm/mod.rs
iter
called by 8
src/llvm/types/ir.rs
iter
called by 6
build.rs
as_slice
called by 5
src/llvm/types/memory_buffer.rs
as_slice
called by 4
src/linker.rs

Shape

Method 104
Function 82
Class 31
Enum 21
Interface 2

Languages

Rust98%
Python2%
C1%

Modules by API surface

src/linker.rs36 symbols
src/llvm/types/di.rs32 symbols
src/llvm/types/ir.rs22 symbols
src/llvm/mod.rs18 symbols
build.rs15 symbols
src/llvm/di.rs13 symbols
src/llvm/types/module.rs12 symbols
src/llvm/types/context.rs10 symbols
src/bin/bpf-linker.rs10 symbols
xtask/src/main.rs9 symbols
tests/compiletest.rs9 symbols
tests/assembly/di_generics.rs6 symbols

For agents

$ claude mcp add bpf-linker \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact