Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Implement SystemV AMD64 ABI struct classification - #7767

Merged
janvorli merged 3 commits into
dotnet:masterfrom
janvorli:implement-systemv-amd64-struct-classification
Sep 5, 2019
Merged

janvorli merged 3 commits into
dotnet:masterfrom
janvorli:implement-systemv-amd64-struct-classification

Conversation

@janvorli

@janvorli janvorli commented Sep 3, 2019

Copy link
Copy Markdown
Member

This change implements SystemV AMD64 ABI struct classification necessary
for correct passing of function arguments of struct types and returning
these by value on Unix AMD64.

This change is a port of the CoreCLR version with necessary changes to reflect differences in the type system interface between CoreRT and CoreCLR. I have also added caching of the classification result as JIT calls classification for the same type many times.

This change implements SystemV AMD64 ABI struct classification necessary
for correct passing of function arguments of struct types and returning
these by value on Unix AMD64.
@janvorli

janvorli commented Sep 3, 2019

Copy link
Copy Markdown
Member Author

There is an issue that I've introduced during the final cleanup (bad assert). I'm working on a fix.

@janvorli

janvorli commented Sep 3, 2019

Copy link
Copy Markdown
Member Author

It was actually an incorrect classification for Nullable. Should be ok now.

{
internal class SystemVStructClassificator
{
const int CLR_SYSTEMV_MAX_EIGHTBYTES_COUNT_TO_PASS_IN_REGISTERS = 2;

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.

Maybe move this const into the SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR struct since it's related? I would probably move the other 3 consts there too since CorInfoTypes.cs is where we look for constants and data structures shared with the JIT.

if (fieldClassificationType == SystemVClassificationType.SystemVClassificationTypeTypedReference ||
TypeDef2SystemVClassification(typeDesc) == SystemVClassificationType.SystemVClassificationTypeTypedReference)
{
// The TypedReference is a very special type.

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.

I know it's unrelated to what you're doing but... sigh, at some point we really ought to make TypedReference on CoreCLR same as TypedReference in CoreRT (the first field is ByReference<T> instead of IntPtr and everything just naturally falls out).

The CoreCLR approach with special casing leaks out everywhere.

@janvorli
janvorli force-pushed the implement-systemv-amd64-struct-classification branch from 75b4a88 to 64df289 Compare September 4, 2019 20:17
@janvorli

janvorli commented Sep 4, 2019

Copy link
Copy Markdown
Member Author

I've found that there is some problem - the Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq test is failing with CPAOT. I'm not sure yet if it is due to my change or not, but I am looking ...

@janvorli

janvorli commented Sep 4, 2019

Copy link
Copy Markdown
Member Author

Never mind, there was no problem, I was just accidentally running ILC built from master without my change. With my change, the test passes.

@MichalStrehovsky MichalStrehovsky left a comment

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.

Thanks!

@janvorli
janvorli merged commit b4e8b02 into dotnet:master Sep 5, 2019
@janvorli
janvorli deleted the implement-systemv-amd64-struct-classification branch September 5, 2019 13:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants