Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix passing too small args for PUTARG_STK on macOS arm64 ABI #68108

Merged
merged 2 commits into from
Apr 16, 2022

Conversation

jakobbotsch
Copy link
Member

Fix #66720

I got far enough that I figured I would submit what I think is a good fix.

cc @dotnet/jit-contrib PTAL @AndyAyersMS

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 16, 2022
@ghost ghost assigned jakobbotsch Apr 16, 2022
@ghost
Copy link

ghost commented Apr 16, 2022

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

Issue Details

Fix #66720

I got far enough that I figured I would submit what I think is a good fix.

cc @dotnet/jit-contrib PTAL @AndyAyersMS

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

Thanks.

We should port this one back to 6.0.

emit->emitIns_S_R(INS_str, storeAttr, srcReg, varNumOut, argOffsetOut);
argOffsetOut += EA_SIZE_IN_BYTES(storeAttr);
}
assert(argOffsetOut <= argOffsetMax); // We can't write beyond the outgoing arg area
return;
}

var_types slotType = genActualType(source);
if (compMacOsArm64Abi())
Copy link
Member

Choose a reason for hiding this comment

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

@jakobbotsch, just for my own education; is it specific to mac ABI? i.e. if we apply the same classification to linux and windows arm64, it will break putarg on those targets?

This TODO is probably related:

// TODO-Cleanup: structs are aligned to 8 bytes on arm64 apple, so it would work, but pass the precise size.
*nextSlotNum += numSlots;
m_nextStackByteOffset += numSlots * TARGET_POINTER_SIZE;

Copy link
Member Author

Choose a reason for hiding this comment

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

macOS arm64 ABI is different in that multiple small arguments can be packed into the same stack slot. It means we have different behavior in some places in the JIT, and that different behavior was wrong here.
The behavior for the other ABIs did not have this bug.

@jakobbotsch jakobbotsch merged commit ce61c09 into dotnet:main Apr 16, 2022
@jakobbotsch
Copy link
Member Author

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/2177458293

@github-actions
Copy link
Contributor

@jakobbotsch backporting to release/6.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix passing too small args for PUTARG_STK on macOS arm64 ABI
Using index info to reconstruct a base tree...
M	src/coreclr/jit/codegenarmarch.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/jit/codegenarmarch.cpp
CONFLICT (content): Merge conflict in src/coreclr/jit/codegenarmarch.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix passing too small args for PUTARG_STK on macOS arm64 ABI
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

emit->emitIns_S_R(INS_str, storeAttr, srcReg, varNumOut, argOffsetOut);
argOffsetOut += EA_SIZE_IN_BYTES(storeAttr);
}
assert(argOffsetOut <= argOffsetMax); // We can't write beyond the outgoing arg area
return;
}

var_types slotType = genActualType(source);
Copy link
Contributor

Choose a reason for hiding this comment

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

do I understand this change correctly that now we have such slot types:
1byte - TYP_BYTE
2bytes - TYP_SHORT
4bytes - TYP_LONG (was TYP_INT before the change).
8bytes - TYP_LONG
?
so if we pass two TYP_INT on the stack, in one 8byte stack slot, don't we override anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not totally sure I understand. genActualType(TYP_INT) returns TYP_INT, not TYP_LONG.

The difference before was that we used the real type of the operand to decide on how much to store on the stack. That's not right, a small-typed operand still produces a value of type genActualType(operand) and it is the PUTARG_STK node that decides how much should be put on the stack. So we had a problem for e.g. a TYP_SHORT indirection feeding into a TYP_INT parameter.

A TYP_INT indirection feeding into a 4 byte parameter will still only store 4 bytes on the stack.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks!

@ghost ghost locked as resolved and limited conversation to collaborators May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in Int16 variables when running in M1 macs
4 participants