From: Alan Maguire <alan.maguire@oracle.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
Clark Williams <williams@redhat.com>,
dwarves@vger.kernel.org, bpf@vger.kernel.org,
Andrii Nakryiko <andrii@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Mark Wieelard <mjw@redhat.com>
Subject: Re: [PATCHES 00/12] pahole: Support more rust tags and references to dwz alternate debug files
Date: Fri, 7 Aug 2026 09:09:16 +0100 [thread overview]
Message-ID: <18b557a8-e1ca-46cf-b03f-5e68490c9229@oracle.com> (raw)
In-Reply-To: <20260731193102.110693-1-acme@kernel.org>
On 31/07/2026 20:30, Arnaldo Carvalho de Melo wrote:
> Hi,
>
> Add support for Rust discriminated unions (enums with explicit
> discriminants).
>
> Rust enums like Option<u32> and Result<i32,u8> are represented in DWARF
> as DW_TAG_variant_part containing DW_TAG_variant children with
> discriminant values. These patches:
>
> - Load DW_TAG_variant_part containers with discriminant tracking
> - Populate DW_TAG_variant children with discriminant values
> - Handle DW_FORM_block encoding for discriminant values
> - Handle DW_TAG_subprogram inside DW_TAG_enumeration (Rust methods)
> - Encode variant parts as BTF_KIND_UNION members
>
> Before: Rust Option<u32> showed as empty struct (0 members)
>
> After: Shows None and Some variants with correct layout
>
> === pahole --expand_types output ===
> struct Option<u32> {
> struct None {
> } __attribute__((__aligned__(4)));
> struct Some {
> /* XXX 4 bytes hole, try to pack */
> u32 __0 __attribute__((__aligned__(4))); /* 4 4 */
> } __attribute__((__aligned__(4)));
> } __attribute__((__aligned__(4)));
>
> BTF has no discriminated-union kind, so variant parts are tentatively
> encoded as BTF_KIND_UNION with overlapping members at offset 0. Further
> discussion is needed to see if we can keep that.
>
It seems like these variants mostly have a leading discriminating
value (telling us which variant is selected), and it looks like it is
possible to infer its presence by determining by its members if it has
that discriminant (do any members have niche layout? if not it is there)
and its size (depends on the number of variants). Given that, would
it make sense to have a discriminant too? It seems that the above
example Option<u32> has one, so we'd have
struct Option<u32> {
uint8_t tag; // 1 byte: Explicit discriminant
uint8_t pad[3];
struct Some {
...
This would give us a better match for the in-memory representation.
What do you think, is it doable?
> DW_FORM_block byte order fix: uses CU-recorded endianness instead of
> assuming little-endian when decoding DW_AT_const_value and
> DW_AT_default_value. Fixes cross-endian DWARF processing (e.g. reading
> big-endian s390x debug info on x86).
>
> Also add support for cross-CU type references and dwz alternate debug
> files.
>
> This is needed to improve the support for, among other things, Rust, as
> noticed in the pretty printing or a perf binary that has rust objects
> linked, built by clang/llvm that use cross-CU references.
>
> DW_TAG_imported_unit support:
>
> Handle same-file partial units where types are shared across CUs
> via DW_TAG_imported_unit. Force-merge CUs that contain inter-CU
> references (DW_FORM_ref_addr) so type lookups resolve correctly.
>
> Fix cus__merging_cu failing to detect DW_FORM_ref_addr when
> DW_FORM_implicit_const causes dwarf_getabbrevattr() to fail.
>
> dwz alternate debug file support:
>
> Handle DW_FORM_GNU_ref_alt references to dwz-compressed alternate
> debug files (.dwz). Pre-processes all alternate partial units with
> separate hash tables and dedup tracking.
>
> Before (Firefox): 1774 "has no entry in cu" errors
> After: processes cleanly with 0 errors
>
> Firefox uses dwz compression which moves common types into a
> separate .dwz file and replaces duplicates with DW_FORM_GNU_ref_alt
> references. pahole now pre-loads the alternate file's partial units,
> resolves all cross-file references, and processes Firefox DWARF
> cleanly.
>
> Includes inter-CU type reference comparison test and
> vmlinux_comparison.py for DWARF/BTF analysis across kernel configs.
>
> Known limitations:
> - Pruning of unreferenced alt PUs is conservatively over-approximated
> - Merged-CU path is single-threaded by design
>
> This makes pahole to be able to support more of the CONFIG_DEBUG_ DWARF
> options, including DWARF5 and compression, see the latest patch in the
> series for more details about how this table is produced:
>
> ┌───────────────────────────┬─────────┬─────┬───────────────────────────────────┬─────────┬───────┬──────────┬────────┬──────────┬─────────┐
> │ File │ Size │ Ver │ Producer │ DWARF │ BTF │ DW-Hash │ DW-Out │ BTF-Hash │ BTF-Out │
> ├───────────────────────────┼─────────┼─────┼───────────────────────────────────┼─────────┼───────┼──────────┼────────┼──────────┼─────────┤
> │ vmlinux.dwarf4 │ 835.7MB │ 4 │ GNU C11 16.1.1 -gdwarf-4 │ 599.2MB │ 7.3MB │ 86e1b611 │ 7.6MB │ 52123c24 │ 7.4MB │
> │ vmlinux.dwarf5 │ 736.3MB │ 5 │ GNU C11 16.1.1 -gdwarf-5 │ 499.7MB │ 7.3MB │ 86e1b611 │ 7.6MB │ 52123c24 │ 7.4MB │
> │ vmlinux.dwarf5.zlib │ 497.8MB │ 5 │ GNU C11 16.1.1 -gdwarf-5 -gz=zlib │ 261.2MB │ 7.3MB │ 86e1b611 │ 7.6MB │ 52123c24 │ 7.4MB │
> │ vmlinux.dwarf5.zstd │ 454.7MB │ 5 │ GNU C11 16.1.1 -gdwarf-5 -gz=zstd │ 218.1MB │ 7.3MB │ 86e1b611 │ 7.6MB │ 52123c24 │ 7.4MB │
> │ vmlinux.toolchain_default │ 736.3MB │ 5 │ GNU C11 16.1.1 │ 499.7MB │ 7.3MB │ 86e1b611 │ 7.6MB │ 52123c24 │ 7.4MB │
> └───────────────────────────┴─────────┴─────┴───────────────────────────────────┴─────────┴───────┴──────────┴────────┴──────────┴─────────┘
>
> Split DWARF support (skeleton CUs) will be supported in upcoming work,
> so as to cover all the possibilities the kernel build system offers
> for generating DWARF.
>
> - Arnaldo
>
> Arnaldo Carvalho de Melo (12):
> dwarf_loader: Initial support for DW_TAG_variant_part
> dwarf_loader: Initial support for DW_TAG_subprogram in DW_TAG_enumeration
> dwarf_loader: Populate DW_TAG_variant children in DW_TAG_variant_part
> btf_encoder: Encode variant parts as union members in BTF
> dwarf_loader: Handle DW_FORM_block in attr_numeric for Rust discriminant values
> dwarf_loader: Allow forcing the merge of CUs for solving inter CU tag references
> dwarf_loader: Support DW_TAG_imported_unit for same-file partial units
> dwarf_loader: Fix cus__merging_cu failing to detect DW_FORM_ref_addr
> dwarf_loader: Add cu parameter to tag__set_spec() and dwarf_tag__set_attr_type()
> dwarf_loader: Support DW_FORM_GNU_ref_alt references to dwz alternate debug files
> tests: Add inter-CU type reference comparison test
> scripts: Add vmlinux_comparison.py for DWARF/BTF analysis
>
> btf_encoder.c | 66 ++-
> ctf_encoder.c | 34 +-
> dwarf_loader.c | 873 ++++++++++++++++++++++++++++++----
> dwarves.c | 77 ++-
> dwarves.h | 63 ++-
> dwarves_emit.c | 10 +-
> dwarves_fprintf.c | 54 ++-
> man-pages/pahole.1 | 18 +-
> pahole.c | 20 +-
> scripts/vmlinux_comparison.py | 367 ++++++++++++++
> tests/block_endian.sh | 146 ++++++
> tests/dwz_alt_file.sh | 204 ++++++++
> tests/inter_cu_refs.sh | 50 ++
> tests/prettify_perf.data.sh | 4 +-
> 14 files changed, 1854 insertions(+), 132 deletions(-)
> create mode 100755 scripts/vmlinux_comparison.py
> create mode 100755 tests/block_endian.sh
> create mode 100755 tests/dwz_alt_file.sh
> create mode 100755 tests/inter_cu_refs.sh
>
next prev parent reply other threads:[~2026-08-07 8:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 19:30 [PATCHES 00/12] pahole: Support more rust tags and references to dwz alternate debug files Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 01/12] dwarf_loader: Initial support for DW_TAG_variant_part Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 02/12] dwarf_loader: Initial support for DW_TAG_subprogram in DW_TAG_enumeration Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 03/12] dwarf_loader: Populate DW_TAG_variant children in DW_TAG_variant_part Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 04/12] btf_encoder: Encode variant parts as union members in BTF Arnaldo Carvalho de Melo
2026-08-11 0:29 ` Yonghong Song
2026-07-31 19:30 ` [PATCH 05/12] dwarf_loader: Handle DW_FORM_block in attr_numeric for Rust discriminant values Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 06/12] dwarf_loader: Allow forcing the merge of CUs for solving inter CU tag references Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 07/12] dwarf_loader: Support DW_TAG_imported_unit for same-file partial units Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 08/12] dwarf_loader: Fix cus__merging_cu failing to detect DW_FORM_ref_addr Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 09/12] dwarf_loader: Add cu parameter to tag__set_spec() and dwarf_tag__set_attr_type() Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 10/12] dwarf_loader: Support DW_FORM_GNU_ref_alt references to dwz alternate debug files Arnaldo Carvalho de Melo
2026-07-31 19:30 ` [PATCH 11/12] tests: Add inter-CU type reference comparison test Arnaldo Carvalho de Melo
2026-07-31 19:31 ` [PATCH 12/12] scripts: Add vmlinux_comparison.py for DWARF/BTF analysis Arnaldo Carvalho de Melo
2026-08-07 8:09 ` Alan Maguire [this message]
2026-08-07 12:43 ` [PATCHES 00/12] pahole: Support more rust tags and references to dwz alternate debug files Arnaldo Carvalho de Melo
2026-08-07 17:34 ` Miguel Ojeda
2026-08-07 18:53 ` Arnaldo Carvalho de Melo
2026-08-07 19:26 ` Gary Guo
2026-08-07 20:30 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18b557a8-e1ca-46cf-b03f-5e68490c9229@oracle.com \
--to=alan.maguire@oracle.com \
--cc=acme@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=mjw@redhat.com \
--cc=williams@redhat.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.