Skip to content

[Feature] Inspect Linux BTF type and function metadata offline #2369

Open

Description

@matbrgz

Type: Feature Domain: Reverse Engineering Status: Proposed Ecosystem: REA

Requested capability

The current contracts have no declared Linux BTF/BTF.ext inspection profile. The published BTF format contains type graphs, function metadata and line information that ordinary ELF section inventory does not decode. Issue #2003 targets Solana sBPF and does not provide a Linux BTF contract.

Acceptance criteria

  • Accept caller-selected BTF bytes or an explicitly identified ELF section and preserve original hash/source ranges.
  • Specify supported BTF versions, byte order, type kinds and BTF.ext function/line/relocation records.
  • Retain unknown kinds and unresolved references explicitly; bound strings, type references, records and graph traversal.
  • Verify original fixtures through CLI/MCP; do not load programs, attach probes, access live kernel state or invoke a verifier.

References and boundaries

This feature needs its own docs/specs//spec.md, plan.md and tasks.md before code. Current upstream sources and existing issues were searched before filing. A new REA provider or expanded execution authority requires the maintainer scope decision specified by CONTRIBUTING.md; this proposal does not supply that decision.

Activity

  1. added
    enhancement
    area: native
    triage
    P3: low
    and removed
    triage
    on Oct 12, 2026
  2. matbrgz commented on Oct 12, 2026

    @matbrgz
    ContributorAuthor

    Implementation & Scope Notes

    Objective (ELI5):
    Parse BPF Type Format (BTF) data from Linux binaries and kernel modules offline, extracting struct definitions, types, and function prototypes.

    Key Requirements:

    • Pure TypeScript parser for the .BTF ELF section and standalone BTF files (/sys/kernel/btf/vmlinux).
    • Decode kind tags (BTF_KIND_STRUCT, BTF_KIND_UNION, BTF_KIND_FUNC, BTF_KIND_FUNC_PROTO) into typed domain structures.
  3. zaid646 commented on Oct 28, 2026

    @zaid646

    Quick scope proposal before I write code.

    I'd like to take this as inspect_btf / inspect-btf, a static reader in the same lane as inspect_kernel_module and inspect_elf_notes.

    First slice: one absolute path, either a standalone BTF blob (/sys/kernel/btf/* or a saved copy) or an ELF/.ko carrying .BTF. .BTF.ext is read when present. .BTF.base / split-BTF presence is reported, and base references stay unresolved — no relocation.

    Result: byte order, version, flags and header lengths; section ranges with SHA-256; string-table statistics; a paged type inventory by 1-based id with the exact kind-specific facts (members and bitfields, params, enum/enum64, arrays, vars/datasecs, decl/type tags); a one-level named reference summary for the types used by the returned page; .BTF.ext func/line/CO-RE records grouped by ELF section, paged per section; explicit unknowns for unknown kinds, out-of-range string offsets, and truncated or overlapping ranges.

    Effects: reads one selected file only. No BPF program load, no attach, no verifier, no live kernel or /sys access, no network, no writes.

    Verification: owned fixtures compiled from a small C source with clang -target bpf -g (source and generator checked in), plus synthetic big-endian, unknown-kind, truncated and malformed fixtures; CLI and MCP boundary coverage; one real vmlinux .BTF run recorded as evidence and not committed.

    Deferred: .BTF.base relocation, .BTF_ids, pretty-printing the type graph, BTF generation.

    Two format details worth pinning:

    • The kernel docs describe info as vlen bits 0–23 / kind 24–30, while include/uapi/linux/btf.h and libbpf decode vlen as 16 bits, kind as 5 bits at 24–28 and bit 31 as kind_flag. I plan to follow the header macros and record the discrepancy rather than silently pick one.
    • The .BTF.ext header's core-relo fields are optional (hdr_len 24 vs 32), so both are admitted.

    Is that slice in scope, and is inspect_btf the name you want? I'll put spec/plan/tasks/verification under docs/specs/btf-inspection/ before the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3: lowarea: nativeenhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions