Skip to content

Commit

Permalink
Enable writeable data for WASM
Browse files Browse the repository at this point in the history
This is going upstream.
  • Loading branch information
SingleAccretion committed Jan 21, 2024
1 parent 1e2fe0d commit e61d726
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ internal static bool SupportsWritableData
{
get
{
// For now just key this off of SupportsRelativePointer to avoid this on both CppCodegen and WASM.
return SupportsRelativePointers;
return true;
}
}

Expand Down Expand Up @@ -1184,7 +1183,7 @@ internal void* WritableData

uint offset = GetFieldOffset(EETypeField.ETF_WritableData);

if (!IsDynamicType)
if (!IsDynamicType && SupportsRelativePointers)
return (void*)GetField<RelativePointer>(offset).Value;
else
return (void*)GetField<Pointer>(offset).Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public EETypeNode(NodeFactory factory, TypeDesc type)
factory.TypeSystemContext.EnsureLoadableType(type);
}

public static bool SupportsWritableData(TargetDetails target)
=> target.SupportsRelativePointers;
public static bool SupportsWritableData(TargetDetails target) => true;

public static bool SupportsFrozenRuntimeTypeInstances(TargetDetails target)
=> SupportsWritableData(target);
Expand Down Expand Up @@ -1125,11 +1124,17 @@ protected void OutputWritableData(NodeFactory factory, ref ObjectDataBuilder obj
{
if (_writableDataNode != null)
{
objData.EmitReloc(_writableDataNode, RelocType.IMAGE_REL_BASED_RELPTR32);
if (factory.Target.SupportsRelativePointers)
objData.EmitReloc(_writableDataNode, RelocType.IMAGE_REL_BASED_RELPTR32);
else
objData.EmitPointerReloc(_writableDataNode);
}
else if (SupportsWritableData(factory.Target))
{
objData.EmitInt(0);
if (factory.Target.SupportsRelativePointers)
objData.EmitInt(0);
else
objData.EmitZeroPointer();
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/tools/aot/ILCompiler.LLVM/CodeGen/LLVMObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ private void EmitObjectNode(ObjectNode node, ObjectData nodeContents)
if (nextRelocValid)
{
Relocation reloc = nodeContents.Relocs[relocIndex];
Debug.Assert(IsSupportedRelocType(node, reloc.RelocType), $"{reloc.RelocType} in {node} not supported");

long delta;
fixed (void* location = &data[reloc.Offset])
{
Expand Down Expand Up @@ -313,6 +315,16 @@ private void EmitObjectNode(ObjectNode node, ObjectData nodeContents)
}
}

private static bool IsSupportedRelocType(ObjectNode node, RelocType type)
{
if (node is StackTraceMethodMappingNode)
{
// Stack trace metadata uses relative pointers, but is currently unused.
return true;
}
return type is RelocType.IMAGE_REL_BASED_HIGHLOW;
}

private void EmitSymbolDef(LLVMValueRef baseSymbol, ReadOnlySpan<byte> symbolIdentifier, int offsetFromBaseSymbol)
{
LLVMValueRef symbolAddress = baseSymbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ private static int Main()
TestReadOnlySpan.Run();
TestStaticInterfaceMethod.Run();
TestConstrainedCall.Run();
#if !CODEGEN_WASM
TestTypeHandles.Run();
#endif
TestIsValueType.Run();
TestIndirectLoads.Run();
TestInitBlock.Run();
Expand Down

0 comments on commit e61d726

Please sign in to comment.