[llvm] [BPF] Define empty set of BPF libcalls (PR #169537)

Michal R via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 01:17:22 PST 2025


vadorovsky wrote:

> > since it would break most rust programs.
> 
> I didn't understand this part. LLVM implementations shouldn't be breaking the verifier. Can you explain why this patch will break Rust programs? Can you also provide an example where that is the case?

LLVM implementation (custom lowering for BPF):

https://github.com/llvm/llvm-project/blob/eb48a61cc17ef6e626a4c4e7c866738225d9870a/llvm/lib/Target/BPF/BPFSelectionDAGInfo.cpp#L27-L45

won't break the verifier, I agree. But it has a limit of 128 bytes:

https://github.com/llvm/llvm-project/blob/eb48a61cc17ef6e626a4c4e7c866738225d9870a/llvm/lib/Target/BPF/BPFSelectionDAGInfo.cpp#L38-L40
https://github.com/llvm/llvm-project/blob/eb48a61cc17ef6e626a4c4e7c866738225d9870a/llvm/lib/Target/BPF/BPFSelectionDAGInfo.h#L34

If we disable libcalls entirely, I think every larger memcpy would result in an error, no?

To clarify about verifier errors - I think what @alessandrod means is that currently, the Rust compiler-builtins' implementations of `memcpy` and `memmove` break the verifier, because they returns a stack pointer `*mut u8`:

https://github.com/rust-lang/compiler-builtins/blob/1574854b08cf2b6a7b3f9ed892dc659812261541/compiler-builtins/src/mem/mod.rs#L14-L31

Here is the kernel code responsible for the verifier error:

https://elixir.bootlin.com/linux/v6.18/source/kernel/bpf/verifier.c#L10981-L10990

Currently, if you compile eBPF code in Rust without providing your implementation of  `memcpy` and `memmove`, compiler-builtis' implementation is going to be used as a libcall, then the verifier will reject the program.

Whether such limitation should exist at all in the kernel is a separate topic - honestly, I think it should be removed. But we should discuss it separately on LKML.

The point is - as a workaround in Aya we provide custom implementation of `memcpy` and `memmove` that does not return anything:

https://github.com/aya-rs/aya/blob/7a3c03e178ced68f63cd1f6cfa3f8fa56459aee9/ebpf/aya-ebpf/src/lib.rs#L75-L99

When we disable libcalls, then compiler-builtins' implementation won't be used, so there should be no verifier error. However, Aya's implementation, unlike custom lowering implementation, has no arbitrary limit - you can copy as much data as the instruction limit in the VM allows you. From my understanding, if we disable libcalls, we might break some programs which rely on large copies.

https://github.com/llvm/llvm-project/pull/169537


More information about the llvm-commits mailing list