Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cedc59f
Move WasmValueType/ResultType/FuncType definitions out of object writ…
adamperlin Feb 10, 2026
b0530ff
Use WasmTypeNode for encoding and recording type signatures in WasmOb…
adamperlin Feb 21, 2026
94badba
Merge branch 'main' of github.com:dotnet/runtime into adamperlin/wasm…
adamperlin Feb 21, 2026
3a679b8
Replace WasmLowering.GetSignature implementation with patched version…
adamperlin Feb 21, 2026
d95867e
Update src/coreclr/tools/Common/Compiler/ObjectWriter/WasmNative.cs
adamperlin Feb 21, 2026
7fa18f7
Update src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/Dependenc…
adamperlin Feb 21, 2026
b4d651e
Update src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWrite…
adamperlin Feb 21, 2026
baeb5c2
Update src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wa…
adamperlin Feb 21, 2026
4f9f0c8
Update src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wa…
adamperlin Feb 21, 2026
fa953d0
Update src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wa…
adamperlin Feb 21, 2026
74a4ae5
Update src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wa…
adamperlin Feb 21, 2026
5bb1458
Resolve additional copilot feedback: dispose of original data stream …
adamperlin Feb 23, 2026
33e9aaa
Add Relocation.MaxSize field, and check against relocation buffer len…
adamperlin Feb 23, 2026
1ac1040
Merge branch 'main' of github.com:dotnet/runtime into adamperlin/wasm…
adamperlin Feb 23, 2026
977b80e
Fix ReadExactly in relocation resolution
adamperlin Feb 23, 2026
f42cf50
Update src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWrite…
adamperlin Feb 23, 2026
4095ea1
Address review feedback
adamperlin Feb 23, 2026
0117e07
Merge branch 'adamperlin/wasm-object-writer-type-relocs' of github.co…
adamperlin Feb 23, 2026
2aafc74
Update src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wa…
adamperlin Feb 23, 2026
056aab4
Address additional review feedback
adamperlin Feb 24, 2026
f6a37d1
Merge branch 'adamperlin/wasm-object-writer-type-relocs' of github.co…
adamperlin Feb 24, 2026
855894e
Remove unused usings
adamperlin Feb 24, 2026
7478bbf
Address review feedback
adamperlin Feb 25, 2026
97c3741
Update src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWrite…
adamperlin Feb 25, 2026
6f902e6
Update src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wa…
adamperlin Feb 26, 2026
4081472
Update src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wa…
adamperlin Feb 26, 2026
9f2448d
Update src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWrite…
adamperlin Feb 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/coreclr/jit/emitwasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ void emitter::emitIns_Call(const EmitCallParams& params)

// TODO-WASM: Generate actual list of types and generate reloc
// This is here to exercise the new JIT-EE API
CorInfoWasmType types[] = {CORINFO_WASM_TYPE_VOID};
CorInfoWasmType types[] = {CORINFO_WASM_TYPE_VOID, CORINFO_WASM_TYPE_I32, CORINFO_WASM_TYPE_I32};
Comment thread
adamperlin marked this conversation as resolved.
Resolved
CORINFO_WASM_TYPE_SYMBOL_HANDLE typeHandle =
codeGen->GetCompiler()->info.compCompHnd->getWasmTypeSymbol(types, 1);
codeGen->GetCompiler()->info.compCompHnd->getWasmTypeSymbol(types, 3);

id = emitNewInstrSC(EA_HANDLE_CNS_RELOC, (cnsval_ssize_t)(void*)typeHandle);
id->idIns(ins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,17 +637,14 @@ public static unsafe void WriteValue(RelocType relocType, void* location, long v
PutRiscV64AuipcCombo((uint*)location, value, isStype);
break;

case RelocType.WASM_FUNCTION_INDEX_LEB:
case RelocType.WASM_TABLE_INDEX_SLEB:
case RelocType.WASM_TYPE_INDEX_LEB:
case RelocType.WASM_GLOBAL_INDEX_LEB:
// These wasm relocs do not have offsets, just targets
return;

case RelocType.WASM_FUNCTION_INDEX_LEB:
case RelocType.WASM_MEMORY_ADDR_LEB:
DwarfHelper.WritePaddedULEB128(new Span<byte>((byte*)location, WASM_PADDED_RELOC_SIZE_32), checked((ulong)value));
return;

case RelocType.WASM_TABLE_INDEX_SLEB:
case RelocType.WASM_MEMORY_ADDR_SLEB:
DwarfHelper.WritePaddedSLEB128(new Span<byte>((byte*)location, WASM_PADDED_RELOC_SIZE_32), value);
return;
Expand All @@ -658,6 +655,9 @@ public static unsafe void WriteValue(RelocType relocType, void* location, long v
}
}

public static readonly int MaxSize = 8;
// Note: Please update the above field if the max size
// changes when adding a new case to this method.
public static int GetSize(RelocType relocType)
{
return relocType switch
Expand All @@ -681,6 +681,14 @@ public static int GetSize(RelocType relocType)
RelocType.IMAGE_REL_BASED_RISCV64_CALL_PLT => 8,
RelocType.IMAGE_REL_BASED_RISCV64_PCREL_I => 8,
RelocType.IMAGE_REL_BASED_RISCV64_PCREL_S => 8,

RelocType.WASM_FUNCTION_INDEX_LEB => WASM_PADDED_RELOC_SIZE_32,
RelocType.WASM_TABLE_INDEX_SLEB => WASM_PADDED_RELOC_SIZE_32,
RelocType.WASM_TYPE_INDEX_LEB => WASM_PADDED_RELOC_SIZE_32,
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,

_ => throw new NotSupportedException(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ protected internal enum ObjectNodeOrder
StackTraceEmbeddedMetadataNode,
StackTraceMethodMappingNode,
ArrayOfEmbeddedDataNode,

//
// Wasm type signatures (need to be emitted some time before the unordered phase)
//
WasmTypeNode,
}

public class EmbeddedObjectNodeComparer : IComparer<EmbeddedObjectNode>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,72 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;
using ILCompiler.DependencyAnalysis;
using Internal.JitInterface;
using ILCompiler.ObjectWriter;

namespace ILCompiler.DependencyAnalysis.Wasm
{
//
// Represents a WASM type signature, e.g. "(i32, i32) -> (i64)". Used as a relocation target for things like 'call_indirect'.
// Does not currently support multiple return values; the return type is always the first type in the array and may be Void.
Comment thread
adamperlin marked this conversation as resolved.
Resolved
//
public class WasmTypeNode : ObjectNode, ISymbolNode
public class WasmTypeNode : ObjectNode, ISymbolNode, ISymbolDefinitionNode
{
private readonly CorInfoWasmType[] _types;
private readonly WasmFuncType _type;
public WasmFuncType Type => _type;

public WasmTypeNode(CorInfoWasmType[] types)
public WasmTypeNode(WasmFuncType type)
{
_types = types;
_type = type;
}

public override bool IsShareable => true;

public override int ClassCode => -45678931;
protected internal override int Phase => (int)ObjectNodePhase.Ordered;

public override int ClassCode => (int)ObjectNodeOrder.WasmTypeNode;

public override bool StaticDependenciesAreComputed => true;

public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.WasmTypeSection;

protected override string GetName(NodeFactory factory)
=> $"Wasm Type ({string.Join(",", _types.Skip(1))}) -> {_types.FirstOrDefault()}";
=> $"Wasm Type Signature: {Type.ToString()}";

public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
=> new ObjectData(
Array.Empty<byte>(),
Array.Empty<Relocation>(),
1,
Array.Empty<ISymbolDefinitionNode>());
{
if (relocsOnly)
{
return new ObjectData(
data: Array.Empty<byte>(),
relocs: Array.Empty<Relocation>(),
alignment: 1,
definedSymbols: new ISymbolDefinitionNode[] { this });
}

byte[] data = new byte[_type.EncodeSize()];
_type.Encode(data);

return new ObjectData(
data: data,
relocs: Array.Empty<Relocation>(),
alignment: 1,
definedSymbols: new ISymbolDefinitionNode[] { this });
}

public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
{
var wtm = (WasmTypeNode)other;
ReadOnlySpan<CorInfoWasmType> lhs = _types, rhs = wtm._types;
var wtn = (WasmTypeNode)other;
// Put shorter signatures earlier in the sort order, on the assumption that they are more likely to be used.
int result = lhs.Length.CompareTo(rhs.Length);
int result = _type.SignatureLength.CompareTo(wtn.Type.SignatureLength);
if (result == 0)
result = MemoryExtensions.SequenceCompareTo(lhs, rhs);
return _type.CompareTo(wtn.Type);
return result;
}

public void AppendMangledName(NameMangler nameMangler, Internal.Text.Utf8StringBuilder sb)
{
sb.Append(nameMangler.CompilationUnitPrefix);
sb.Append("__wasmtype_"u8);

foreach (var type in _types)
sb.Append(type switch {
CorInfoWasmType.CORINFO_WASM_TYPE_VOID => 'v',
CorInfoWasmType.CORINFO_WASM_TYPE_V128 => 'V',
CorInfoWasmType.CORINFO_WASM_TYPE_F64 => 'd',
CorInfoWasmType.CORINFO_WASM_TYPE_F32 => 'f',
CorInfoWasmType.CORINFO_WASM_TYPE_I64 => 'j',
CorInfoWasmType.CORINFO_WASM_TYPE_I32 => 'i',
_ => throw new NotImplementedException($"Unknown CorInfoWasmType: {type}"),
});
_type.AppendMangledName(nameMangler, sb);
}

public int Offset => 0;
Expand Down
Loading
Loading