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 struct copying for structs with an unaligned size #387

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

rinon
Copy link
Collaborator

@rinon rinon commented Aug 29, 2024

Clang started packing structs immediately after
stack arguments, but we used to copy memory
arguments as 8-byte chunks. Instead, copy only up
to the size of the struct argument to avoid
overwriting other bytes above it on the stack.

Fixes #365

@rinon rinon requested a review from fw-immunant August 29, 2024 01:22
@rinon rinon changed the title Sjc/fix_structs_test Fix struct copying for structs with an unaligned size Aug 29, 2024
@rinon rinon force-pushed the sjc/fix_structs_test branch from b0474e0 to c5dc580 Compare August 29, 2024 01:27
Copy link
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

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

Various comments inline.

Comment on lines 255 to 260
sig.ret.push_back(CAbiArg{
.kind = CAbiArgKind::Memory,
.size = static_cast<unsigned>(num_regs) * 8,
.align = 8,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this unchanged (in terms of still working with eightbytes) because the ABI behaves differently between arguments and returns, or because this PR alters behavior for multiple arguments being packed together but there is only ever one value returned?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe branch only handles multiple integral values. Strangely sized structs are handled in abiSlotsForArg above.

@rinon rinon force-pushed the sjc/fix_structs_test branch from c5dc580 to 9e1dbe3 Compare September 19, 2024 22:19
rinon added 2 commits October 3, 2024 10:38

Verified

This commit was signed with the committer’s verified signature.
raydouglass Ray Douglass

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Clang started packing structs immediately after
stack arguments, but we used to copy memory
arguments as 8-byte chunks. Instead, copy only up
to the size of the struct argument to avoid
overwriting other bytes above it on the stack.
@rinon
Copy link
Collaborator Author

rinon commented Oct 9, 2024

@fw-immunant I think I've addressed all your feedback, so this needs another look when you can.

@fw-immunant
Copy link
Contributor

@fw-immunant I think I've addressed all your feedback, so this needs another look when you can.

One last question, otherwise all looks good.

Verified

This commit was signed with the committer’s verified signature.
@rinon
Copy link
Collaborator Author

rinon commented Oct 11, 2024

I ported over the free space simplification that is going to happen for ARM anyway. Should be good now?

@rinon rinon merged commit 1bfc58d into main Oct 11, 2024
34 checks passed
@rinon rinon deleted the sjc/fix_structs_test branch October 11, 2024 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Structs test fails on Arch (LLVM 18)
2 participants