详细介绍:Next steps for BPF support in the GNU toolchain
Support for BPF in the kernel has been tied to the LLVM toolchain since the advent of extended BPF. There has been a growing effort to add BPF support to the GNU toolchain as well, though. At the 2025 GNU Tools Cauldron, the developers involved got together with representatives of the kernel community to talk about the state of that work and what needs to happen next.
自从扩展 BPF 出现以来,内核对 BPF 的支持一直与 LLVM 器具链绑定。不过,近年来也有越来越多的努力在为 GNU 工具链添加 BPF 支撑。在 2025 年的 GNU Tools Cauldron 大会上,相关开发者与内核社区的代表聚在一起,讨论了这项工作的当前进展以及下一步需要完成的事项。
Integrating BTF and CTF
The BPF type format (BTF) represents the types of kernel data structures and functions; it is used to enable BPF programs to run on multiple kernels, and by the verifier to ensure program correctness, among other uses. It is derived from the Compact C Type Format (CTF), which is a more general-purpose format that makes debugging information available for compiled programs. Nick Alcock gave a high-speed presentation of his work to reunify those two formats.
BPF 类型格式(BTF)用于表示内核数据结构和函数的类型;它的用途包括让 BPF 代码能够在多个内核上运行,并为验证器提供类型信息以确保程序的正确性。BTF 派生自更通用的紧凑 C 类型格式(CTF),后者首要用于为已编译程序给予调试信息。Nick Alcock 在会上进行了一个节奏很快的报告,介绍了他正在进行的将这两种格式重新统一的工作。
The libctf library, which works with CTF, is now able to both produce and consume BTF, he began. It can also work with an under-development "CTFv4" format that adds support for some of the trickier cases. This work is being tied into the kernel build, which would allow the creation of BTF directly when building the kernel, rather than as a separate step using the pahole utility as is done now.
他介绍说,用于处理 CTF 的 libctf 库现在已经能够生成和读取 BTF 数据。它还可以与正在开发中的 “CTFv4” 格式协同工作,该格式为一些较复杂的情况增加了承受。这项工作正在与内核构建过程集成,从而可以在构建内核时直接生成 BTF,而不再需要像现在那样在编译后使用 pahole 工具作为独立步骤来生成。
There are a couple of enhancements that are needed before BTF can completely replace CTF beyond the kernel, though. A string header field is needed to be able to separate the BTF from each translation unit when the results are all combined. Some sort of agreement on a format for referring to structure members in archives (holding BTF data for multiple translation units) is required for compaction purposes. To be able to use this format in user space, there has to be a representation for floating-point data — a feature the kernel has never needed. With those in place, the extra capabilities provided by CTF would only be needed to represent huge structures (rather larger than would ever make sense in the kernel) and conflicting types with the same name. Then, GCC could create BTF for both kernel and user space, with the toolchain performing
浙公网安备 33010602011771号