Format:BTF (BPF Type Format)
| On this wiki | Facts · Code · Notes · Topics |
|---|
Compact type-information format of the Linux kernel and eBPF: a .BTF section (and /sys/kernel/btf/vmlinux) starting with the 16-bit magic 0xEB9F, a header with type and string sections, and 20 type kinds (int, ptr, struct, enum, func, datasec) described by a 12-byte btf_type.
Identification
- Magic
0xEB9Fas a 16-bit value in the file's byte order: bytes9F EBin little-endian files,EB 9Fin big-endian. Version byte 1. Fact:BTF (BPF Type Format)/magic/BTF magic. - Lives in the ELF section
.BTFof vmlinux, kernel modules (Format:Linux kernel module (.ko)) and BPF object files; the running kernel exposes it raw in/sys/kernel/btf/vmlinux(modules:/sys/kernel/btf/<module>). - Companion sections:
.BTF.ext(func_info, line_info, CO-RE relocations of BPF objects),.BTF_ids(BTF ID lists and sets used inside the kernel),.BTF.base(minimal base types so split BTF of a module survives a rebuilt base).
Header
Fact:BTF (BPF Type Format)/struct/btf header. Read hdr_len instead of assuming a header size. type_off and str_off count from the end of the header.
Types
Types are numbered from 1 in section order (id 0 is void). Each starts with a 12-byte btf_type (Fact:BTF (BPF Type Format)/struct/btf type) followed by vlen kind-specific entries. Names are offsets into the string section (offset 0 is the empty string). Kinds: Fact:BTF (BPF Type Format)/enum/BTF kinds.
Use in reverse engineering
- A kernel built with CONFIG_DEBUG_INFO_BTF carries full struct layouts (field names, byte and bit offsets) without DWARF; dump with
bpftool btf dump file /sys/kernel/btf/vmlinuxor parse the section. - Function prototypes:
BTF_KIND_FUNCpoints to aFUNC_PROTO. Global variables:VARentries listed by aDATASEC(one per ELF section, with offset and size of each variable).
Code & repositories
- https://github.com/torvalds/linux @
32c52ec87d6245ee2d12ed5dd509e40062939b50· license: GPL-2.0 WITH Linux-syscall-note (read from COPYING; GitHub's detector did not classify it)
Linux kernel sources (GPL-2.0): Documentation/arch/x86/boot.rst, include/uapi/linux/btf.h, include/linux/module.h, vermagic.h, export.h, scripts/kallsyms.c, scripts/mod/modpost.c, scripts/extract-vmlinux
Tested on: source read, not run: not run; source read at the pinned commit · checked 2026-10-18; last activity 2026-10-18
Pitfalls
- New kinds appeared over time (
FLOAT16,DECL_TAG17,TYPE_TAG18,ENUM6419); a parser must size unknown kinds or fail clearly. - For struct/union with kind_flag set, a member's
offsetpacks the bitfield size in the top 8 bits and the bit offset in the low 24.
Sources: Documentation/bpf/btf.rst, include/uapi/linux/btf.h. See Platform:Linux kernel.