Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf-linker core dump running pass 'BPF DAG->DAG Pattern Instruction Selection' #210

Open
l2dy opened this issue Jul 18, 2024 · 2 comments
Open

Comments

@l2dy
Copy link

l2dy commented Jul 18, 2024

cargo xtask build of this program crashes.

#![no_std]
#![no_main]

use aya_ebpf::{
    bindings::xdp_action,
    helpers::bpf_ktime_get_ns,
    macros::{map, xdp},
    maps::LruHashMap,
    programs::XdpContext,
};
use aya_log_ebpf::error;

#[map]
static START: LruHashMap<u32, u64> = LruHashMap::with_max_entries(1 << 10, 0);

#[xdp]
pub fn aya_crash_repro(ctx: XdpContext) -> u32 {
    match try_aya_crash_repro(ctx) {
        Ok(ret) => ret,
        Err(_) => xdp_action::XDP_ABORTED,
    }
}

fn try_aya_crash_repro(ctx: XdpContext) -> Result<u32, u32> {
    let ts = unsafe { bpf_ktime_get_ns() };
    let bucket = 0u32;
    if let Some(start_ts) = unsafe { START.get(&bucket) } {
        let latency = ts - start_ts;
        let bucket_index = latency.ilog2();
        error!(&ctx, "{}", bucket_index);
    }
    Ok(xdp_action::XDP_PASS)
}

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    unsafe { core::hint::unreachable_unchecked() }
}

The output is

error: linking with `bpf-linker` failed: signal: 6 (SIGABRT) (core dumped)
  |
  = note: LC_ALL="C" PATH="/home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/l2dy/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/work/opshell/" VSLANG="1033" "bpf-linker" "--export-symbols" "/tmp/rustcBw2itW/symbols" "/tmp/rustcBw2itW/symbols.o" "/home/l2dy/aya/aya-crash-repro-ebpf/../target/bpfel-unknown-none/debug/deps/aya_crash_repro-0886bd8e8675c312.aya_crash_repro.fc631aa60ebb484-cgu.0.rcgu.o" "-L" "/home/l2dy/aya/aya-crash-repro-ebpf/../target/bpfel-unknown-none/debug/deps" "-L" "/home/l2dy/aya/aya-crash-repro-ebpf/../target/debug/deps" "-L" "/home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/bpfel-unknown-none/lib" "--cpu" "generic" "-L" "/home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/bpfel-unknown-none/lib" "-o" "/home/l2dy/aya/aya-crash-repro-ebpf/../target/bpfel-unknown-none/debug/deps/aya_crash_repro-0886bd8e8675c312" "-O3" "--debug"
  = note: unable to open LLVM shared lib /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-18-rust-1.81.0-nightly.so: /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-18-rust-1.81.0-nightly.so: file too short
          PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
          Stack dump:
          0.    Running pass 'Function Pass Manager' on module 'aya_crash_repro-0886bd8e8675c312'.
          1.    Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@aya_crash_repro'

and the crash backtrace is

(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007fd697d80fb3 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007fd697d34d96 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007fd697d2026d in __GI_abort () at abort.c:100
#4  0x00007fd693fe79d8 in llvm::report_fatal_error(llvm::Twine const&, bool) () from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#5  0x00007fd69528297e in llvm::BPFTargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&) const ()
   from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#6  0x00007fd69629d739 in (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) [clone .llvm.10772212417860934100] ()
   from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#7  0x00007fd69629ba37 in llvm::SelectionDAGISel::CodeGenAndEmitDAG() () from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#8  0x00007fd6962e8b2e in llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) ()
   from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#9  0x00007fd6963f67ce in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) ()
   from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#10 0x00007fd6962609d4 in llvm::FPPassManager::runOnFunction(llvm::Function&) () from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#11 0x00007fd69625fe45 in llvm::FPPassManager::runOnModule(llvm::Module&) () from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#12 0x00007fd69681fa60 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#13 0x00007fd694e93492 in LLVMTargetMachineEmit(LLVMOpaqueTargetMachine*, LLVMOpaqueModule*, llvm::raw_pwrite_stream&, LLVMCodeGenFileType, char**) ()
   from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#14 0x00007fd694e93397 in LLVMTargetMachineEmitToFile () from /home/l2dy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.81.0-nightly
#15 0x000055e3fd25eac1 in bpf_linker::llvm::codegen::{closure#0} () at src/llvm/mod.rs:302
#16 bpf_linker::llvm::Message::with<i32, bpf_linker::llvm::codegen::{closure_env#0}> () at src/llvm/mod.rs:350
#17 bpf_linker::llvm::codegen (tm=0x3f81, module=0x3f81, output=..., output_type=llvm_sys::target_machine::LLVMCodeGenFileType::LLVMAssemblyFile) at src/llvm/mod.rs:301
#18 0x000055e3fd2578b1 in bpf_linker::linker::Linker::emit (self=0x7ffd4fcabb90, output=..., output_type=llvm_sys::target_machine::LLVMCodeGenFileType::LLVMObjectFile) at src/linker.rs:505
#19 0x000055e3fd2578b1 in bpf_linker::linker::Linker::codegen (self=0x7ffd4fcabb90)
#20 bpf_linker::linker::Linker::link (self=0x7ffd4fcabb90) at src/linker.rs:268
#21 0x000055e3fd113815 in bpf_linker::main () at src/bin/bpf-linker.rs:285
@fslongjin
Copy link

fslongjin commented Jul 31, 2024

I met the same problem too.

may be we cannot use ilog2 or leading_zeros

@l2dy
Copy link
Author

l2dy commented Jul 31, 2024

I was able to workaround this issue by building bpf-linker against the latest LLVM.

Here is the patch I used on nixpkgs to install a working bpf-linker.

diff --git a/pkgs/development/tools/bpf-linker/default.nix b/pkgs/development/tools/bpf-linker/default.nix
index a9a6fed278685e8..dac83b645b0cd63 100644
--- a/pkgs/development/tools/bpf-linker/default.nix
+++ b/pkgs/development/tools/bpf-linker/default.nix
@@ -2,7 +2,7 @@
 , stdenv
 , rustPlatform
 , fetchFromGitHub
-, llvmPackages_18
+, llvmPackages_git
 , zlib
 , ncurses
 , libxml2
@@ -28,7 +28,7 @@ rustPlatform.buildRustPackage rec {
 
   buildNoDefaultFeatures = true;
 
-  nativeBuildInputs = [ llvmPackages_18.llvm ];
+  nativeBuildInputs = [ llvmPackages_git.llvm ];
   buildInputs = [ zlib ncurses libxml2 ];
 
   # fails with: couldn't find crate `core` with expected target triple bpfel-unknown-none

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants