Skip to content

Use RhpGetThread with emulated TLS in arm64 EH helpers - #137697

Merged
jkotas merged 4 commits into
dotnet:mainfrom
am11:fix/arm64-emulated-tls
Nov 18, 2026
Merged

jkotas merged 4 commits into
dotnet:mainfrom
am11:fix/arm64-emulated-tls

Conversation

@am11

@am11 am11 commented Nov 16, 2026

Copy link
Copy Markdown
Member

INLINE_GETTHREAD reads tls_CurrentThread directly on arm64, which does not exist with FEATURE_EMULATED_TLS (Android). Call RhpGetThread in CallEHFunclet and RhpResumeAfterCatch instead, like PInvoke.S and GcProbe.S do.

Fixes #137692

INLINE_GETTHREAD reads tls_CurrentThread directly on arm64, which does
not exist with FEATURE_EMULATED_TLS (Android). Call RhpGetThread in
CallEHFunclet and RhpResumeAfterCatch instead, like PInvoke.S and
GcProbe.S do.

Fixes dotnet#137692

Co-authored-by: Cursor <[email protected]>
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 16, 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.

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.

🟡 Changes recommended

A critical unwind issue remains: GETTHREAD_ETLS_2 restores fp without resetting the CFA to sp, which can cause asynchronous stack walks on emulated-TLS builds to recover the wrong caller stack pointer.

1 open issue
What changed in this PR

This PR addresses the Android ARM64 NativeAOT link failure reported in #137692 by making exception-handling helpers use RhpGetThread when emulated thread-local storage is enabled.

Changes:

  • Preserve funclet arguments across thread lookup in CallEHFunclet.
  • Use the emulated-TLS accessor in RhpResumeAfterCatch, while retaining inline access for native-TLS builds.
File Description
src/​coreclr/​runtime/​arm64/​EHHelpers.S Adds conditional RhpGetThread lookup and argument preservation for funclet invocation.
src/​coreclr/​nativeaot/​Runtime/​arm64/​ExceptionHandling.S Adds emulated-TLS lookup during catch resumption and uses x2 for the thread pointer.

Review effort: Balanced

am11 added 2 commits November 18, 2026 01:40
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr makes fp the CFA register, and the
epilog does not switch it back to sp, so the unwind rules after these
macros were based on the caller's fp.

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

Static review found no actionable defects, but the ARM64 EH register-preservation and shared TLS unwind-metadata changes require Android ARM64 NativeAOT linking and exception/GC smoke validation that has not been performed.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jkotas jkotas 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.

Thanks!

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.

[NativeAOT][Android] ARM64 link fails with undefined tls_CurrentThread after EH helper changes

3 participants