# aya-rs/bpf-linker architecture

> Architecture diagram of the GitHub repository aya-rs/bpf-linker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aya-rs/bpf-linker
- Repository: https://github.com/aya-rs/bpf-linker

## Overview

BPF Linker is a command-line static linker for LLVM bitcode, textual IR, and object/archive inputs, producing BPF code or intermediate output. The main flow accepts inputs and linker options, combines and prepares LLVM modules, optionally sanitizes debug metadata for BTF, then emits the selected output. The graph also includes the LLVM wrapper layer and documented compatibility options. Some orchestration details are unsampled; those links are omitted rather than inferred from module names.

Main entry points: [`src/linker.rs`](https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs) (Linker API), [`src/llvm/types/module.rs`](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/module.rs) (LLVM module), [`src/llvm/mod.rs`](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/mod.rs) (LLVM operations), [`src/llvm/di.rs`](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/di.rs) (BTF sanitization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command line"]
  node_cli["CLI options<br/>[bpf-linker.rs]"]
end

subgraph group_link["Linking pipeline"]
  node_linker["Linker API<br/>[linker.rs]"]
  node_inputs["Input detection<br/>[linker.rs]"]
  node_archive["Archive inputs<br/>[linker.rs]"]
  node_optimization["Module optimization<br/>[mod.rs]"]
  node_output["Linked output<br/>[linker.rs]"]
end

subgraph group_llvm["LLVM interface"]
  node_llvm_engine["LLVM operations<br/>[mod.rs]"]
  node_context["LLVM context<br/>[context.rs]"]
  node_module["LLVM module<br/>[module.rs]"]
  node_buffer["Memory buffers<br/>[memory_buffer.rs]"]
  node_iter["IR iterators<br/>[iter.rs]"]
  node_target["Target machine<br/>[target_machine.rs]"]
  node_ir_values["IR value wrappers<br/>[ir.rs]"]
end

subgraph group_debug["Debug metadata"]
  node_debug["BTF sanitization<br/>[di.rs]"]
  node_debug_types["DI wrappers<br/>[di.rs]"]
  node_debug_builder["DI builder<br/>[di_builder.rs]"]
end

node_user(("Build user"))

node_user -->|"invokes"| node_cli
node_cli -.->|"configures"| node_linker
node_linker -->|"detects"| node_inputs
node_inputs -->|"recognizes"| node_archive
node_linker -->|"uses"| node_llvm_engine
node_llvm_engine -->|"creates"| node_context
node_context -->|"creates"| node_module
node_llvm_engine -->|"links modules"| node_module
node_module -->|"iterates IR"| node_iter
node_llvm_engine -->|"optimizes"| node_optimization
node_linker -->|"sanitizes BTF"| node_debug
node_debug -->|"rewrites metadata"| node_debug_types
node_debug -->|"builds metadata"| node_debug_builder
node_debug -->|"traverses values"| node_ir_values
node_linker -.->|"emits code"| node_target
node_target -->|"emits module"| node_module
node_module -->|"writes bitcode"| node_buffer
node_linker -->|"returns output"| node_output

click node_cli "https://github.com/aya-rs/bpf-linker/blob/main/src/bin/bpf-linker.rs"
click node_linker "https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs"
click node_inputs "https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs"
click node_archive "https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs"
click node_llvm_engine "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/mod.rs"
click node_context "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/context.rs"
click node_module "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/module.rs"
click node_buffer "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/memory_buffer.rs"
click node_iter "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/iter.rs"
click node_target "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/target_machine.rs"
click node_optimization "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/mod.rs"
click node_debug "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/di.rs"
click node_debug_types "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/di.rs"
click node_debug_builder "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/di_builder.rs"
click node_ir_values "https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/ir.rs"
click node_output "https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_user toneBlue
class node_linker,node_inputs,node_archive,node_optimization,node_output toneAmber
class node_llvm_engine,node_context,node_module,node_buffer,node_iter,node_target,node_ir_values toneMint
class node_debug,node_debug_types,node_debug_builder toneRose
```

## Components

### Command line

- [CLI options](https://github.com/aya-rs/bpf-linker/blob/main/src/bin/bpf-linker.rs): `src/bin/bpf-linker.rs`

### Linking pipeline

- [Linker API](https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs): `src/linker.rs`
- [Input detection](https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs): `src/linker.rs`
- [Archive inputs](https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs): `src/linker.rs`
- [Module optimization](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/mod.rs): `src/llvm/mod.rs`
- [Linked output](https://github.com/aya-rs/bpf-linker/blob/main/src/linker.rs): `src/linker.rs`

### LLVM interface

- [LLVM operations](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/mod.rs): `src/llvm/mod.rs`
- [LLVM context](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/context.rs): `src/llvm/types/context.rs`
- [LLVM module](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/module.rs): `src/llvm/types/module.rs`
- [Memory buffers](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/memory_buffer.rs): `src/llvm/types/memory_buffer.rs`
- [IR iterators](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/iter.rs): `src/llvm/iter.rs`
- [Target machine](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/target_machine.rs): `src/llvm/types/target_machine.rs`
- [IR value wrappers](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/ir.rs): `src/llvm/types/ir.rs`

### Debug metadata

- [BTF sanitization](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/di.rs): `src/llvm/di.rs`
- [DI wrappers](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/di.rs): `src/llvm/types/di.rs`
- [DI builder](https://github.com/aya-rs/bpf-linker/blob/main/src/llvm/types/di_builder.rs): `src/llvm/types/di_builder.rs`

### Other components

- **Build user**

## Connections

- Build user → CLI options: invokes (evidence: `README.md`)
- CLI options → Linker API: configures
- Linker API → Input detection: detects (evidence: `src/linker.rs`)
- Input detection → Archive inputs: recognizes (evidence: `src/linker.rs`)
- Linker API → LLVM operations: uses (evidence: `src/linker.rs`)
- LLVM operations → LLVM context: creates (evidence: `src/llvm/types/context.rs`)
- LLVM context → LLVM module: creates (evidence: `src/llvm/types/context.rs`)
- LLVM operations → LLVM module: links modules (evidence: `src/llvm/mod.rs`)
- LLVM module → IR iterators: iterates IR (evidence: `src/llvm/types/module.rs`)
- LLVM operations → Module optimization: optimizes (evidence: `src/llvm/mod.rs`)
- Linker API → BTF sanitization: sanitizes BTF (evidence: `src/linker.rs`)
- BTF sanitization → DI wrappers: rewrites metadata (evidence: `src/llvm/di.rs`)
- BTF sanitization → DI builder: builds metadata (evidence: `src/llvm/di.rs`)
- BTF sanitization → IR value wrappers: traverses values (evidence: `src/llvm/di.rs`)
- Linker API → Target machine: emits code
- Target machine → LLVM module: emits module (evidence: `src/llvm/types/target_machine.rs`)
- LLVM module → Memory buffers: writes bitcode (evidence: `src/llvm/types/module.rs`)
- Linker API → Linked output: returns output (evidence: `src/linker.rs`)
