Skip to content

Emit DWARF 5 location and range lists in NativeAOT - #137212

Merged
MichalStrehovsky merged 3 commits into
dotnet:mainfrom
jbevain:jbevain/dwarf5
Nov 10, 2026
Merged

MichalStrehovsky merged 3 commits into
dotnet:mainfrom
jbevain:jbevain/dwarf5

Conversation

@jbevain

@jbevain jbevain commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

With --gdwarf-5 (IlcDwarfVersion=5), ILC emitted version 5 compile units but kept writing DWARF 4 style .debug_loc and .debug_ranges data. DWARF 5 consumers read DW_AT_location/DW_AT_ranges sec_offsets from .debug_loclists/.debug_rnglists, so llvm-dwarfdump reported errors like "unknown rnglists encoding" and "LLE of kind ... not supported".

For DWARF 5, write location and range lists to .debug_loclists and .debug_rnglists with the list table header, DW_LLE_start_end/ DW_RLE_start_end entries, ULEB128 expression lengths, and DW_LLE_end_of_list/DW_RLE_end_of_list terminators. Map the new sections for Mach-O as well.

Extend the DwarfDump smoke test to dump the loc/range list sections and add a Dwarf5Dump variant that builds the same test with IlcDwarfVersion=5.

With --gdwarf-5 (IlcDwarfVersion=5), ILC emitted version 5 compile units
but kept writing DWARF 4 style .debug_loc and .debug_ranges data.
DWARF 5 consumers read DW_AT_location/DW_AT_ranges sec_offsets from
.debug_loclists/.debug_rnglists, so llvm-dwarfdump reported errors like
"unknown rnglists encoding" and "LLE of kind ... not supported".

For DWARF 5, write location and range lists to .debug_loclists and
.debug_rnglists with the list table header, DW_LLE_start_end/
DW_RLE_start_end entries, ULEB128 expression lengths, and
DW_LLE_end_of_list/DW_RLE_end_of_list terminators. Map the new
sections for Mach-O as well.

Extend the DwarfDump smoke test to dump the loc/range list sections and
add a Dwarf5Dump variant that builds the same test with IlcDwarfVersion=5.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 890faa16-c536-4f7a-a00a-58d472a8fb1b
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 9, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@am11
am11 requested a review from filipnavara November 9, 2026 21:55
@jbevain

jbevain commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Test failure unrelated: System.Numerics.Tensors.Tests.TensorSpanTests.TensorExtensionsSpanInSpanOut.

This has only been validated on Linux with Ubuntu 24.04.2 LTS, x86_64. Will validate on macOS next.

jbevain and others added 2 commits November 9, 2026 15:11
dsymutil rewrites DWARF 5 location and range lists using
DW_LLE_base_addressx/DW_RLE_base_addressx, which index into .debug_addr
via the compile unit's DW_AT_addr_base. dsymutil only emits
DW_AT_addr_base when the input unit has one, so without it the
resulting dSYM had unresolvable base addresses (thousands of
llvm-dwarfdump --verify errors). Emit an empty .debug_addr table and
reference it from the compile unit when generating DWARF 5.

Co-authored-by: Copilot <[email protected]>
When DWARF 5 is enabled, DwarfBuilder writes list table headers and
references .debug_loclists, .debug_rnglists and .debug_addr. Create
those sections in the Wasm object writer instead of always using the
DWARF 4 .debug_loc and .debug_ranges sections.

Co-authored-by: Copilot <[email protected]>
@jbevain

jbevain commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Validated on macOS 27.2.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The DWARF 5 changes need end-to-end validation of Mach-O dsymutil handling of the empty .debug_addr contribution and Wasm linking, since review was source-only and the added smoke tests are Linux-only.

No open issues 🎉

What changed in this PR

This PR updates NativeAOT’s debug-info emission to use DWARF 5 location and range list formats when IlcDwarfVersion=5, while retaining the existing formats for older versions.

Changes:

  • Emit DWARF 5 list headers, entries, expression lengths, terminators, and section references.
  • Wire the new sections into Unix and WebAssembly object writers, add Mach-O mappings, and emit an empty address table.
  • Extend the debug-info smoke test to dump list sections and add a DWARF 5 test variant.
File Description
src/​tests/​nativeaot/​SmokeTests/​DwarfDump/​Program.cs Adds location and range list dumping to the smoke test.
src/​tests/​nativeaot/​SmokeTests/​DwarfDump/​Dwarf5Dump.csproj Adds a Linux smoke-test variant targeting DWARF 5.
src/​coreclr/​tools/​Common/​Compiler/​ObjectWriter/​WasmRelocatableObjectWriter.cs Selects version-appropriate list sections and emits the address table.
src/​coreclr/​tools/​Common/​Compiler/​ObjectWriter/​MachObjectWriter.cs Maps the new debug sections to Mach-O names.
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​ObjectWriter/​UnixObjectWriter.Aot.cs Connects DWARF 5 list and address sections to Unix emission.
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​ObjectWriter/​Dwarf/​DwarfNative.cs Defines DWARF 5 list entry and terminator constants.
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​ObjectWriter/​Dwarf/​DwarfInfoWriter.cs Writes version-specific list encodings and section references.
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​ObjectWriter/​Dwarf/​DwarfBuilder.cs Writes list-table headers, lengths, and an empty address table.
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​ObjectWriter/​Dwarf/​DwarfAbbrev.cs Adds a DWARF 5 compile-unit abbreviation with an address-table base.

Review effort: Balanced

@MichalStrehovsky MichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@MichalStrehovsky
MichalStrehovsky merged commit 35f1ed6 into dotnet:main Nov 10, 2026
107 checks passed
@jbevain
jbevain deleted the jbevain/dwarf5 branch November 10, 2026 02:52
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants