Skip to content

Remove Wrapper delegate kind; switch ARM32 VSD hidden arg to R12 and fix ARM32 fail-path register preservation#129403

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/remove-wrapper-delegate-kind
Draft

Remove Wrapper delegate kind; switch ARM32 VSD hidden arg to R12 and fix ARM32 fail-path register preservation#129403
Copilot wants to merge 5 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 across VM/JIT/AOT/contracts and System.Private.CoreLib.

  • ARM32 VSD calling-convention alignment

    • Updates ARM32 stub-dispatch plumbing to carry IndirectionCellAndFlags in r12 and token in r4.
    • Aligns JIT virtual-stub parameter selection on ARM32 to REG_R12.
  • Wrapper delegate infrastructure removal

    • Removes wrapper-delegate creation/detection/runtime paths from COMDelegate.
    • Removes remaining wrapper handling from MulticastDelegate.CoreCLR.cs.
    • Removes wrapper-specific IL stub kind/plumbing and associated metadata fields.
    • Removes wrapper-specific JIT call flags and late-arg handling.
  • Cross-layer contract cleanup

    • Deletes obsolete wrapperDelegateInvoke and offsetOfWrapperDelegateIndirectCell from EE/JIT interfaces and SuperPMI agnostic records.
    • Keeps VM/JIT/AOT call-info structures consistent after field removal.
    • Revs the JIT/EE interface GUID in jiteeversionguid.h to match the interface change.
  • IL stub enum cleanup

    • Deletes the unused wrapper IL stub value and renumbers subsequent IL stub values in VM (method.hpp, dllimport.h) and corresponding cDAC contract mapping.
  • ARM32 ResolveStub correctness fix

    • Fixes ResolveStub::_failEntryPoint to avoid clobbering r12 (which now carries IndirectionCellAndFlags).
    • Uses r4 as decrement scratch for _pCounter update and preserves callee-saved r4 via stack save/restore in the fail path.
  • R2R compatibility boundary

    • Bumps ReadyToRun major/minimum version to 23 for the ARM32 VSD register contract change.
    • Syncs version constants across native and managed header definitions.
  • Documentation update

    • Updates docs/design/coreclr/botr/clr-abi.md hidden-parameter section: ARM32 VSD hidden parameter is now R12.
// src/coreclr/jit/compiler.h (ARM32)
#elif defined(TARGET_ARM)
    reg     = REG_R12;
    regMask = RBM_R12;

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

CORINFO_CONST_LOOKUP instParamLookup;

bool wrapperDelegateInvoke;

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.

@copilot This is JIT/EE interface change. You need to rev the JIT/EE interface GUID.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in commit cdd573d by revving JITEEVersionIdentifier in src/coreclr/inc/jiteeversionguid.h to match the JIT/EE interface change.

@@ -1701,7 +1701,6 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO
pResult->sig.flags |= CorInfoSigInfoFlags.CORINFO_SIGFLAG_FAT_CALL;
}

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.

@copilot Nit: extra blank line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 4611ce1 by removing the extra blank line.

Comment thread src/coreclr/vm/method.hpp Outdated
StubArrayOp = 9,
StubMulticastDelegate = 10,
StubWrapperDelegate = 11,
// 11 was StubWrapperDelegate

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.

@copilot The cDAC contract is not stable yet. You can delete the unused value from here and cDAC.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 4611ce1. Removed the unused ILStubType value and renumbered the remaining values in the runtime-side contract enum.

@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
ILSTUB_UNBOXINGILSTUB = 0x80000005,
ILSTUB_INSTANTIATINGSTUB = 0x80000006,
ILSTUB_WRAPPERDELEGATE_INVOKE = 0x80000007,
// 0x80000007 was ILSTUB_WRAPPERDELEGATE_INVOKE

@jkotas jkotas Jun 15, 2026

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.

@copilot Delete the unused value and renumber the rest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 4611ce1. Deleted the unused ILSTUB value and renumbered the remaining ILSTUB_* constants.

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


// ------------------------------------------------------------------
// void ResolveWorkerAsmStub(r0, r1, r2, r3, r4:IndirectionCellAndFlags, r12:DispatchToken)
// void ResolveWorkerAsmStub(r0, r1, r2, r3, r12:IndirectionCellAndFlags, r4:DispatchToken)

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.

@copilot r4 won't work here. It is callee saved register. This will need to use stack instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 4611ce1. The fail path now preserves callee-saved r4 by saving/restoring it on the stack while using it as scratch.

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
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:18
Copilot AI changed the title Remove Wrapper delegate kind; switch ARM32 VSD hidden arg to R12 Remove Wrapper delegate kind; switch ARM32 VSD hidden arg to R12 and fix ARM32 fail-path clobber Jun 15, 2026
Copilot AI requested a review from jkotas June 15, 2026 05:19
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 15, 2026 06:09

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

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

Done in 4611ce1. Removed remaining wrapper-handling paths from MulticastDelegate.CoreCLR.cs.

Copilot AI changed the title Remove Wrapper delegate kind; switch ARM32 VSD hidden arg to R12 and fix ARM32 fail-path clobber Remove Wrapper delegate kind; switch ARM32 VSD hidden arg to R12 and fix ARM32 fail-path register preservation Jun 15, 2026
// The delegate may be put into a wrapper delegate if our target method requires it. This local
// will always hold the real (un-wrapped) delegate.
DELEGATEREF refRealDelegate = NULL;
DELEGATEREF refRealDelegate = *pRefThis;

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.

Rename the local since *pRefThis is always the real one now.

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.

@copilot Address this feedback

@MichalPetryka

Copy link
Copy Markdown
Contributor

There seem to be tons of test failures on arm32 currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants