Commit 8d07196
[wasm coreclr] Fix fields alignment (#115364)
* Fix fields alignment
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:
```
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.
* Update conditions to use TARGET_WASM
* Apply suggestions from code review
* Apply suggestions from code review
---------
Co-authored-by: Jan Kotas <[email protected]>1 parent 54bec5f commit 8d07196
2 files changed
+4
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 11 | + | |
| 12 | + | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 149 | + | |
| 150 | + | |
153 | 151 | | |
154 | 152 | | |
155 | 153 | | |
| |||
0 commit comments