Skip to content

Conversation

@janvorli
Copy link
Member

There is a problem with delegate calls when the first target arch is aligned to 16 bytes. One path to call the delegate removes the delegate obj from the argument list by moving the arguments on the interpreter stack by the size of the delegate obj slot. But in the problematic case, the stack slot of the delegate obj is followed by an unused slot that ensures the alignment of the first target argument that starts after it. Moving the arguments by the 8 bytes garbles the arguments and makes that unused slot part of the first target arg. Moreover, it also doesn't move the last 8 bytes of the last argument due to this.

This change fixes it by ensuring that we move the arguments starting at the aligned location of the first target argument.

This fixes a large number of the libraries tests.

There is a problem with delegate calls when the first target arch is
aligned to 16 bytes. One path to call the delegate removes the delegate
obj from the argument list by moving the arguments on the interpreter
stack by the size of the delegate obj slot. But in the problematic case,
the stack slot of the delegate obj is followed by an unused slot that
ensures the alignment of the first target argument that starts after it.
Moving the arguments by the 8 bytes garbles the arguments and makes that
unused slot part of the first target arg. Moreover, it also doesn't move
the last 8 bytes of the last argument due to this.

This change fixes it by ensuring that we move the arguments starting at
the aligned location of the first target argument.
@janvorli janvorli added this to the 11.0.0 milestone Nov 24, 2025
@janvorli janvorli self-assigned this Nov 24, 2025
Copilot AI review requested due to automatic review settings November 24, 2025 21:02
@janvorli janvorli requested review from BrzVlad and kg as code owners November 24, 2025 21:02
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

Copilot finished reviewing on behalf of janvorli November 24, 2025 21: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 fixes a bug in the interpreter's delegate call handling when the first target method argument requires 16-byte alignment. The issue occurred because the code was incorrectly using INTERP_STACK_SLOT_SIZE (8 bytes) to calculate where to start moving arguments, but when 16-byte alignment is needed, there's an 8-byte padding slot between the delegate object and the first target argument. This caused argument corruption.

Key changes:

  • In compiler.cpp: Added logic to calculate and emit the correct offset of the first target argument (firstTargetArgOffset) based on its alignment requirement
  • In interpexec.cpp: Updated the non-tail delegate call path to read and use this offset instead of the hardcoded INTERP_STACK_SLOT_SIZE

Reviewed changes

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

File Description
src/coreclr/interpreter/compiler.cpp Calculates and emits the alignment-based offset of the first target argument for INTOP_CALLDELEGATE instructions
src/coreclr/vm/interpexec.cpp Reads the first target argument offset and uses it when shifting arguments to remove the delegate object from the argument list

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copy link
Member

@kg kg left a comment

Choose a reason for hiding this comment

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

Aside from the comment LGTM

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@janvorli
Copy link
Member Author

There is some problem with the change, the interpreter test is failing in the CI. I need to investigate.

@janvorli
Copy link
Member Author

I've forgotten to add the change in intops.def, that was the issue. Added now.

@janvorli janvorli closed this Nov 25, 2025
@janvorli janvorli reopened this Nov 25, 2025
@janvorli
Copy link
Member Author

/ba-g the failures are infra issue due to macos-13 brownout

@janvorli janvorli merged commit 7baffba into dotnet:main Nov 25, 2025
82 of 94 checks passed
@janvorli janvorli deleted the fix-delegate-calls-with-first-arg-large-alignment branch November 25, 2025 21:48
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.

2 participants