Skip to content

Commit 2daa4bc

Browse files
authored
[browser][coreCLR] enable bigint (#121025)
1 parent b3a8d0d commit 2daa4bc

File tree

12 files changed

+61
-58
lines changed

12 files changed

+61
-58
lines changed

eng/native.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<ItemGroup>
1616
<NativeCMakeArg Condition="'$(_IcuDir)' != ''" Include="-cmakeargs &quot;-DCMAKE_ICU_DIR=$(_IcuDir)&quot;" />
1717
<NativeCMakeArg Condition="'$(_TzdDir)' != ''" Include="-cmakeargs &quot;-DCMAKE_TZD_DIR=$(_TzdDir)&quot;" />
18+
<NativeCMakeArg Condition="'$(RuntimeFlavor)' == 'Mono'" Include="-cmakeargs &quot;-DCLR_CMAKE_RUNTIME_MONO=1&quot;" />
19+
<NativeCMakeArg Condition="'$(RuntimeFlavor)' == 'CoreCLR'" Include="-cmakeargs &quot;-DCLR_CMAKE_RUNTIME_CORECLR=1&quot;" />
1820
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_PRODUCT_VERSION=$(ProductVersion)&quot;" />
1921
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_CONTINUOUS_INTEGRATION_BUILD=$(ContinuousIntegrationBuild)&quot;" />
2022
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_NET_CORE_APP_CURRENT_VERSION=$(NetCoreAppCurrentVersion)&quot;" />

eng/native/configureplatform.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,21 @@ if(NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
499499
endif()
500500

501501
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
502+
else()
503+
if(CLR_CMAKE_RUNTIME_CORECLR)
504+
if(CLR_CMAKE_TARGET_BROWSER)
505+
add_link_options(-fwasm-exceptions)
506+
add_link_options(-Wno-unused-command-line-argument)
507+
add_link_options(-Wl,-error-limit=0)
508+
509+
add_compile_options(-fwasm-exceptions)
510+
add_compile_options(-mbulk-memory)
511+
add_compile_options(-msimd128)
512+
endif()
513+
if(CLR_CMAKE_TARGET_WASI)
514+
add_compile_options(-fexceptions)
515+
endif()
516+
endif()
502517
endif()
503518

504519
if (CLR_CMAKE_HOST_ANDROID)

src/coreclr/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ endif()
3535

3636
OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
3737

38-
if (CLR_CMAKE_TARGET_ARCH_WASM)
39-
add_compile_options(
40-
-fwasm-exceptions
41-
-msimd128)
42-
add_link_options(
43-
-fwasm-exceptions
44-
)
45-
endif()
46-
4738
#----------------------------------------------------
4839
# Cross target Component build specific configuration
4940
#----------------------------------------------------

src/coreclr/gc/unix/cgroup.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class CGroup
6868
static void Initialize()
6969
{
7070
s_cgroup_version = FindCGroupVersion();
71-
FindCGroupPath(s_cgroup_version == 1 ? &IsCGroup1MemorySubsystem : nullptr, &s_memory_cgroup_path, &s_memory_cgroup_hierarchy_mount);
71+
if (s_cgroup_version != 0)
72+
{
73+
FindCGroupPath(s_cgroup_version == 1 ? &IsCGroup1MemorySubsystem : nullptr, &s_memory_cgroup_path, &s_memory_cgroup_hierarchy_mount);
74+
}
7275
}
7376

7477
static void Cleanup()
@@ -119,7 +122,7 @@ class CGroup
119122
// modes because both of those involve cgroup v1 controllers managing
120123
// resources.
121124

122-
#if !HAVE_NON_LEGACY_STATFS
125+
#if !HAVE_NON_LEGACY_STATFS || TARGET_WASM
123126
return 0;
124127
#else
125128

src/coreclr/gc/unix/gcenv.unix.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ typedef cpuset_t cpu_set_t;
108108
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN
109109
#endif
110110

111+
#ifdef __EMSCRIPTEN__
112+
#include <emscripten/heap.h>
113+
#endif // __EMSCRIPTEN__
114+
115+
111116
// The cached total number of CPUs that can be used in the OS.
112117
static uint32_t g_totalCpuCount = 0;
113118

@@ -814,7 +819,7 @@ static uint64_t GetMemorySizeMultiplier(char units)
814819
return 1;
815820
}
816821

817-
#if !defined(__APPLE__) && !defined(__HAIKU__)
822+
#if !defined(__APPLE__) && !defined(__HAIKU__) && !defined(__EMSCRIPTEN__)
818823
// Try to read the MemAvailable entry from /proc/meminfo.
819824
// Return true if the /proc/meminfo existed, the entry was present and we were able to parse it.
820825
static bool ReadMemAvailable(uint64_t* memAvailable)
@@ -1082,6 +1087,8 @@ uint64_t GetAvailablePhysicalMemory()
10821087
{
10831088
available = info.free_memory;
10841089
}
1090+
#elif defined(__EMSCRIPTEN__)
1091+
available = emscripten_get_heap_max() - emscripten_get_heap_size();
10851092
#else // Linux
10861093
static volatile bool tryReadMemInfo = true;
10871094

src/coreclr/hosts/corerun/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ else()
5656
System.Native.TimeZoneData.Invariant)
5757
# linker options for NodeJs, link in JavaScript helper, access to local filesystem
5858
if (CLR_CMAKE_TARGET_BROWSER)
59-
target_compile_options(corerun PRIVATE
60-
-fwasm-exceptions
61-
-msimd128
62-
)
6359
target_link_libraries(corerun PRIVATE
6460
System.Native.Browser-Static)
6561
set(JS_SYSTEM_NATIVE_BROWSER
@@ -73,12 +69,12 @@ else()
7369
LINK_FLAGS "--pre-js ${JS_CORE_RUN_PRE} --js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS}"
7470
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
7571
target_link_options(corerun PRIVATE
76-
-fwasm-exceptions
7772
-sEXIT_RUNTIME=1
7873
-sINITIAL_MEMORY=134217728
7974
-sMAXIMUM_MEMORY=2147483648
8075
-sALLOW_MEMORY_GROWTH=1
8176
-sSTACK_SIZE=5MB
77+
-sWASM_BIGINT=1
8278
-sEXPORTED_FUNCTIONS=_main,_GetDotNetRuntimeContractDescriptor
8379
-sENVIRONMENT=node,shell,web
8480
-Wl,-error-limit=0)

src/coreclr/interpreter/compiler.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ void InterpCompiler::LinkBBs(InterpBasicBlock *from, InterpBasicBlock *to)
461461
if (newCapacity > prevCapacity)
462462
{
463463
InterpBasicBlock **newa = (InterpBasicBlock**)AllocMemPool(newCapacity * sizeof(InterpBasicBlock*));
464-
memcpy(newa, from->ppOutBBs, from->outCount * sizeof(InterpBasicBlock*));
464+
if (from->outCount != 0)
465+
{
466+
memcpy(newa, from->ppOutBBs, from->outCount * sizeof(InterpBasicBlock*));
467+
}
465468
from->ppOutBBs = newa;
466469
}
467470
from->ppOutBBs [from->outCount] = to;
@@ -483,7 +486,9 @@ void InterpCompiler::LinkBBs(InterpBasicBlock *from, InterpBasicBlock *to)
483486
int newCapacity = GetBBLinksCapacity(to->inCount + 1);
484487
if (newCapacity > prevCapacity) {
485488
InterpBasicBlock **newa = (InterpBasicBlock**)AllocMemPool(newCapacity * sizeof(InterpBasicBlock*));
486-
memcpy(newa, to->ppInBBs, to->inCount * sizeof(InterpBasicBlock*));
489+
if (to->inCount != 0) {
490+
memcpy(newa, to->ppInBBs, to->inCount * sizeof(InterpBasicBlock*));
491+
}
487492
to->ppInBBs = newa;
488493
}
489494
to->ppInBBs [to->inCount] = from;
@@ -5300,7 +5305,10 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
53005305
// We need to realloc the IL code buffer to hold the extra opcodes
53015306

53025307
uint8_t* newILCode = (uint8_t*)AllocMemPool(newILCodeSize);
5303-
memcpy(newILCode, m_pILCode, m_ILCodeSize);
5308+
if (m_ILCodeSize != 0)
5309+
{
5310+
memcpy(newILCode, m_pILCode, m_ILCodeSize);
5311+
}
53045312
memcpy(newILCode + m_synchronizedFinallyStartOffset, opCodesForSynchronizedMethodFinally, sizeof(opCodesForSynchronizedMethodFinally));
53055313
memcpy(newILCode + m_synchronizedPostFinallyOffset, opCodesForSynchronizedMethodEpilog, sizeof(opCodesForSynchronizedMethodEpilog));
53065314
m_pILCode = newILCode;
@@ -5512,7 +5520,10 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
55125520
{
55135521
MergeStackTypeInfo(m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight);
55145522
// This is relevant only for copying the vars associated with the values on the stack
5515-
memcpy(m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight * sizeof(StackInfo));
5523+
if (pNewBB->stackHeight != 0)
5524+
{
5525+
memcpy(m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight * sizeof(StackInfo));
5526+
}
55165527
m_pStackPointer = m_pStackBase + pNewBB->stackHeight;
55175528
}
55185529
else
@@ -5527,7 +5538,10 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
55275538
if (pNewBB->stackHeight >= 0)
55285539
{
55295540
// This is relevant only for copying the vars associated with the values on the stack
5530-
memcpy (m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight * sizeof(StackInfo));
5541+
if (pNewBB->stackHeight != 0)
5542+
{
5543+
memcpy (m_pStackBase, pNewBB->pStackState, pNewBB->stackHeight * sizeof(StackInfo));
5544+
}
55315545
m_pStackPointer = m_pStackBase + pNewBB->stackHeight;
55325546
pNewBB->emitState = BBStateEmitting;
55335547
emittedBBlocks = true;

src/coreclr/pal/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,5 @@ include_directories(${COREPAL_SOURCE_DIR}/inc)
66
include_directories(${COREPAL_SOURCE_DIR}/src)
77
include_directories(${COREPAL_SOURCE_DIR}/../inc)
88

9-
if (NOT CLR_CMAKE_TARGET_BROWSER)
10-
add_compile_options(-fexceptions)
11-
else()
12-
add_compile_options(
13-
-fwasm-exceptions
14-
-msimd128
15-
)
16-
add_link_options(
17-
-fwasm-exceptions
18-
)
19-
endif()
20-
219
add_subdirectory(src)
2210
add_subdirectory(tests)

src/coreclr/pal/src/misc/cgroup.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ class CGroup
4949
static void Initialize()
5050
{
5151
s_cgroup_version = FindCGroupVersion();
52-
FindCGroupPath(s_cgroup_version == 1 ? &IsCGroup1CpuSubsystem : nullptr, &s_cpu_cgroup_path);
52+
if (s_cgroup_version != 0)
53+
{
54+
FindCGroupPath(s_cgroup_version == 1 ? &IsCGroup1CpuSubsystem : nullptr, &s_cpu_cgroup_path);
55+
}
5356
}
5457

5558
static void Cleanup()
@@ -84,7 +87,7 @@ class CGroup
8487
// modes because both of those involve cgroup v1 controllers managing
8588
// resources.
8689

87-
#if !HAVE_NON_LEGACY_STATFS
90+
#if !HAVE_NON_LEGACY_STATFS || TARGET_WASM
8891
return 0;
8992
#else
9093
struct statfs stats;

src/coreclr/vm/methodtablebuilder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3678,7 +3678,10 @@ VOID MethodTableBuilder::AllocateWorkingSlotTables()
36783678

36793679
// Allocate a FieldDesc* for each field
36803680
bmtMFDescs->ppFieldDescList = new (GetStackingAllocator()) FieldDesc*[bmtMetaData->cFields];
3681-
ZeroMemory(bmtMFDescs->ppFieldDescList, bmtMetaData->cFields * sizeof(FieldDesc *));
3681+
if (bmtMetaData->cFields != 0)
3682+
{
3683+
ZeroMemory(bmtMFDescs->ppFieldDescList, bmtMetaData->cFields * sizeof(FieldDesc *));
3684+
}
36823685

36833686
// Create a temporary function table (we don't know how large the vtable will be until the very end,
36843687
// since we don't yet know how many declared methods are overrides vs. newslots).

0 commit comments

Comments
 (0)