Skip to content

BPF target build failure on latest rust #155580

Description

@pineapplehunter

I found that the latest Rust compiler can not produce a BPF binary
I have bisected the nightly builds and found that the regression occurs between these commits.

e96bb7e..de6d33c

Looking at the LLVM version, it seems to have been introduced with the update to LLVM 22.

I am not familiar enough with the codebase to debug it, but I did not see any reporting on this issue, so I am posting it here.

Code

Create a new cargo project and write the code below to src/main.rs

#![no_std]
#![no_main]

#[unsafe(no_mangle)]
pub extern "C" fn foo() {}

#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
    loop {}
}

Compile it with the below command

$ cargo build --target bpfel-unknown-none -Zbuild-std

I expected to see this happen: Successfully compiles

Instead, this happened: Fails to compile with an error

$ cargo build --target bpfel-unknown-none -Zbuild-std
   Compiling compiler_builtins v0.1.160 (...)
   Compiling core v0.0.0 (...)
   Compiling sample-bpf-rust v0.1.0 (...)
error: linking with `bpf-linker` failed: exit status: 1
  |
  = note:  "bpf-linker" "--export-symbols" ".../target/bpfel-unknown-none/debug/deps/rustcGmK5MN/symbols" ".../target/bpfel-unknown-none/debug/deps/rustcGmK5MN/symbols.o" "<1 object files omitted>" ".../target/bpfel-unknown-none/debug/deps/{libcore-14f6f9bfa850cc98,libcompiler_builtins-447d8cec32abd3bb}.rlib" "-L" ".../target/bpfel-unknown-none/debug/deps/rustcGmK5MN/raw-dylibs" "--cpu" "generic" "-o" ".../target/bpfel-unknown-none/debug/deps/sample_bpf_rust-941d8611665955c2" "-O0" "--debug"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: ERROR llvm: Invalid record
          Error: failure linking module .../target/bpfel-unknown-none/debug/deps/sample_bpf_rust-941d8611665955c2.72ulv28v6rhi4ams0w0iegf04.18s161b.rcgu.o

(project directory and a few other directories are replaced with ...)

Version it worked on

It most recently worked on: 1.95.0-nightly (e96bb7e 2026-01-27)

rustc 1.95.0-nightly (e96bb7e44 2026-01-27)
binary: rustc
commit-hash: e96bb7e44fbcc23c1e6009e8d0ee8ab208668fb4
commit-date: 2026-01-27
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8

Version with regression

rustc --version --verbose:

rustc 1.95.0-nightly (de6d33c03 2026-01-28)
binary: rustc
commit-hash: de6d33c033441c5880b863f94d7a3ec8cad141bd
commit-date: 2026-01-28
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0

Backtrace

The compiler does not crash.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions