LLVM improvements for BPF verification

Alan Jowett gave a remote presentation at the 2024 Linux Storage, Filesystem, Memory Management, and BPF Summit about what features could be added to LLVM to make writing BPF programs easier. While there is nothing specific to LLVM about BPF code (and the next session in the track was led by GCC developer José Marchesi about better support for that compiler), LLVM is currently the most common way to turn C code into BPF bytecode. That translation, however, runs into problems when the BPF verifier cannot understand the code LLVM's optimizations produce.

Alan Jowett 在 2024 年 Linux 存储、文件系统、内存管理和 BPF 峰会上进行了远程演讲,讨论了可以为 LLVM 添加哪些功能以简化 BPF 程序的编写。虽然 BPF 代码本身与 LLVM 没有直接关系(同一议题中的下一场由 GCC 开发者 José Marchesi 主持,讨论如何改进对 GCC 的支持),但 LLVM 目前是将 C 代码编译为 BPF 字节码最常用的方式。然而,这一转换过程在 BPF 校验器无法理解 LLVM 优化生成的代码时会遇到问题。

Jowett began by talking about how LLVM processes code internally. First, the C code is translated to LLVM intermediate representation (IR). Then, several passes of optimizations gradually turn the IR into a more efficient version. Finally, the code generator creates BPF bytecode corresponding to the IR. The problem with this process is that LLVM has had many years to develop sophisticated optimizations. It is not uncommon, Jowett said, for LLVM to produce code that is correct, but that the BPF verifier cannot understand — a problem LWN has covered before. For that reason, developers sometimes have to use inline BPF assembly to circumvent the optimizer in order to have their programs accepted.

Jowett 首先介绍了 LLVM 内部是如何处理代码的。首先,C 代码会被翻译为 LLVM 的中间表示(IR)。然后,经过若干轮优化,这些 IR 会被逐步转化为更高效的形式。最终,代码生成器根据 IR 生成对应的 BPF 字节码。问题在于 LLVM 多年来积累了大量复杂的优化机制。Jowett 表示,LLVM 经常会生成语义上正确但 BPF 校验器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mounter625

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值