diff --git a/eng/native.props b/eng/native.props index 06b2cc035e9af4..6d7f605c9dbc17 100644 --- a/eng/native.props +++ b/eng/native.props @@ -15,6 +15,8 @@ + + diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index 5cd67cbadf69b2..ed9e67b5c32bd3 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -499,6 +499,21 @@ if(NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) +else() + if(CLR_CMAKE_RUNTIME_CORECLR) + if(CLR_CMAKE_TARGET_BROWSER) + add_link_options(-fwasm-exceptions) + add_link_options(-Wno-unused-command-line-argument) + add_link_options(-Wl,-error-limit=0) + + add_compile_options(-fwasm-exceptions) + add_compile_options(-mbulk-memory) + add_compile_options(-msimd128) + endif() + if(CLR_CMAKE_TARGET_WASI) + add_compile_options(-fexceptions) + endif() + endif() endif() if (CLR_CMAKE_HOST_ANDROID) diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 002f34965f950f..cc85821174ae46 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -35,15 +35,6 @@ endif() OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF) -if (CLR_CMAKE_TARGET_ARCH_WASM) - add_compile_options( - -fwasm-exceptions - -msimd128) - add_link_options( - -fwasm-exceptions - ) -endif() - #---------------------------------------------------- # Cross target Component build specific configuration #---------------------------------------------------- diff --git a/src/coreclr/gc/unix/cgroup.cpp b/src/coreclr/gc/unix/cgroup.cpp index 8389e8692bf00d..ff1712235a339d 100644 --- a/src/coreclr/gc/unix/cgroup.cpp +++ b/src/coreclr/gc/unix/cgroup.cpp @@ -68,7 +68,10 @@ class CGroup static void Initialize() { s_cgroup_version = FindCGroupVersion(); - FindCGroupPath(s_cgroup_version == 1 ? &IsCGroup1MemorySubsystem : nullptr, &s_memory_cgroup_path, &s_memory_cgroup_hierarchy_mount); + if (s_cgroup_version != 0) + { + FindCGroupPath(s_cgroup_version == 1 ? &IsCGroup1MemorySubsystem : nullptr, &s_memory_cgroup_path, &s_memory_cgroup_hierarchy_mount); + } } static void Cleanup() @@ -119,7 +122,7 @@ class CGroup // modes because both of those involve cgroup v1 controllers managing // resources. -#if !HAVE_NON_LEGACY_STATFS +#if !HAVE_NON_LEGACY_STATFS || TARGET_WASM return 0; #else diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index e67e8a8d818d4c..1295f7d0a138a9 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -108,6 +108,11 @@ typedef cpuset_t cpu_set_t; #define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN #endif +#ifdef __EMSCRIPTEN__ +#include +#endif // __EMSCRIPTEN__ + + // The cached total number of CPUs that can be used in the OS. static uint32_t g_totalCpuCount = 0; @@ -814,7 +819,7 @@ static uint64_t GetMemorySizeMultiplier(char units) return 1; } -#if !defined(__APPLE__) && !defined(__HAIKU__) +#if !defined(__APPLE__) && !defined(__HAIKU__) && !defined(__EMSCRIPTEN__) // Try to read the MemAvailable entry from /proc/meminfo. // Return true if the /proc/meminfo existed, the entry was present and we were able to parse it. static bool ReadMemAvailable(uint64_t* memAvailable) @@ -1082,6 +1087,8 @@ uint64_t GetAvailablePhysicalMemory() { available = info.free_memory; } +#elif defined(__EMSCRIPTEN__) + available = emscripten_get_heap_max() - emscripten_get_heap_size(); #else // Linux static volatile bool tryReadMemInfo = true; diff --git a/src/coreclr/hosts/corerun/CMakeLists.txt b/src/coreclr/hosts/corerun/CMakeLists.txt index 73b5ddd777032a..09a425da61bf85 100644 --- a/src/coreclr/hosts/corerun/CMakeLists.txt +++ b/src/coreclr/hosts/corerun/CMakeLists.txt @@ -56,10 +56,6 @@ else() System.Native.TimeZoneData.Invariant) # linker options for NodeJs, link in JavaScript helper, access to local filesystem if (CLR_CMAKE_TARGET_BROWSER) - target_compile_options(corerun PRIVATE - -fwasm-exceptions - -msimd128 - ) target_link_libraries(corerun PRIVATE System.Native.Browser-Static) set(JS_SYSTEM_NATIVE_BROWSER @@ -73,12 +69,12 @@ else() LINK_FLAGS "--pre-js ${JS_CORE_RUN_PRE} --js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") target_link_options(corerun PRIVATE - -fwasm-exceptions -sEXIT_RUNTIME=1 -sINITIAL_MEMORY=134217728 -sMAXIMUM_MEMORY=2147483648 -sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=5MB + -sWASM_BIGINT=1 -sEXPORTED_FUNCTIONS=_main,_GetDotNetRuntimeContractDescriptor -sENVIRONMENT=node,shell,web -Wl,-error-limit=0) diff --git a/src/coreclr/interpreter/compiler.cpp b/src/coreclr/interpreter/compiler.cpp index 96fb5630c9cbd2..45d931af5529aa 100644 --- a/src/coreclr/interpreter/compiler.cpp +++ b/src/coreclr/interpreter/compiler.cpp @@ -461,7 +461,10 @@ void InterpCompiler::LinkBBs(InterpBasicBlock *from, InterpBasicBlock *to) if (newCapacity > prevCapacity) { InterpBasicBlock **newa = (InterpBasicBlock**)AllocMemPool(newCapacity * sizeof(InterpBasicBlock*)); - memcpy(newa, from->ppOutBBs, from->outCount * sizeof(InterpBasicBlock*)); + if (from->outCount != 0) + { + memcpy(newa, from->ppOutBBs, from->outCount * sizeof(InterpBasicBlock*)); + } from->ppOutBBs = newa; } from->ppOutBBs [from->outCount] = to; @@ -483,7 +486,9 @@ void InterpCompiler::LinkBBs(InterpBasicBlock *from, InterpBasicBlock *to) int newCapacity = GetBBLinksCapacity(to->inCount + 1); if (newCapacity > prevCapacity) { InterpBasicBlock **newa = (InterpBasicBlock**)AllocMemPool(newCapacity * sizeof(InterpBasicBlock*)); - memcpy(newa, to->ppInBBs, to->inCount * sizeof(InterpBasicBlock*)); + if (to->inCount != 0) { + memcpy(newa, to->ppInBBs, to->inCount * sizeof(InterpBasicBlock*)); + } to->ppInBBs = newa; } to->ppInBBs [to->inCount] = from; @@ -5300,7 +5305,10 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo) // We need to realloc the IL code buffer to hold the extra opcodes uint8_t* newILCode = (uint8_t*)AllocMemPool(newILCodeSize); - memcpy(newILCode, m_pILCode, m_ILCodeSize); + if (m_ILCodeSize != 0) + { + memcpy(newILCode, m_pILCode, m_ILCodeSize); + } memcpy(newILCode + m_synchronizedFinallyStartOffset, opCodesForSynchronizedMethodFinally, sizeof(opCodesForSynchronizedMethodFinally)); memcpy(newILCode + m_synchronizedPostFinallyOffset, opCodesForSynchronizedMethodEpilog, sizeof(opCodesForSynchronizedMethodEpilog)); m_pILCode = newILCode; @@ -5512,7 +5520,10 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo) { MergeStackTypeInfo(m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight); // This is relevant only for copying the vars associated with the values on the stack - memcpy(m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight * sizeof(StackInfo)); + if (pNewBB->stackHeight != 0) + { + memcpy(m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight * sizeof(StackInfo)); + } m_pStackPointer = m_pStackBase + pNewBB->stackHeight; } else @@ -5527,7 +5538,10 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo) if (pNewBB->stackHeight >= 0) { // This is relevant only for copying the vars associated with the values on the stack - memcpy (m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight * sizeof(StackInfo)); + if (pNewBB->stackHeight != 0) + { + memcpy (m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight * sizeof(StackInfo)); + } m_pStackPointer = m_pStackBase + pNewBB->stackHeight; pNewBB->emitState = BBStateEmitting; emittedBBlocks = true; diff --git a/src/coreclr/pal/CMakeLists.txt b/src/coreclr/pal/CMakeLists.txt index 7c83e540be6907..580bccb7cd6301 100644 --- a/src/coreclr/pal/CMakeLists.txt +++ b/src/coreclr/pal/CMakeLists.txt @@ -6,17 +6,5 @@ include_directories(${COREPAL_SOURCE_DIR}/inc) include_directories(${COREPAL_SOURCE_DIR}/src) include_directories(${COREPAL_SOURCE_DIR}/../inc) -if (NOT CLR_CMAKE_TARGET_BROWSER) - add_compile_options(-fexceptions) -else() - add_compile_options( - -fwasm-exceptions - -msimd128 - ) - add_link_options( - -fwasm-exceptions - ) -endif() - add_subdirectory(src) add_subdirectory(tests) diff --git a/src/coreclr/pal/src/misc/cgroup.cpp b/src/coreclr/pal/src/misc/cgroup.cpp index 427e9ef1301ff2..f4110c08ff42cb 100644 --- a/src/coreclr/pal/src/misc/cgroup.cpp +++ b/src/coreclr/pal/src/misc/cgroup.cpp @@ -49,7 +49,10 @@ class CGroup static void Initialize() { s_cgroup_version = FindCGroupVersion(); - FindCGroupPath(s_cgroup_version == 1 ? &IsCGroup1CpuSubsystem : nullptr, &s_cpu_cgroup_path); + if (s_cgroup_version != 0) + { + FindCGroupPath(s_cgroup_version == 1 ? &IsCGroup1CpuSubsystem : nullptr, &s_cpu_cgroup_path); + } } static void Cleanup() @@ -84,7 +87,7 @@ class CGroup // modes because both of those involve cgroup v1 controllers managing // resources. -#if !HAVE_NON_LEGACY_STATFS +#if !HAVE_NON_LEGACY_STATFS || TARGET_WASM return 0; #else struct statfs stats; diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index 1195153c5b12b8..12ff81c1181d7f 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -3678,7 +3678,10 @@ VOID MethodTableBuilder::AllocateWorkingSlotTables() // Allocate a FieldDesc* for each field bmtMFDescs->ppFieldDescList = new (GetStackingAllocator()) FieldDesc*[bmtMetaData->cFields]; - ZeroMemory(bmtMFDescs->ppFieldDescList, bmtMetaData->cFields * sizeof(FieldDesc *)); + if (bmtMetaData->cFields != 0) + { + ZeroMemory(bmtMFDescs->ppFieldDescList, bmtMetaData->cFields * sizeof(FieldDesc *)); + } // Create a temporary function table (we don't know how large the vtable will be until the very end, // since we don't yet know how many declared methods are overrides vs. newslots). diff --git a/src/native/corehost/browserhost/CMakeLists.txt b/src/native/corehost/browserhost/CMakeLists.txt index 5f79d7d92a8eff..5a9cc782f721a7 100644 --- a/src/native/corehost/browserhost/CMakeLists.txt +++ b/src/native/corehost/browserhost/CMakeLists.txt @@ -24,10 +24,6 @@ add_library(BrowserHost-Static ) set_target_properties(BrowserHost-Static PROPERTIES OUTPUT_NAME BrowserHost CLEAN_DIRECT_OUTPUT 1) -target_compile_options(BrowserHost-Static PRIVATE - -fwasm-exceptions - -msimd128 - ) target_link_libraries(BrowserHost-Static PRIVATE hostmisc ) @@ -97,11 +93,6 @@ set_target_properties(browserhost PROPERTIES LINK_FLAGS "--js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS} --js-library ${JS_SYSTEM_RUNTIME_INTEROPSERVICES_JAVASCRIPT_NATIVE} --js-library ${JS_BROWSER_HOST} --extern-post-js ${JS_SYSTEM_NATIVE_BROWSER_EXPOST}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") -target_compile_options(browserhost PRIVATE - -fwasm-exceptions - -msimd128 - ) - if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG) target_link_options(browserhost PRIVATE # -sVERBOSE @@ -112,7 +103,6 @@ if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG) ) endif () -# WASM-TODO -sWASM_BIGINT=1 # WASM-TODO -emit-llvm # WASM-TODO --source-map-base http://microsoft.com target_link_options(browserhost PRIVATE @@ -120,16 +110,14 @@ target_link_options(browserhost PRIVATE -sMAXIMUM_MEMORY=2147483648 -sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=5MB + -sWASM_BIGINT=1 -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXIT_RUNTIME=0 -sEXPORTED_RUNTIME_METHODS=UTF8ToString,cwrap,ccall,HEAPU8,HEAPU32,HEAPU64,BROWSER_HOST -sEXPORTED_FUNCTIONS=_posix_memalign,_free,stackAlloc,stackRestore,stackSave,_BrowserHost_InitializeCoreCLR,_BrowserHost_ExecuteAssembly,___cpp_exception -sEXPORT_NAME=createDotnetRuntime - -fwasm-exceptions - -lnodefs.js - -Wno-unused-command-line-argument - -Wl,-error-limit=0) + -lnodefs.js) target_link_libraries(browserhost PUBLIC BrowserHost-Static diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 26c19240be13bb..5c2c01c8bcdc96 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -68,13 +68,6 @@ if(NOT CLR_CMAKE_TARGET_ARCH_WASM) else() set(TEST_LIB_TYPE STATIC) - add_compile_options( - -fwasm-exceptions - -msimd128) - add_link_options( - -fwasm-exceptions - ) - # opt in into tests that make sense for WASM add_subdirectory(JIT/interpreter) endif()