Skip to content

Remove Wrapper delegate kind, switch ARM32 VSD hidden arg to R12#129403

Merged
jkotas merged 64 commits into
mainfrom
copilot/remove-wrapper-delegate-kind
Jun 19, 2026
Merged

Remove Wrapper delegate kind, switch ARM32 VSD hidden arg to R12#129403
jkotas merged 64 commits into
mainfrom
copilot/remove-wrapper-delegate-kind

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

CoreCLR’s "Wrapper" delegate kind was retained only to satisfy an ARM32 VSD ABI quirk (r4 hidden cell). This change removes that special delegate path by moving ARM32 VSD hidden-parameter passing to r12 and deleting wrapper-delegate infrastructure.

Fixes #129399

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 15, 2026 04:32
Copilot AI changed the title [WIP] Remove need for the special Wrapper delegate kind Remove Wrapper delegate kind; switch ARM32 VSD hidden arg to R12 Jun 15, 2026
Copilot AI requested a review from jkotas June 15, 2026 04:33
@MichalPetryka

Copy link
Copy Markdown
Contributor

@copilot Remove all wrapper handling code from MulticastDelegate.CoreCLR.cs too.

Comment thread src/coreclr/inc/corinfo.h
Comment thread src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs Outdated
Comment thread src/coreclr/vm/method.hpp Outdated
@MichalPetryka

Copy link
Copy Markdown
Contributor

@copilot Remove all wrapper handling code from MulticastDelegate.CoreCLR.cs too.

@jkotas Can you repost this since only maintainers can interact with copilot?

Comment thread src/coreclr/vm/dllimport.h Outdated
@jkotas

jkotas commented Jun 15, 2026

Copy link
Copy Markdown
Member

@copilot Remove all wrapper handling code from MulticastDelegate.CoreCLR.cs too.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Comment thread src/coreclr/vm/arm/asmhelpers.S Outdated
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 15, 2026 05:03
@jkotas

jkotas commented Jun 18, 2026

Copy link
Copy Markdown
Member

@copilot Tests are still failing with

Assert failure(PID 16 [0x00000010], Thread: 16 [0x0010]): Data pointer is outside of loaded image.
File: /__w/1/s/src/coreclr/vm/readytoruninfo.h:537
Image: /root/helix/work/correlation/corerun

…bDispatch

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
@jkotas

jkotas commented Jun 18, 2026

Copy link
Copy Markdown
Member

@copilot Revert last commit. Change REG_R2R_INDIRECT_PARAM to r12 instead

Copilot AI and others added 2 commits June 18, 2026 20:29
…rtualStubDispatch"

This reverts commit 9295b50.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Revert last commit. Change REG_R2R_INDIRECT_PARAM to r12 instead

Fixed in the last two commits:

  1. Reverted the ImportThunk r4/r12 split (the ImportThunk.cs is back to using r12 for all three cases).
  2. Changed REG_R2R_INDIRECT_PARAM from REG_R4 to REG_R12 in src/coreclr/jit/targetarm.h so the JIT places the indirection cell in r12, matching the thunk's expectation.

@jkotas

jkotas commented Jun 19, 2026

Copy link
Copy Markdown
Member

@copilot Investigate test failures

22:16:15.423 Running test: global::Runtime_79354.Program.TestEntryPoint()
ASSERT FAILED
	Expression: pMgr != NULL
	Location:   /__w/1/s/src/coreclr/vm/virtualcallstub.cpp:1711
	Function:   VSD_ResolveWorker
	Process:    16

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.

Pull request overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/vm/arm/asmhelpers.S
Comment thread src/coreclr/vm/arm/stubs.cpp
Comment thread src/coreclr/vm/arm/stubs.cpp
… VSD

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Comment thread src/coreclr/vm/arm/stubs.cpp Outdated
Comment thread src/coreclr/vm/arm/stubs.cpp Outdated
Comment thread src/coreclr/vm/arm/stubs.cpp Outdated
Comment thread src/coreclr/vm/arm/stubs.cpp Outdated
…bbering lr

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Investigate test failures

22:16:15.423 Running test: global::Runtime_79354.Program.TestEntryPoint()

...

The root cause was in the simple case of EmitShuffleThunk (no stack-to-stack copies). The code was doing ldr lr, [r12] to load the dispatch stub into lr, then bx lr to jump there — but this clobbers lr (the caller's return address). When the target method eventually executes bx lr to return, it would return to the dispatch stub instead of the original caller, creating infinite dispatch / corrupted call state.

Fixed in the latest commit by replacing ldr lr, [r12] + bx lr with ldr pc, [r12]:

  • Loads the target from [r12] (the IndirectionCell) directly into PC (tail call)
  • lr is never modified — caller's return address is preserved
  • r12 stays intact as the IndirectionCell for VSD throughout the dispatch path

…tail call

- Replace ThumbEmitProlog(3,0,FALSE) with direct ThumbEmitPush({r4,r5,r6})
- Remove lr save since we're tail-calling (not making a subroutine call)
- Replace ldr r6,[r12]+str r6,[sp+...] with ldr pc,[r12] tail call
- Replace ThumbEmitEpilog() with ThumbEmitPop({r4,r5,r6})+ldr pc,[r12]
- Update cbSavedRegs to 3*4 (r4,r5,r6 only, no lr)
- Delete ThumbEmitProlog and ThumbEmitEpilog methods from cgencpu.h
- Delete DescribeProlog from stublink.h and stublink.cpp
- Delete prolog tracking fields (m_fProlog, m_cCalleeSavedRegs, m_cbStackFrame, m_fPushArgRegs)

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Comment thread src/coreclr/vm/stublink.h Outdated
@jkotas

jkotas commented Jun 19, 2026

Copy link
Copy Markdown
Member

@dotnet/jit-contrib Could you please review this?

This is deleting CoreCLR Arm32 ABI quirk and supporting infrastructure. IIRC, this quirk was a micro-optimization for Arm32 done in the Windows Phone era. We can live without this Arm32 specific micro-optimization going forward.

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.

Pull request overview

Copilot reviewed 39 out of 39 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/vm/arm/asmhelpers.S
Comment thread src/coreclr/vm/arm/stubs.cpp
Comment thread src/coreclr/vm/arm/stubs.cpp

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.

Pull request overview

Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/coreclr/jit/targetarm.h:183

  • On ARM32 this change makes both VSD hidden parameter and the R2R indirection cell register be R12. Existing ARM32 call emission for VSD/R2R indirection typically needs a scratch register to load the call target from [R12] before calling; with R12 now reserved for the hidden indirection-cell value, loading into (or otherwise clobbering) R12 would break stub dispatch (the callee would no longer receive the indirection cell in the expected register). Please ensure the ARM32 call sequence is updated to preserve R12 while still performing an indirect call (e.g., an explicit call-via-memory pattern) and that LSRA/codegen are updated accordingly.
// R2R indirect call. Use the same registers as VSD
#define REG_R2R_INDIRECT_PARAM          REG_R12
#define RBM_R2R_INDIRECT_PARAM          RBM_R12

// JMP Indirect call register
#define REG_INDIRECT_CALL_TARGET_REG REG_R12

Comment thread src/coreclr/vm/arm/asmhelpers.S
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Investigate removing Wrapper delegate kind

5 participants