diff --git a/eng/native.wasm.targets b/eng/native.wasm.targets index 6df6de93a22b55..8b86ba9b2df243 100644 --- a/eng/native.wasm.targets +++ b/eng/native.wasm.targets @@ -81,6 +81,7 @@ + <_EmccExportedRuntimeMethods>@(EmccExportedRuntimeMethod -> '%(Identity)',',') diff --git a/eng/native/configureoptimization.cmake b/eng/native/configureoptimization.cmake index 9669115fc931a4..f568203c726d3e 100644 --- a/eng/native/configureoptimization.cmake +++ b/eng/native/configureoptimization.cmake @@ -9,6 +9,9 @@ elseif(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_TARGET_ANDROID) # -O2 optimization generates faster/smaller code on Android add_compile_options($<$:-O2>) + elseif (CLR_CMAKE_TARGET_BROWSER) + # -O2 prevents emscripten metadce from stripping user-requested global exports + add_link_options($<$:-O2>) else() add_compile_options($<$:-O3>) endif() diff --git a/src/coreclr/hosts/corerun/CMakeLists.txt b/src/coreclr/hosts/corerun/CMakeLists.txt index 31d3d0acf2a69d..93909d44fe034c 100644 --- a/src/coreclr/hosts/corerun/CMakeLists.txt +++ b/src/coreclr/hosts/corerun/CMakeLists.txt @@ -89,9 +89,11 @@ else() -sEXPORT_ES6=1 -sEXIT_RUNTIME=1 -sEXPORTED_RUNTIME_METHODS=CORERUN,ENV,${CMAKE_EMCC_EXPORTED_RUNTIME_METHODS} - -sEXPORTED_FUNCTIONS=_main,___stack_pointer,${CMAKE_EMCC_EXPORTED_FUNCTIONS} + -sEXPORTED_FUNCTIONS=_main,${CMAKE_EMCC_EXPORTED_FUNCTIONS} -sEXPORT_NAME=createDotnetRuntime -sENVIRONMENT=node,shell,web + -lexports.js + -Wl,--export=__stack_pointer -Wl,--error-limit=0) if (CORERUN_IN_BROWSER) diff --git a/src/mono/browser/build/BrowserWasmApp.CoreCLR.targets b/src/mono/browser/build/BrowserWasmApp.CoreCLR.targets index 74d7508e710171..40b486404316fd 100644 --- a/src/mono/browser/build/BrowserWasmApp.CoreCLR.targets +++ b/src/mono/browser/build/BrowserWasmApp.CoreCLR.targets @@ -555,7 +555,6 @@ <_EmccLinkStepArgs Include="-s EXPORT_ES6=1" /> - <_EmccLinkStepArgs Include="-lexports.js" /> <_EmccLinkStepArgs Include="-s INITIAL_MEMORY=$(WasmInitialHeapSize)" /> @@ -598,6 +597,11 @@ <_EmccLinkStepArgs Include="$(EmccExtraLDFlags)" /> + + <_EmccLinkStepArgs Include="-lexports.js" /> + + <_EmccLinkStepArgs Include="-Wl,--export=__stack_pointer" /> + <_EmccLinkStepArgs Include="-Wl,--error-limit=0" /> diff --git a/src/native/corehost/browserhost/CMakeLists.txt b/src/native/corehost/browserhost/CMakeLists.txt index ebba89e8c307c8..42f72ba5c0f911 100644 --- a/src/native/corehost/browserhost/CMakeLists.txt +++ b/src/native/corehost/browserhost/CMakeLists.txt @@ -122,6 +122,8 @@ target_link_options(browserhost PRIVATE -sEXPORT_NAME=createDotnetRuntime -sENVIRONMENT=web,webview,worker,node,shell --emit-symbol-map + -lexports.js + -Wl,--export=__stack_pointer -Wl,--error-limit=0) target_link_libraries(browserhost PRIVATE