Ensure EH native helpers are not on the stack trace#120951
Merged
janvorli merged 1 commit intodotnet:mainfrom Oct 21, 2025
Merged
Ensure EH native helpers are not on the stack trace#120951janvorli merged 1 commit intodotnet:mainfrom
janvorli merged 1 commit intodotnet:mainfrom
Conversation
Currently, the EH native helpers, like RhpSfiNext, that are library imports, are visible on the stack trace in case JIT / R2R doesn't inline the IL stubs for those pinvokes. That's due to two issues * The library imports are not marked by the `[StackTraceHidden]` attribute * Even if they were, the LibraryImportGenerator doesn't propagate this attribute to the target pinvoke This change fixes both of these issues.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that exception handling (EH) native helper functions do not appear in stack traces by propagating the [StackTraceHidden] attribute from library import declarations to their generated P/Invoke stubs. The change addresses an issue where EH helpers like RhpSfiNext were visible in stack traces when JIT/R2R didn't inline their IL stubs.
- Adds
[StackTraceHidden]attribute to EH native helper library imports in CoreCLR - Extends LibraryImportGenerator to recognize and forward the
[StackTraceHidden]attribute to generated P/Invoke stubs - Adds supporting infrastructure for handling the new attribute in the source generator
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/System.Private.CoreLib/src/System/Runtime/ExceptionServices/InternalCalls.cs | Adds [StackTraceHidden] attribute to all EH native helper library imports |
| src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs | Defines type name constants and name syntax properties for StackTraceHiddenAttribute |
| src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StubEnvironment.cs | Adds property to retrieve StackTraceHiddenAttribute symbol from compilation |
| src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs | Extends generator logic to detect and forward [StackTraceHidden] attribute to generated stubs |
jkoritzinsky
approved these changes
Oct 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, the EH native helpers, like
RhpSfiNext, that are library imports, are visible on the stack trace in case JIT / R2R doesn't inline the IL stubs for those pinvokes. That's due to two issues[StackTraceHidden]attributeLibraryImportGeneratordoesn't propagate this attribute to the target pinvokeThis change fixes both of these issues.
Close #120436