From a41395a165542010812fee708c3ee4b28c6758e6 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Sat, 19 Apr 2025 22:38:59 +1000 Subject: [PATCH] feat(eBPF): embed BTF information in eBPF kernel (#8842) It turns out that the Rust compiler doesn't always say that it is adding debug information to a binary even when it does! The build output only displays `[optimized]` when in fact it does actually emit debug information. Adding an additional linker flag configures `bpf-linker` to include the necessary BTF information in our kernel. This makes debugging verifier errors much easier as the program output contains source code annotiations. It also should make it easier to debug issues using `xdpdump` which relies on BTF information. Resolves: #8503 --- rust/Cargo.toml | 3 +++ rust/relay/ebpf-turn-router/build.rs | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 33fa8ee18..7427ba1b2 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -234,3 +234,6 @@ split-debuginfo = "packed" [profile.release.package.firezone-gui-client] debug = "full" split-debuginfo = "packed" + +[profile.release.package.ebpf-turn-router] +debug = 2 diff --git a/rust/relay/ebpf-turn-router/build.rs b/rust/relay/ebpf-turn-router/build.rs index 3655e0aba..b25dbd27e 100644 --- a/rust/relay/ebpf-turn-router/build.rs +++ b/rust/relay/ebpf-turn-router/build.rs @@ -14,4 +14,11 @@ use which::which; fn main() { let bpf_linker = which("bpf-linker").expect("bpf-linker not found in $PATH"); println!("cargo:rerun-if-changed={}", bpf_linker.to_str().unwrap()); + + if std::env::var("CARGO_BUILD_TARGET") + .ok() + .is_some_and(|t| t == "bpfel-unknown-none" || t == "bpfeb-unknown-unknown") + { + println!("cargo:rustc-link-arg=--btf"); + } }