-
Notifications
You must be signed in to change notification settings - Fork 5k
[wasm coreclr] Fix fields alignment #115364
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
[wasm coreclr] Fix fields alignment #115364
Conversation
Fixes dotnet#115363 The problem happened in MethodTableBuilder::PlaceInstanceFields where in wasm case the fields were placed at wrong offsets. The native representation looks like this: ``` class field wasm type offset ----------------------------------------------------------------------------------------------- Object PTR_MethodTable m_pMethTab i32 0 AssemblyLoadContextBaseObject int64_t _id i64 8 OBJECTREF _unloadLock i32 12 OBJECTREF _resolvingUnmanagedDll i32 OBJECTREF _resolving i32 OBJECTREF _unloading i32 OBJECTREF _name i32 INT_PTR _nativeAssemblyLoadContext i32 DWORD _state i32 40 CLR_BOOL _isCollectible i8 44 ``` While the managed field offsets were calculated wrong, the _id was placed at offset 4 and thus all the following fields were at wrong offsets too. The size check then failed. By enabling FEATURE_64BIT_ALIGNMENT the dwOffsetBias is set to TARGET_POINTER_SIZE and the fields layout is calculated properly. The 8 bytes types in wasm should be aligned to 8 bytes https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md#data-representation so hopefully the rest of the changes enabled by this feature should apply as well. Before this feature was enabled only for arm 32bits.
There was a problem hiding this 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 field alignment issues in wasm CoreCLR by correcting the managed field offset calculation.
- Expanded the 64-bit alignment feature to include the wasm platform using the TARGET_BROWSER flag.
- Updates in both switches.h and gcenv.object.h files enable proper alignment for 8-byte types on wasm.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/coreclr/inc/switches.h | Added TARGET_BROWSER to enable FEATURE_64BIT_ALIGNMENT |
src/coreclr/gc/env/gcenv.object.h | Added TARGET_BROWSER to enable FEATURE_64BIT_ALIGNMENT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Fixes #115363
The problem happened in
MethodTableBuilder::PlaceInstanceFields
where in wasm case the fields were placed at wrong offsets.The native representation looks like this:
While the managed field offsets were calculated wrong, the _id was placed at offset 4 and thus all the following fields were at wrong offsets too. The size check then failed.
By enabling
FEATURE_64BIT_ALIGNMENT
thedwOffsetBias
is set toTARGET_POINTER_SIZE
and the fields layout is calculated properly.The 8 bytes wide types in wasm should be aligned to 8 bytes
https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md#data-representation
so hopefully the rest of the changes enabled by this feature should apply as well. Before this feature was enabled only for arm 32bits.