Skip to content

Remove calli target tagging from CoreCLR interop stubs - #131642

Draft
jkotas with Copilot wants to merge 14 commits into
mainfrom
copilot/delete-target-shifting-call
Draft

Remove calli target tagging from CoreCLR interop stubs#131642
jkotas with Copilot wants to merge 14 commits into
mainfrom
copilot/delete-target-shifting-call

Conversation

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

This change removes the (target << 1) | 1 encoding previously used for marshaling-required unmanaged calli paths. MethodDesc and unmanaged target handling now follow their actual storage semantics instead of relying on low-bit tagging.

  • Interop stub fast paths

    • Removes target tagging from GenericPInvokeCalliHelper on 64-bit architectures.
    • Removes the matching decode path in PInvokeStubLinker::DoPInvoke.
    • Deletes stale debugger/interop cleanup that still assumed tagged calli targets.
  • InlinedCallFrame semantics

    • Simplifies InlinedCallFrame::HasFunction for non-32-bit targets to treat non-null m_Datum as a function-bearing frame.
    • Preserves the existing 32-bit stack-size sentinel behavior where m_Datum is still overloaded for indirect-call stack metadata.
    • Updates comments to describe the remaining contract precisely.
  • EH marker cleanup

    • Normalizes InlinedCallFrameMarker::ExceptionHandlingHelper handling to a single low-bit marker.
    • Removes 64-bit-specific assumptions that only existed because of calli target tagging.
  • cDAC stack walking

    • Updates cDAC StackWalk frame interpretation to match the new runtime encoding rules.
    • Adjusts unit tests that validate EH-helper detection and InlinedCallFrame classification.

Example of the removed special-case flow:

// old
target = (target << 1) | 1;
...
EmitLoadStubContext(pcsEmit, dwStubFlags);
pcsEmit->EmitLDC(1);
pcsEmit->EmitSHR_UN();

// new
EmitLoadStubContext(pcsEmit, dwStubFlags);

Note

This PR description was created by GitHub Copilot.

Copilot AI and others added 3 commits July 31, 2026 12:34
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 12:56

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Comment thread test.cs Outdated
Comment thread src/coreclr/vm/frames.h Outdated
@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.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 13:38

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Comment thread src/coreclr/jit/lower.cpp Outdated

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 Change this to be x86 specific

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.

Addressed in 8b5a9ce.

Comment thread src/coreclr/jit/lower.cpp Outdated
// If the stub parameter value is not needed, m_Datum will be initialized by the VM.
// CALLI stubs use the secret stub argument directly as the unmanaged target, so they leave m_Datum
// unused and keep the target only in the secret stub argument slot.
if (m_compiler->info.compPublishStubParam)

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 Just set the datum field to 0 here. Instead modify the IL generated for ILStubs to set the datum field to MethodDesc explicitly in the shared IL stubs that need it.

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 0e77207.

Comment thread src/coreclr/vm/frames.h Outdated
@@ -2100,12 +2100,11 @@ class InlinedCallFrame : public Frame

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 this method and inline the logic into GetFunction_Impl - the only place where this method is called

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 0e77207.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 19:31

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Comment thread src/coreclr/jit/importercalls.cpp
Comment thread src/coreclr/jit/lower.cpp Outdated
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 1, 2026 11:53

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 1, 2026 11:58

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 1, 2026 12:21

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Comment thread src/coreclr/interpreter/compiler.cpp Outdated
return true;
}

case NI_System_StubHelpers_SetNextCallFrameMethodDesc:

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 Revert all changes related to SetNextCallFrameMethodDesc

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.

Reverted all SetNextCallFrameMethodDesc-related changes in 963f13c.

Comment thread src/coreclr/jit/lower.cpp Outdated
Comment on lines +7032 to +7036
if (m_compiler->info.compPublishStubParam && call->HasInlinedCallFrameMethodDesc())
{
src = m_compiler->gtNewLclvNode(call->GetInlinedCallFrameMethodDescLclNum(), TYP_I_IMPL);
}
else if (m_compiler->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PUBLISH_STUB_PARAM_ICF_MD))

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.

Suggested change
if (m_compiler->info.compPublishStubParam && call->HasInlinedCallFrameMethodDesc())
{
src = m_compiler->gtNewLclvNode(call->GetInlinedCallFrameMethodDescLclNum(), TYP_I_IMPL);
}
else if (m_compiler->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PUBLISH_STUB_PARAM_ICF_MD))
if (m_compiler->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PUBLISH_STUB_PARAM_ICF_MD))

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.

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 963f13c.

Note

This reply was generated by GitHub Copilot.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 2, 2026 03:49

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

CORJIT_FLAG_SOFTFP_ABI = 30, // Enable armel calling convention
#endif
CORJIT_FLAG_USE_DISPATCH_HELPERS = 31, // The JIT should use helpers for interface dispatch instead of virtual stub dispatch
CORJIT_FLAG_PUBLISH_STUB_PARAM_ICF_MD = 32, // JIT should publish the stub secret param in InlinedCallFrame.m_Datum for indirect unmanaged calls

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 this flag. We do not need to set the datum field for shared stubs

0xe1ec,
0x4f52,
{0xa1, 0xbf, 0xf9, 0x19, 0x90, 0x8a, 0xa3, 0x3c}
constexpr GUID JITEEVersionIdentifier = { /* 8445fef6-8ba2-4cd4-bf1a-fa0c0fc276de */

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 Revert changes in this file

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants