Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,14 @@ if (CLR_CMAKE_HOST_WIN32)
message(FATAL_ERROR "MC not found")
endif()

elseif (NOT CLR_CMAKE_HOST_BROWSER AND NOT CLR_CMAKE_HOST_WASI)
elseif (CLR_CMAKE_HOST_BROWSER OR CLR_CMAKE_HOST_WASI)
# The wasm toolchains (emscripten / wasi-sdk) use clang, which can assemble
# preprocessed (.S) wasm assembly files directly.
set (CMAKE_ASM_COMPILER_VERSION "${CMAKE_C_COMPILER_VERSION}")

enable_language(ASM)

else()
# This is a workaround for upstream issue: https://gitlab.kitware.com/cmake/cmake/-/issues/22995.
#
# In Clang.cmake, the decision to use single or double hyphen for target and gcc-toolchain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ public DelayLoadHelperImport(
_useJumpableStub = useJumpableStub;
if (factory.Target.Architecture == TargetArchitecture.Wasm32)
{
if (instanceSignature is GenericLookupSignature)
{
// Generic lookups are resolved via eager fixups and don't need import thunks
_delayLoadHelper = null;
}
else
{
_delayLoadHelper = factory.WasmImportThunkPortableEntrypoint(this);
}
_delayLoadHelper = factory.WasmImportThunkPortableEntrypoint(this);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public override int CompareToImpl(ISortableNode other, CompilerComparer comparer

private static readonly WasmSignature _genericLookupSignature32Bit = new WasmSignature(
new WasmFuncType(
new WasmResultType(new[] { WasmValueType.I32, WasmValueType.I32 }),
new WasmResultType(new[] { WasmValueType.I32, WasmValueType.I32, WasmValueType.I32 }),
new WasmResultType(new[] { WasmValueType.I32 })),
"iii");
"iip");
private static readonly WasmSignature _genericLookupSignature64Bit = new WasmSignature(
new WasmFuncType(
new WasmResultType(new[] { WasmValueType.I64, WasmValueType.I64 }),
new WasmResultType(new[] { WasmValueType.I64, WasmValueType.I64, WasmValueType.I64 }),
new WasmResultType(new[] { WasmValueType.I64 })),
"lll");
"llp");

public override ObjectData GetData(NodeFactory factory, System.Boolean relocsOnly = false)
{
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -943,12 +943,17 @@ elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)
elseif(CLR_CMAKE_TARGET_ARCH_WASM)
set(VM_HEADERS_WKS_ARCH_ASM
${ARCH_SOURCES_DIR}/entrypoints.h
${ARCH_SOURCES_DIR}/asmconstants.h
)
set(VM_SOURCES_WKS_ARCH_ASM
${ARCH_SOURCES_DIR}/dynamichelpers.S
)
set(VM_SOURCES_WKS_ARCH
${RUNTIME_DIR}/${ARCH_SOURCES_DIR}/writebarriers.cpp
${ARCH_SOURCES_DIR}/calldescrworkerwasm.cpp
${ARCH_SOURCES_DIR}/profiler.cpp
${ARCH_SOURCES_DIR}/helpers.cpp
${ARCH_SOURCES_DIR}/dynamichelpers.cpp
exceptionhandling.cpp
gcinfodecoder.cpp
)
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/cgensys.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ extern "C" PCODE STDCALL DelayLoad_MethodCall(TransitionBlock* pTransitionBlock,
extern "C" void STDCALL DelayLoad_MethodCall();
#endif

#ifdef TARGET_WASM
extern "C" SIZE_T STDCALL DelayLoad_Helper(TransitionBlock* pTransitionBlock, READYTORUN_IMPORT_THUNK_PORTABLE_ENTRYPOINT* pImportThunkEntry, uint8_t *moduleBase, int32_t rvaOfModuleFixup);
#else
extern "C" void STDCALL DelayLoad_Helper();
#endif
extern "C" void STDCALL DelayLoad_Helper_Obj();
extern "C" void STDCALL DelayLoad_Helper_ObjObj();
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10869,6 +10869,9 @@ void CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN
{
helperMD = GetMethodDescForILBasedDynamicJitHelper(dynamicFtnNum);
_ASSERTE(PortableEntryPoint::GetMethodDesc((PCODE)targetAddr) == helperMD);
#ifdef FEATURE_READYTORUN
_ASSERTE(PortableEntryPoint::GetActualCode((PCODE)targetAddr) != NULL);
#endif
}

#else // !FEATURE_PORTABLE_ENTRYPOINTS
Expand Down
21 changes: 17 additions & 4 deletions src/coreclr/vm/prestub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3361,7 +3361,17 @@ PCODE DynamicHelperFixup(TransitionBlock * pTransitionBlock, TADDR * pCell, DWOR

RVA rva = pNativeImage->GetDataRva((TADDR)pCell);

PTR_READYTORUN_IMPORT_SECTION pImportSection = pModule->GetImportSectionFromIndex(sectionIndex);
PTR_READYTORUN_IMPORT_SECTION pImportSection;
if (sectionIndex != (DWORD)-1)
{
pImportSection = pModule->GetImportSectionFromIndex(sectionIndex);
_ASSERTE(pImportSection == pModule->GetImportSectionForRVA(rva));
}
else
{
pImportSection = pModule->GetImportSectionForRVA(rva);
}

_ASSERTE(pImportSection == pModule->GetImportSectionForRVA(rva));

_ASSERTE(pImportSection->EntrySize == sizeof(TADDR));
Expand Down Expand Up @@ -3392,6 +3402,7 @@ PCODE DynamicHelperFixup(TransitionBlock * pTransitionBlock, TADDR * pCell, DWOR

switch (kind)
{
#ifndef TARGET_WASM
case READYTORUN_FIXUP_NewObject:
th = ZapSig::DecodeType(pModule, pInfoModule, pBlob);
th.AsMethodTable()->EnsureInstanceActive();
Expand Down Expand Up @@ -3443,7 +3454,7 @@ PCODE DynamicHelperFixup(TransitionBlock * pTransitionBlock, TADDR * pCell, DWOR
pMD->EnsureActive();
}
break;

#endif // !TARGET_WASM
case READYTORUN_FIXUP_ThisObjDictionaryLookup:
case READYTORUN_FIXUP_TypeDictionaryLookup:
case READYTORUN_FIXUP_MethodDictionaryLookup:
Expand All @@ -3464,6 +3475,7 @@ PCODE DynamicHelperFixup(TransitionBlock * pTransitionBlock, TADDR * pCell, DWOR
{
switch (kind)
{
#ifndef TARGET_WASM
case READYTORUN_FIXUP_IsInstanceOf:
case READYTORUN_FIXUP_ChkCast:
{
Expand Down Expand Up @@ -3553,7 +3565,7 @@ PCODE DynamicHelperFixup(TransitionBlock * pTransitionBlock, TADDR * pCell, DWOR
}
}
break;

#endif // !TARGET_WASM
default:
UNREACHABLE();
}
Expand All @@ -3577,6 +3589,7 @@ PCODE DynamicHelperFixup(TransitionBlock * pTransitionBlock, TADDR * pCell, DWOR
{
switch (kind)
{
#ifndef TARGET_WASM
case READYTORUN_FIXUP_NewObject:
{
bool fHasSideEffectsUnused;
Expand Down Expand Up @@ -3650,7 +3663,7 @@ PCODE DynamicHelperFixup(TransitionBlock * pTransitionBlock, TADDR * pCell, DWOR
}
}
break;

#endif // !TARGET_WASM
case READYTORUN_FIXUP_ThisObjDictionaryLookup:
case READYTORUN_FIXUP_TypeDictionaryLookup:
case READYTORUN_FIXUP_MethodDictionaryLookup:
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/vm/readytoruninfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ struct GenericDictionaryDynamicHelperStubData
GenericHandleArgs *HandleArgs;
};

#ifdef FEATURE_PORTABLE_ENTRYPOINTS
struct GenericDictionaryDynamicHelperStubData_PortableEntryPoint
{
PCODE HelperFunctionTableIndex;
GenericDictionaryDynamicHelperStubData stubData;
};
#endif

class ReadyToRunLoadedImage
{
TADDR m_pImageBase;
Expand Down
50 changes: 50 additions & 0 deletions src/coreclr/vm/wasm/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,55 @@
// Be sure to rebuild clr/src/vm/ceemain.cpp after changing this file, to
// ensure that the constants match the expected C/C++ values

#ifndef ASMCONSTANTS_C_ASSERT
#define ASMCONSTANTS_C_ASSERT(cond)
#endif

#ifndef ASMCONSTANTS_RUNTIME_ASSERT
#define ASMCONSTANTS_RUNTIME_ASSERT(cond)
#endif

// Some constants are different in _DEBUG builds. This macro factors out ifdefs from below.
#ifdef _DEBUG
#define DBG_FRE(dbg,fre) dbg
#else
#define DBG_FRE(dbg,fre) fre
#endif

#define DynamicHelperFrameFlags_ObjectArg 1
#define DynamicHelperFrameFlags_ObjectArg2 2

#define OFFSETOF__MethodTable__m_pPerInstInfo DBG_FRE(0x24, 0x20)
ASMCONSTANTS_C_ASSERT(OFFSETOF__MethodTable__m_pPerInstInfo
== offsetof(MethodTable, m_pPerInstInfo));

#define OFFSETOF__InstantiatedMethodDesc__m_pPerInstInfo DBG_FRE(0x28, 0x14)
ASMCONSTANTS_C_ASSERT(OFFSETOF__InstantiatedMethodDesc__m_pPerInstInfo
== offsetof(InstantiatedMethodDesc, m_pPerInstInfo));

#define OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__stubData 0x04
ASMCONSTANTS_C_ASSERT(OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__stubData
== offsetof(GenericDictionaryDynamicHelperStubData_PortableEntryPoint, stubData));

#define OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__SecondIndir 0x4
ASMCONSTANTS_C_ASSERT(OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__SecondIndir
== offsetof(GenericDictionaryDynamicHelperStubData, SecondIndir) + offsetof(GenericDictionaryDynamicHelperStubData_PortableEntryPoint, stubData));

#define OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__LastIndir 0x8
ASMCONSTANTS_C_ASSERT(OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__LastIndir
== offsetof(GenericDictionaryDynamicHelperStubData, LastIndir) + offsetof(GenericDictionaryDynamicHelperStubData_PortableEntryPoint, stubData));

#define OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__SizeOffset 0xC
ASMCONSTANTS_C_ASSERT(OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__SizeOffset
== offsetof(GenericDictionaryDynamicHelperStubData, SizeOffset) + offsetof(GenericDictionaryDynamicHelperStubData_PortableEntryPoint, stubData));

#define OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__SlotOffset 0x10
ASMCONSTANTS_C_ASSERT(OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__SlotOffset
== offsetof(GenericDictionaryDynamicHelperStubData, SlotOffset) + offsetof(GenericDictionaryDynamicHelperStubData_PortableEntryPoint, stubData));

#define OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__HandleArgs 0x14
ASMCONSTANTS_C_ASSERT(OFFSETOF__GenericDictionaryDynamicHelperStubData_PortableEntryPoint__HandleArgs
== offsetof(GenericDictionaryDynamicHelperStubData, HandleArgs) + offsetof(GenericDictionaryDynamicHelperStubData_PortableEntryPoint, stubData));

#undef ASMCONSTANTS_RUNTIME_ASSERT
#undef ASMCONSTANTS_C_ASSERT
Loading
Loading