Skip to content

Ensure EH native helpers are not on the stack trace#120951

Merged
janvorli merged 1 commit intodotnet:mainfrom
janvorli:propagate-stack-trace-hidden-to-pinvoke
Oct 21, 2025
Merged

Ensure EH native helpers are not on the stack trace#120951
janvorli merged 1 commit intodotnet:mainfrom
janvorli:propagate-stack-trace-hidden-to-pinvoke

Conversation

@janvorli
Copy link
Member

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.

Close #120436

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.
@janvorli janvorli added this to the 11.0.0 milestone Oct 21, 2025
@janvorli janvorli requested a review from jkoritzinsky October 21, 2025 20:06
@janvorli janvorli self-assigned this Oct 21, 2025
Copilot AI review requested due to automatic review settings October 21, 2025 20:06
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 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

@janvorli janvorli merged commit f762c3b into dotnet:main Oct 21, 2025
138 checks passed
@janvorli janvorli deleted the propagate-stack-trace-hidden-to-pinvoke branch October 21, 2025 22:58
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

3 participants