From c3f28eb2987c26e86f5502b4b0467e9a4123b66c Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Tue, 7 Apr 2026 15:57:01 -0700 Subject: [PATCH 1/6] Add new WASM_MEMORY_ADDR_REL_LEB reloc - This is used to make loads/stores more efficient. loads/stores have an offset baked into them, so instead of global.get 1 i32.const add i32.load We can do global.get 1 i32.load offset= Overall this saves 3 bytes of space per load from an RVA relative address --- src/coreclr/inc/corinfo.h | 2 + .../Compiler/DependencyAnalysis/Relocation.cs | 5 + .../Compiler/ObjectWriter/WasmInstructions.cs | 145 ++++++++++++------ .../Compiler/ObjectWriter/WasmObjectWriter.cs | 16 ++ .../tools/Common/JitInterface/CorInfoImpl.cs | 1 + .../tools/Common/JitInterface/CorInfoTypes.cs | 2 + 6 files changed, 128 insertions(+), 43 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 319aaeb23d82cb..5ba772bcebd970 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -928,6 +928,8 @@ enum class CorInfoReloc // e.g. in R2R scenarios as an offset from __image_base WASM_TYPE_INDEX_LEB, // Wasm: a type index encoded as a 5-byte varuint32, e.g. the type immediate in a call_indirect. WASM_GLOBAL_INDEX_LEB, // Wasm: a global index encoded as a 5-byte varuint32, e.g. the index immediate in a get_global. + WASM_MEMORY_ADDR_REL_LEB, // Wasm: a relative linear memory index encoded as a 5-byte varint32. Used as the immediate argument of a load or store instruction, + // e.g. in R2R scenarios as an offset from __image_base }; enum CorInfoGCType diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs index e42de9d295a037..e716729a547d49 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs @@ -59,6 +59,8 @@ public enum RelocType WASM_TABLE_INDEX_I32 = 0x207, // Wasm: a table index encoded as a 4-byte uint32, e.g. for storing the "address" of a function into linear memory WASM_TABLE_INDEX_I64 = 0x208, // Wasm: a table index encoded as a 8-byte uint64, e.g. for storing the "address" of a function into linear memory + WASM_MEMORY_ADDR_REL_LEB = 0x209, // Wasm: a relative linear memory index encoded as a 5-byte varint32. Used as the immediate argument of a load or store instruction, + // e.g. in R2R scenarios as an offset from __image_base // // Relocation operators related to TLS access @@ -656,6 +658,7 @@ public static unsafe void WriteValue(RelocType relocType, void* location, long v case RelocType.WASM_GLOBAL_INDEX_LEB: case RelocType.WASM_FUNCTION_INDEX_LEB: case RelocType.WASM_MEMORY_ADDR_LEB: + case RelocType.WASM_MEMORY_ADDR_REL_LEB: DwarfHelper.WritePaddedULEB128(new Span((byte*)location, WASM_PADDED_RELOC_SIZE_32), checked((ulong)value)); return; @@ -710,6 +713,7 @@ public static int GetSize(RelocType relocType) RelocType.WASM_GLOBAL_INDEX_LEB => WASM_PADDED_RELOC_SIZE_32, RelocType.WASM_MEMORY_ADDR_LEB => WASM_PADDED_RELOC_SIZE_32, RelocType.WASM_MEMORY_ADDR_SLEB => WASM_PADDED_RELOC_SIZE_32, + RelocType.WASM_MEMORY_ADDR_REL_LEB => WASM_PADDED_RELOC_SIZE_32, RelocType.WASM_MEMORY_ADDR_REL_SLEB => WASM_PADDED_RELOC_SIZE_32, RelocType.WASM_TABLE_INDEX_I32 => 4, RelocType.WASM_TABLE_INDEX_I64 => 8, @@ -783,6 +787,7 @@ public static unsafe long ReadValue(RelocType relocType, void* location) return 0; case RelocType.WASM_MEMORY_ADDR_LEB: + case RelocType.WASM_MEMORY_ADDR_REL_LEB: return checked((long)DwarfHelper.ReadULEB128(new ReadOnlySpan(location, WASM_PADDED_RELOC_SIZE_32))); case RelocType.WASM_MEMORY_ADDR_SLEB: diff --git a/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs b/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs index cef0e10580c797..87043cd0a02f00 100644 --- a/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs +++ b/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs @@ -295,12 +295,81 @@ public static void OffsetRelocationsByOffset(Span buffer, int offset } } - class WasmMemoryArgInstruction : WasmExpr + struct WasmEncodableULong : IWasmEncodable + { + private ulong _value; + public WasmEncodableULong(ulong value) + { + _value = value; + } + public int EncodeSize() + { + return (int)DwarfHelper.SizeOfULEB128(_value); + } + public int Encode(Span buffer) + { + return DwarfHelper.WriteULEB128(buffer, _value); + } + public int EncodeRelocationCount() => 0; + public int EncodeRelocations(Span buffer) => 0; + } + + struct WasmEncodableSymbol : IWasmEncodable + { + private ISymbolNode _symbol; + private RelocType _relocType; + + public WasmEncodableSymbol(ISymbolNode symbol, RelocType relocType) + { + _symbol = symbol; + _relocType = relocType; + } + + public int EncodeSize() + { + return Relocation.GetSize(_relocType); + } + + public int Encode(Span buffer) + { + // The actual value is not encoded into the buffer, instead a relocation is emitted for the symbol + int relocSize = Relocation.GetSize(_relocType); + switch (_relocType) + { + case RelocType.WASM_FUNCTION_INDEX_LEB: + case RelocType.WASM_MEMORY_ADDR_LEB: + case RelocType.WASM_MEMORY_ADDR_REL_LEB: + case RelocType.WASM_TYPE_INDEX_LEB: + case RelocType.WASM_GLOBAL_INDEX_LEB: + DwarfHelper.WritePaddedULEB128(buffer, 0); + break; + + case RelocType.WASM_TABLE_INDEX_SLEB: + case RelocType.WASM_MEMORY_ADDR_REL_SLEB: + DwarfHelper.WritePaddedSLEB128(buffer, 0); + break; + + default: + throw new Exception($"Unknown WASM reloc type : {_relocType}"); + } + return relocSize; + } + + public int EncodeRelocationCount() => 1; + + public int EncodeRelocations(Span buffer) + { + buffer[0] = new Relocation(_relocType, 0, _symbol); + return 1; + } + } + + class WasmMemoryArgInstruction : WasmExpr where TOffset : IWasmEncodable { readonly uint _align; - readonly ulong _offset; + readonly TOffset _offset; - public WasmMemoryArgInstruction(WasmExprKind kind, uint align, ulong offset) : base(kind) + public WasmMemoryArgInstruction(WasmExprKind kind, uint align, TOffset offset) : base(kind) { switch (align) { @@ -317,7 +386,7 @@ public WasmMemoryArgInstruction(WasmExprKind kind, uint align, ulong offset) : b public override int EncodeSize() { - uint valSize = DwarfHelper.SizeOfULEB128(_align) + DwarfHelper.SizeOfULEB128(_offset); + int valSize = (int)DwarfHelper.SizeOfULEB128(_align) + _offset.EncodeSize(); return base.EncodeSize() + (int)valSize; } @@ -325,9 +394,17 @@ public override int Encode(Span buffer) { int pos = base.Encode(buffer); pos += DwarfHelper.WriteULEB128(buffer.Slice(pos), _align); - pos += DwarfHelper.WriteULEB128(buffer.Slice(pos), _offset); + pos += _offset.Encode(buffer.Slice(pos)); return pos; } + public override int EncodeRelocationCount() => _offset.EncodeRelocationCount(); + public override int EncodeRelocations(Span buffer) + { + int relocsEncoded = _offset.EncodeRelocations(buffer); + if (relocsEncoded > 0) + WasmExpr.OffsetRelocationsByOffset(buffer.Slice(0, relocsEncoded), base.EncodeSize() + (int)DwarfHelper.SizeOfULEB128(_align)); + return relocsEncoded; + } } // Represents a constant expression (e.g., (i32.const )) @@ -399,46 +476,27 @@ public override int EncodeRelocations(Span buffer) sealed class WasmLEBConstantReloc : WasmExpr { - readonly ISymbolNode _symbol; - readonly RelocType _relocType; + readonly WasmEncodableSymbol _symbol; public WasmLEBConstantReloc(WasmExprKind kind, ISymbolNode symbol, RelocType relocType) : base(kind) { - _symbol = symbol; - _relocType = relocType; + _symbol = new WasmEncodableSymbol(symbol, relocType); } - public override int EncodeSize() => base.EncodeSize() + Relocation.GetSize(_relocType); + public override int EncodeSize() => base.EncodeSize() + _symbol.EncodeSize(); public override int Encode(Span buffer) { int pos = base.Encode(buffer); - int relocSize = Relocation.GetSize(_relocType); - switch (_relocType) - { - case RelocType.WASM_FUNCTION_INDEX_LEB: - case RelocType.WASM_MEMORY_ADDR_LEB: - case RelocType.WASM_TYPE_INDEX_LEB: - case RelocType.WASM_GLOBAL_INDEX_LEB: - DwarfHelper.WritePaddedULEB128(buffer.Slice(pos, relocSize), 0); - break; - - case RelocType.WASM_TABLE_INDEX_SLEB: - case RelocType.WASM_MEMORY_ADDR_REL_SLEB: - DwarfHelper.WritePaddedSLEB128(buffer.Slice(pos, relocSize), 0); - break; - - default: - throw new Exception($"Unknown WASM reloc type : {_relocType}"); - } - - pos += relocSize; + pos += _symbol.Encode(buffer.Slice(pos)); return pos; } - public override int EncodeRelocationCount() => 1; + public override int EncodeRelocationCount() => _symbol.EncodeRelocationCount(); public override int EncodeRelocations(Span buffer) { - buffer[0] = new Relocation(_relocType, base.EncodeSize(), _symbol); - return 1; + int relocsEncoded = _symbol.EncodeRelocations(buffer); + if (relocsEncoded > 0) + WasmExpr.OffsetRelocationsByOffset(buffer.Slice(0, relocsEncoded), base.EncodeSize()); + return relocsEncoded; } } @@ -694,32 +752,33 @@ public static WasmExpr ConstRVA(ISymbolNode symbolNode) public static WasmExpr Add => new WasmBinaryExpr(WasmExprKind.I32Add); public static WasmExpr Sub => new WasmBinaryExpr(WasmExprKind.I32Sub); public static WasmExpr Ge_s => new WasmBinaryExpr(WasmExprKind.I32Ge_s); - public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.I32Load, 4, offset); - public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.I32Store, 4, offset); + public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.I32Load, 4, new WasmEncodableULong(offset)); + public static WasmExpr LoadWithRVAOffset(ISymbolNode symbolNode) => new WasmMemoryArgInstruction(WasmExprKind.I32Load, 4, new WasmEncodableSymbol(symbolNode, RelocType.WASM_MEMORY_ADDR_REL_LEB)); + public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.I32Store, 4, new WasmEncodableULong(offset)); } static class I64 { - public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.I64Load, 8, offset); - public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.I64Store, 8, offset); + public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.I64Load, 8, new WasmEncodableULong(offset)); + public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.I64Store, 8, new WasmEncodableULong(offset)); } static class F32 { - public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.F32Load, 4, offset); - public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.F32Store, 4, offset); + public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.F32Load, 4, new WasmEncodableULong(offset)); + public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.F32Store, 4, new WasmEncodableULong(offset)); } static class F64 { - public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.F64Load, 8, offset); - public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.F64Store, 8, offset); + public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.F64Load, 8, new WasmEncodableULong(offset)); + public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.F64Store, 8, new WasmEncodableULong(offset)); } static class V128 { - public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.V128Load, 16, offset); - public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.V128Store, 16, offset); + public static WasmExpr Load(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.V128Load, 16, new WasmEncodableULong(offset)); + public static WasmExpr Store(ulong offset) => new WasmMemoryArgInstruction(WasmExprKind.V128Store, 16, new WasmEncodableULong(offset)); } static class Memory diff --git a/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs b/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs index bceb16c096e174..6fab037c6cf504 100644 --- a/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs +++ b/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs @@ -961,6 +961,22 @@ private unsafe void ResolveRelocations(int sectionIndex, MemoryStream sectionStr Relocation.WriteValue(reloc.Type, pData, virtualSymbolImageOffset + addend); break; } + case RelocType.WASM_MEMORY_ADDR_REL_LEB: + { + // These relocs should be for cases of the form: + // global.get __image_base + // i32.load + // So, the relocated address value should always represent an offset relative to image base. + // This offset should ALWAYS be equal to the actual offset from image base at runtime, due to Webcil's + // flag mapping + if (symbolWebcilSection is null) + { + throw new InvalidDataException(); + } + + Relocation.WriteValue(reloc.Type, pData, virtualSymbolImageOffset + addend); + break; + } case RelocType.WASM_TABLE_INDEX_I32: case RelocType.WASM_TABLE_INDEX_I64: case RelocType.WASM_TABLE_INDEX_SLEB: diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 1654ad2613be04..0af041b078149e 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -4250,6 +4250,7 @@ private RelocType GetRelocType(CorInfoReloc reloc) CorInfoReloc.WASM_MEMORY_ADDR_LEB => RelocType.WASM_MEMORY_ADDR_LEB, CorInfoReloc.WASM_MEMORY_ADDR_SLEB => RelocType.WASM_MEMORY_ADDR_SLEB, CorInfoReloc.WASM_MEMORY_ADDR_REL_SLEB => RelocType.WASM_MEMORY_ADDR_REL_SLEB, + CorInfoReloc.WASM_MEMORY_ADDR_REL_LEB => RelocType.WASM_MEMORY_ADDR_REL_LEB, CorInfoReloc.WASM_TYPE_INDEX_LEB => RelocType.WASM_TYPE_INDEX_LEB, CorInfoReloc.WASM_GLOBAL_INDEX_LEB => RelocType.WASM_GLOBAL_INDEX_LEB, _ => throw new ArgumentException("Unsupported relocation type: " + reloc), diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 9969f75ef2db0b..e84795d2e3f4a6 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -518,6 +518,8 @@ public enum CorInfoReloc // e.g. in R2R scenarios, encoding an offset from __image_base WASM_TYPE_INDEX_LEB, // Wasm: a type index encoded as a 5-byte varuint32, e.g. the type immediate in a call_indirect. WASM_GLOBAL_INDEX_LEB, // Wasm: a global index encoded as a 5-byte varuint32, e.g. the index immediate in a get_global. + WASM_MEMORY_ADDR_REL_LEB, // Wasm: a relative linear memory index encoded as a 5-byte varuint32. Used as the immediate argument of a load or store instruction, + // e.g. in R2R scenarios, encoding an offset from __image_base } public enum CorInfoGCType From 5f42e8f7c8000db130743eac8c9840ca04d061d5 Mon Sep 17 00:00:00 2001 From: adamperlin Date: Wed, 8 Apr 2026 15:34:13 -0700 Subject: [PATCH 2/6] Fix comment --- src/coreclr/inc/corinfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 5ba772bcebd970..415a07e102db1e 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -928,7 +928,7 @@ enum class CorInfoReloc // e.g. in R2R scenarios as an offset from __image_base WASM_TYPE_INDEX_LEB, // Wasm: a type index encoded as a 5-byte varuint32, e.g. the type immediate in a call_indirect. WASM_GLOBAL_INDEX_LEB, // Wasm: a global index encoded as a 5-byte varuint32, e.g. the index immediate in a get_global. - WASM_MEMORY_ADDR_REL_LEB, // Wasm: a relative linear memory index encoded as a 5-byte varint32. Used as the immediate argument of a load or store instruction, + WASM_MEMORY_ADDR_REL_LEB, // Wasm: a relative linear memory index encoded as a 5-byte varuint32. Used as the immediate argument of a load or store instruction, // e.g. in R2R scenarios as an offset from __image_base }; From 72ad91bf9a620e39b308ebb1cceab0af5f0217a4 Mon Sep 17 00:00:00 2001 From: adamperlin Date: Wed, 8 Apr 2026 15:37:53 -0700 Subject: [PATCH 3/6] Bump JIT/EE interface version due to new CorInfoReloc --- src/coreclr/inc/jiteeversionguid.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 17e19b9cdae81c..495f521cbac190 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -37,11 +37,11 @@ #include -constexpr GUID JITEEVersionIdentifier = { /* d4aa533f-231b-4bd3-9d4e-238f88b337cb */ - 0xd4aa533f, - 0x231b, - 0x4bd3, - {0x9d, 0x4e, 0x23, 0x8f, 0x88, 0xb3, 0x37, 0xcb} +constexpr GUID JITEEVersionIdentifier = { /* 5fad64ab-f0ea-4c4d-b67a-b3a47ef0b321 */ + 0x5fad64ab, + 0xf0ea, + 0x4c4d, + {0xb6, 0x7a, 0xb3, 0xa4, 0x7e, 0xf0, 0xb3, 0x21} }; #endif // JIT_EE_VERSIONING_GUID_H From 39b68739579055d9118461297cc638ce67c2ab35 Mon Sep 17 00:00:00 2001 From: Adam Perlin Date: Thu, 9 Apr 2026 09:25:51 -0700 Subject: [PATCH 4/6] Update src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../tools/Common/Compiler/DependencyAnalysis/Relocation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs index e716729a547d49..c51dbceaa32fe9 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs @@ -59,7 +59,7 @@ public enum RelocType WASM_TABLE_INDEX_I32 = 0x207, // Wasm: a table index encoded as a 4-byte uint32, e.g. for storing the "address" of a function into linear memory WASM_TABLE_INDEX_I64 = 0x208, // Wasm: a table index encoded as a 8-byte uint64, e.g. for storing the "address" of a function into linear memory - WASM_MEMORY_ADDR_REL_LEB = 0x209, // Wasm: a relative linear memory index encoded as a 5-byte varint32. Used as the immediate argument of a load or store instruction, + WASM_MEMORY_ADDR_REL_LEB = 0x209, // Wasm: a relative linear memory index encoded as a 5-byte varuint32. Used as the immediate argument of a load or store instruction, // e.g. in R2R scenarios as an offset from __image_base // From 0c448a519e367b5d104fb9901cd96e5b13670b5b Mon Sep 17 00:00:00 2001 From: adamperlin Date: Thu, 9 Apr 2026 13:25:58 -0700 Subject: [PATCH 5/6] Feedback; slice buffer to reloc size before writing padded relocs in WasmInstructions --- .../tools/Common/Compiler/ObjectWriter/WasmInstructions.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs b/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs index 87043cd0a02f00..020d28029249da 100644 --- a/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs +++ b/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs @@ -334,6 +334,7 @@ public int Encode(Span buffer) { // The actual value is not encoded into the buffer, instead a relocation is emitted for the symbol int relocSize = Relocation.GetSize(_relocType); + Debug.Assert(buffer.Length >= relocSize); switch (_relocType) { case RelocType.WASM_FUNCTION_INDEX_LEB: @@ -341,12 +342,12 @@ public int Encode(Span buffer) case RelocType.WASM_MEMORY_ADDR_REL_LEB: case RelocType.WASM_TYPE_INDEX_LEB: case RelocType.WASM_GLOBAL_INDEX_LEB: - DwarfHelper.WritePaddedULEB128(buffer, 0); + DwarfHelper.WritePaddedULEB128(buffer.Slice(0, relocSize), 0); break; case RelocType.WASM_TABLE_INDEX_SLEB: case RelocType.WASM_MEMORY_ADDR_REL_SLEB: - DwarfHelper.WritePaddedSLEB128(buffer, 0); + DwarfHelper.WritePaddedSLEB128(buffer.Slice(0, relocSize), 0); break; default: @@ -367,7 +368,7 @@ public int EncodeRelocations(Span buffer) class WasmMemoryArgInstruction : WasmExpr where TOffset : IWasmEncodable { readonly uint _align; - readonly TOffset _offset; + TOffset _offset; public WasmMemoryArgInstruction(WasmExprKind kind, uint align, TOffset offset) : base(kind) { From 8988ba1b62a1b02a70b4ae67391a2d1756e58161 Mon Sep 17 00:00:00 2001 From: adamperlin Date: Thu, 9 Apr 2026 13:41:37 -0700 Subject: [PATCH 6/6] Rename __image_base -> imageBase in comments --- .../tools/Common/Compiler/DependencyAnalysis/Relocation.cs | 4 ++-- .../tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | 4 ++-- src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs index c51dbceaa32fe9..05f2e1213bf73f 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs @@ -52,7 +52,7 @@ public enum RelocType WASM_MEMORY_ADDR_SLEB = 0x203, // Wasm: a linear memory index encoded as a 5-byte varint32. Used for the immediate argument of a i32.const instruction, // e.g. taking the address of a C++ global. WASM_MEMORY_ADDR_REL_SLEB = 0x204, // Wasm: a relative linear memory index encoded as a 5-byte varint32. Used as the immediate argument of an i32.const instruction, - // e.g. in R2R scenarios, encoding an offset from __image_base + // e.g. in R2R scenarios, encoding an offset from $imageBase WASM_TYPE_INDEX_LEB = 0x205, // Wasm: a type index encoded as a 5-byte varuint32, e.g. the type immediate in a call_indirect. WASM_GLOBAL_INDEX_LEB = 0x206, // Wasm: a global index encoded as a 5-byte varuint32, e.g. the index immediate in a get_global. @@ -60,7 +60,7 @@ public enum RelocType WASM_TABLE_INDEX_I32 = 0x207, // Wasm: a table index encoded as a 4-byte uint32, e.g. for storing the "address" of a function into linear memory WASM_TABLE_INDEX_I64 = 0x208, // Wasm: a table index encoded as a 8-byte uint64, e.g. for storing the "address" of a function into linear memory WASM_MEMORY_ADDR_REL_LEB = 0x209, // Wasm: a relative linear memory index encoded as a 5-byte varuint32. Used as the immediate argument of a load or store instruction, - // e.g. in R2R scenarios as an offset from __image_base + // e.g. in R2R scenarios as an offset from $imageBase // // Relocation operators related to TLS access diff --git a/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs b/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs index 6fab037c6cf504..7f1bb208f7b563 100644 --- a/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs +++ b/src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs @@ -946,7 +946,7 @@ private unsafe void ResolveRelocations(int sectionIndex, MemoryStream sectionStr case RelocType.WASM_MEMORY_ADDR_REL_SLEB: { // These relocs should be for cases of the form: - // global.get __image_base + // global.get $imageBase // i32.const // i32.add // i32.load 0 @@ -964,7 +964,7 @@ private unsafe void ResolveRelocations(int sectionIndex, MemoryStream sectionStr case RelocType.WASM_MEMORY_ADDR_REL_LEB: { // These relocs should be for cases of the form: - // global.get __image_base + // global.get $imageBase // i32.load // So, the relocated address value should always represent an offset relative to image base. // This offset should ALWAYS be equal to the actual offset from image base at runtime, due to Webcil's diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index e84795d2e3f4a6..2a098727ae5ab6 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -515,11 +515,11 @@ public enum CorInfoReloc WASM_MEMORY_ADDR_SLEB, // Wasm: a linear memory index encoded as a 5-byte varint32. Used for the immediate argument of a i32.const instruction, // e.g. taking the address of a C++ global. WASM_MEMORY_ADDR_REL_SLEB, // Wasm: a relative linear memory index encoded as a 5-byte varint32. Used as the immediate argument of an i32.const instruction, - // e.g. in R2R scenarios, encoding an offset from __image_base + // e.g. in R2R scenarios, encoding an offset from $imageBase WASM_TYPE_INDEX_LEB, // Wasm: a type index encoded as a 5-byte varuint32, e.g. the type immediate in a call_indirect. WASM_GLOBAL_INDEX_LEB, // Wasm: a global index encoded as a 5-byte varuint32, e.g. the index immediate in a get_global. WASM_MEMORY_ADDR_REL_LEB, // Wasm: a relative linear memory index encoded as a 5-byte varuint32. Used as the immediate argument of a load or store instruction, - // e.g. in R2R scenarios, encoding an offset from __image_base + // e.g. in R2R scenarios, encoding an offset from $imageBase } public enum CorInfoGCType