Skip to content

Commit 8d07196

Browse files
radekdoulikjkotas
andauthored
[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

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/coreclr/gc/env/gcenv.object.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
extern bool g_oldMethodTableFlags;
99
#endif
1010

11-
// ARM requires that 64-bit primitive types are aligned at 64-bit boundaries for interlocked-like operations.
12-
// Additionally the platform ABI requires these types and composite type containing them to be similarly
13-
// aligned when passed as arguments.
14-
#ifdef TARGET_ARM
11+
// Some 32-bit platform ABIs require that 64-bit primitive types and composite types containing them are aligned at 64-bit boundaries.
12+
#if defined(TARGET_ARM) || defined(TARGET_WASM)
1513
#define FEATURE_64BIT_ALIGNMENT
1614
#endif
1715

src/coreclr/inc/switches.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,8 @@
146146
#define FEATURE_HFA
147147
#endif
148148

149-
// ARM requires that 64-bit primitive types are aligned at 64-bit boundaries for interlocked-like operations.
150-
// Additionally the platform ABI requires these types and composite type containing them to be similarly
151-
// aligned when passed as arguments.
152-
#ifdef TARGET_ARM
149+
// Some 32-bit platform ABIs require that 64-bit primitive types and composite types containing them are aligned at 64-bit boundaries.
150+
#if defined(TARGET_ARM) || defined(TARGET_WASM)
153151
#define FEATURE_64BIT_ALIGNMENT
154152
#endif
155153

0 commit comments

Comments
 (0)