Pahole gains Rust enum DWARF support and dwz alternate debug handling
Arnaldo Carvalho de Melo’s series stops Rust Option and Result types from collapsing to empty BTF structs and unblocks type loading on dwz-compressed debuginfo.
Pahole can now load Rust discriminated unions from DWARF and emit them into BTF, fixing a long-standing gap that left types such as Option and Result looking like empty structs. Arnaldo Carvalho de Melo posted the work on the BPF list, along with support for dwz alternate debug files and cross-compilation-unit type references that modern Rust and distro debuginfo routinely produce.
Rust enums with explicit discriminants show up in DWARF as variant_part containers with variant children. Previously pahole dropped that structure, so BTF consumers saw zero-member structs. The new path tracks discriminants (including block-encoded 128-bit values), keeps methods nested under enumerations, and encodes each variant as an overlapping BTF union member at offset zero. On a real async Rust binary, more than 22,000 types that had been empty structs became proper unions with named variants such as None and Some.
BTF still has no discriminated-union kind, so the union encoding is provisional. Alan Maguire asked whether pahole should also surface an explicit discriminant field to match in-memory layout. Miguel Ojeda and others cautioned against inferring niche layouts from member shapes: rustc’s default representation is unstable, and reverse-engineering it would break silently across compiler releases. The next step is mapping loaded DWARF more carefully onto existing BTF kinds and proposing extensions only where that is impossible.
The same series fixes two practical blockers for tools that already ship Rust. Parallel DWARF loading could not resolve inter-CU references used by Rust objects linked into perf; detection of those references was also broken when DWARF5 implicit_const abbreviations appeared early in a file. Pahole now forces the merged-CU path when needed so pretty-printing and BTF encoding see complete types. Separately, binaries processed by dwz (the common case for Fedora and RHEL debuginfo packages, and for some Rust-heavy packages such as Chromium) no longer lose partial units or alternate-file references; pahole follows imported units, maintains a separate offset space for .gnu_debugaltlink data, and warns clearly when the matching debuginfo package is missing.
Cross-endian DW_FORM_block decoding was corrected as well, so big-endian debug info is read correctly on little-endian hosts. Together the changes move pahole from “Rust types mostly missing” to “Rust types loaded and roughly representable,” which matters for BTF-based tracing and for anyone inspecting kernels or userspace that mix C and Rust.