The BTF File Format
More than Just Debugging
Arnaldo Carvalho de Melo
acme@redhat.com
Red Hat Inc.
BTF
- BPF Type Format
- Origins on CTF
- Compact C-Type Information
- Sun's dtrace
- DWARF subset
- Always available
- Like CFI/.eh_frame for unwinding
sys_bpf & BTF
- libbpf notices .BTF ELF section
- parses it
- Uses BPF_BTF_LOAD command
- Kernel validates it
- Tools use BPF_OBJ_GET_INFO_BY_FD
Pretty Printing of BPF maps
- Retrieve map's BTF info with BPF_OBJ_GET_INFO_BY_FD
- bpftool
- pretty print each of the elements
Generating BTF info
- DaveM notices CTF in a Solaris kernel image
- Hands me an initial .h with the main definitions
- pahole gets refactored to support multiple formats
- CTF being the first DWARF companion
- 10 years later: BPF needs this
- BTF
- llvm generates it as well, directly
pahole BTF encoder
- dwarf loader
- Reads DWARF tags
- Intermediate format
- BTF encoder uses it
- Inserts a new .BTF ELF section
pahole BTF loader
- Reads BTF tags
- Intermediate format
- pretty prints
btfdiff
- pahole -F btf file.o
- pahole -F dwarf --flat_arrays file.o
- diff the results
- Should produce the same results
- Regression tests
Encoding multiple CUs
- Compile Unit
- Encode just one .BTF section
- For multiple object files
- Like vmlinux
- Bump the IDs of types
- To make them unique
- Deduplicate later
Deduplication
- Done by a Facebook engineer
- Under internal review
- Algorithm described in blog post
- URL in last slide
- Claimed to have 97.6x reduction of BTF type info
- 64.2x overall for types and strings
- Room for improvements
- Reuse .debug_str format
Compile once, run everywhere
- The non-debugging part
- Use BTF in BPF programs
- And the vmlinux .BTF section
- To figure out if ABI changed
- Move operands while loading
- To new offset
- Or refuse loading
- Progress described in Vancouver's LPC
Further reading
- Initial BTF doc patch:
http://https://marc.info/?l=linux-netdev&m=154760035404541
- BTF dedup:
https://facebookmicrosites.github.io/bpf/blog/2018/11/14/btf-enhancement.html