Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Dec 5, 2025

Fixes #121093 (because I needed more precise tracking of what gets stack trace data)
Fixes #103156 (because I needed to change how we stringify anyway)
Fixes #68714 (the thing I wanted to fix when I started)

  • Embeds line number data into executable (avoids having to carry PDB/DWO/DSYM, and writing parsers for those)
  • The data is emitted into a separate hashtable that hashes two different things based on the source of the stack trace data (we carry method stack trace data in reflection metadata and in dedicated stack trace data; for methods that are not targets of reflection). This requires using two mechanisms to do lookups. As to why we use these mechanisms for lookups instead of code addresses: we cannot do hashtables based on code addresses, this would require complex object writer coordination.

Cc @dotnet/ilc-contrib

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for embedding line number information into native AOT applications, allowing stack traces to include file names and line numbers without requiring separate debug symbol files (PDB/DWO/DSYM). The implementation uses hashtables to map methods to their line number data, with two different lookup mechanisms: one for methods with dedicated stack trace metadata and another for methods with reflection metadata.

Key Changes

  • Introduces StackTraceLineNumbersNode and StackTraceDocumentsNode to embed line number and document information into the executable
  • Adds HasLineNumbers flag to MethodStackTraceVisibilityFlags and corresponding StackTraceRecordFlags to control line number emission
  • Extends VersionResilientHashCode with CombineThreeValuesIntoHash method for hashing three values

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs Adds regression test for issue #121093 validating stack trace contains method names for both reflected and non-reflected generic methods
src/libraries/Common/src/Internal/VersionResilientHashCode.cs Adds CombineThreeValuesIntoHash method for creating stable hash codes from three values
src/coreclr/tools/aot/ILCompiler/Program.cs Updates stack trace emission policy to enable line numbers when stack trace data is emitted
src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj Adds new node files to project
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs Updates ComputeMetadata signature to include reflection-based stack trace mappings
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/StackTraceEmissionPolicy.cs Adds HasLineNumbers flag support and constructor parameter to control line number inclusion
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs Refactors stack trace mapping to support both regular and reflection-based line number generation, adds flag-based filtering
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceMethodMappingNode.cs Updates to use flag enum instead of boolean
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs New node that generates hashtable mapping methods to compressed line number data
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceDocumentsNode.cs New node that stores document paths with offset-based indexing
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/AnalysisBasedMetadataManager.cs Updates ComputeMetadata signature to include reflection-based stack trace mappings
src/coreclr/tools/Common/Internal/Runtime/MetadataBlob.cs Adds blob IDs for line numbers and documents
src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs Adds ordering entries for new node types

@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review December 9, 2025 22:52
@MichalStrehovsky
Copy link
Member Author

The extra data adds 5-10% in size (MichalStrehovsky/rt-sz#199 (comment)) to existing apps. So I'm not folding this into StackTraceSupport property (that we enable by default and is by itself a 10% cost). I triggered a another rt-sz run on what is in the branch now to verify the additional cost is zero when this is not enabled (well, not fully zero since we still have code to read it, but close).

This is ready for review now.

@MichalStrehovsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MichalStrehovsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MichalStrehovsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MichalStrehovsky MichalStrehovsky merged commit e0ccd29 into dotnet:main Dec 17, 2025
152 of 154 checks passed
@MichalStrehovsky MichalStrehovsky deleted the fix68714 branch December 17, 2025 22:48
MichalStrehovsky pushed a commit that referenced this pull request Dec 22, 2025
Updates the repro project according to
#122227.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants