Skip to content

Conversation

@philipc
Copy link
Contributor

@philipc philipc commented Jan 25, 2026

Replace parts of the transform code with gimli's generic DWARF transformation support. Most of the remaining code is specific to the needs of Wasmtime.

This change relates to #5537. While this PR provides some small improvements, it doesn't fundamentally change the quality of the transformed DWARF. The primary benefit is simply less code in Wasmtime.

The overall behaviour is the same as the previous implementation. We build a graph of the DIE dependencies, and prune DIEs that don't have valid code ranges. Then we traverse the DIE tree again and transform the DIEs. However, there are some differences.

Previously, unresolved references to DIEs were stored in PendingUnitRefs and PendingDebugInfoRefs, then at the end of the transformation we went back and fixed up these references. The new behaviour reserves IDs for all of the DIEs in the dependency tree before transformation, which avoids the need to fix up references later. It also allows gimli to correctly handle references in DWARF expressions, although that doesn't currently matter for Wasmtime because it doesn't handle references in expressions yet. The visible effect of this in Wasmtime is that the order of transformed attributes will now always match the original DWARF.

The DIE tree pruning is slightly different. We no longer add back-edges pointing to namespace DIEs or the root DIE, which previously caused some DIEs to be reachable when they should not have been. In particular, this affects DW_TAG_variable DIEs for global variables. Wasmtime can't currently translate the location for globals, so they were added without a valid DW_AT_location. These DIEs are now omitted from the transformed DWARF. In the future when global variables can be translated correctly, they can be included by calling ReserveUnitSection::require_entry.

Performance measurements for wasmtime compile -D debug-info=y show minimal change.

Replace parts of the transform code with `gimli`'s generic DWARF
transformation support. Most of the remaining code is specific to the
needs of Wasmtime.

The overall behaviour is the same as the previous implementation. We
build a graph of the DIE dependencies, and prune DIEs that don't have
valid code ranges. Then we traverse the DIE tree again and transform the
DIEs. However, there are some differences.

Previously, unresolved references to DIEs were stored in `PendingUnitRefs`
and `PendingDebugInfoRefs`, then at the end of the transformation we
went back and fixed up these references. The new behaviour reserves IDs
for all of the DIEs in the dependency tree before transformation, which
avoids the need to fix up references later. It also allows gimli to
correctly handle references in DWARF expressions, although that doesn't
currently matter for Wasmtime because it doesn't handle references in
expressions yet. The visible effect of this in Wasmtime is that the
order of transformed attributes will now always match the original DWARF.

The DIE tree pruning is slightly different. We no longer add back-edges
pointing to namespace DIEs or the root DIE, which previously caused some
DIEs to be reachable when they should not have been. In particular,
this affects DW_TAG_variable DIEs for global variables. Wasmtime can't
currently translate the location for globals, so they were added without
a valid DW_AT_location. These DIEs are now omitted from the transformed
DWARF. In the future when global variables can be translated correctly,
they can be included by calling `ReserveUnitSection::require_entry`.

Performance measurements for `wasmtime compile -D debug-info=y` show
minimal change.
@philipc philipc requested a review from a team as a code owner January 25, 2026 03:51
@philipc philipc requested review from fitzgen and removed request for a team January 25, 2026 03:51
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

Successfully merging this pull request may close these issues.

1 participant