diff options
author | Zoltan Varga <vargaz@gmail.com> | 2018-10-16 11:29:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-16 11:29:29 +0300 |
commit | 0beb087567017593f4992c8ab40dfbdddf3c6d8b (patch) | |
tree | 07bf42b6ea5e683ef9f70227acee91d85926c0f1 | |
parent | b71a4b76bbda471528431d07d7a58bd23b5d2d35 (diff) |
[WIP] [wasm] AOT work. (#11071)
* [runtime] Fix the signature of some native type tests.
* [runtime] Add stubs for the ves_icall_System_Net_NetworkInformation_MacOsIPInterfaceProperties_ParseRouteInfo_internal () icall, needed for AOT.
* [wasm] Print a native stack trace on asserts.
* [wasm] Avoid mmaps with zero length, it leads to an exception under emscripten.
* [bcl] Preserve CustomAttributeData:.ctor (), its called from the runtime.
* [wasm] Print out full test names in the test runner.
* [wasm] Preserve System.Threading.WasmRuntim.
* [wasm] Rename config.js to mono-config.js
* [wasm] Add targets to build aot versions of the test suites.
* [wasm] Exit with a nonzero exit code in case of a failure.
* [wasm] Disable crash reporting.
* [wasm] Use mono headers for public functions.
* [wasm] Enable building AOT tests on CI.
* [wasm] Run some AOT test suites on CI.
* [runtime] Make MonoBundledAssembly.size non-const.
* [wasm] Add a --setenv=VARIABLE=VALUE argument to runtime-tests.js which allows the setting of environment variables.
* [wasm] Update cross compiler executable name.
* [wasm] Remove unused aot-driver.js file, runtime-tests.js has the same functionality.
* [wasm] Run mini tests with AOT on CI.
* [wasm] Error out if the linker fails.
* [wasm] Fix building the AOT tests from another directory.
* [wasm] Use a matching Mono.Cecil.dll for the linker.
* [wasm] Fix running aot tests on CI.
* Revert "[sdks] Switch the invocation of the offsets too to 64 bit on osx. (#10903)"
This reverts commit 2989a83f23bc46ce5d44486bc33e0dc6d627270d.
This seems to cause failures on linux+webassembly.
-rw-r--r-- | mcs/class/corlib/LinkerDescriptor/mscorlib.xml | 7 | ||||
-rw-r--r-- | mono/metadata/assembly.h | 2 | ||||
-rw-r--r-- | mono/metadata/custom-attrs.c | 1 | ||||
-rw-r--r-- | mono/metadata/mono-route.c | 14 | ||||
-rw-r--r-- | mono/metadata/mono-route.h | 7 | ||||
-rw-r--r-- | mono/mini/builtin-types.cs | 6 | ||||
-rw-r--r-- | mono/utils/mono-mmap.c | 13 | ||||
-rwxr-xr-x | scripts/ci/run-jenkins.sh | 5 | ||||
-rw-r--r-- | sdks/builds/runtime.mk | 4 | ||||
-rw-r--r-- | sdks/builds/wasm.mk | 1 | ||||
-rw-r--r-- | sdks/wasm/Makefile | 51 | ||||
-rw-r--r-- | sdks/wasm/README.md | 6 | ||||
-rw-r--r-- | sdks/wasm/aot-driver.js | 126 | ||||
-rw-r--r-- | sdks/wasm/driver.c | 210 | ||||
-rw-r--r-- | sdks/wasm/incrementalrunner.cs | 2 | ||||
-rw-r--r-- | sdks/wasm/main.cs | 2 | ||||
-rw-r--r-- | sdks/wasm/packager.cs | 10 | ||||
-rw-r--r-- | sdks/wasm/runtime-tests.js | 49 |
18 files changed, 193 insertions, 323 deletions
diff --git a/mcs/class/corlib/LinkerDescriptor/mscorlib.xml b/mcs/class/corlib/LinkerDescriptor/mscorlib.xml index 2f7e2e7c8b0..6cdd34adde2 100644 --- a/mcs/class/corlib/LinkerDescriptor/mscorlib.xml +++ b/mcs/class/corlib/LinkerDescriptor/mscorlib.xml @@ -488,6 +488,11 @@ <type fullname="System.Reflection.AssemblyName" preserve="fields" /> <type fullname="System.Reflection.ConstructorInfo" preserve="fields" /> + <!-- custom-attr.c: create_custom_attr_data --> + <type fullname="System.Reflection.CustomAttributeData"> + <method signature="System.Void .ctor(System.Reflection.ConstructorInfo,System.Reflection.Assembly,System.IntPtr,System.UInt32)" /> + </type> + <!-- reflection.c: create_cattr_named_arg - create an instance with the ctor using 2 parameters --> <type fullname="System.Reflection.CustomAttributeNamedArgument"> <method signature="System.Void .ctor(System.Reflection.MemberInfo,System.Object)" /> @@ -807,5 +812,7 @@ <type fullname="Mono.RuntimeStructs/HandleStackMark" /> <!-- marshal.c (mono_marshal_get_native_wrapper) --> <type fullname="Mono.RuntimeStructs/MonoError" /> + + <type fullname="System.Threading.WasmRuntime"/> </assembly> </linker> diff --git a/mono/metadata/assembly.h b/mono/metadata/assembly.h index 79f566c4aad..19f44f3dd51 100644 --- a/mono/metadata/assembly.h +++ b/mono/metadata/assembly.h @@ -110,7 +110,7 @@ MONO_API void mono_assembly_name_free (MonoAssemblyName typedef struct { const char *name; const unsigned char *data; - const unsigned int size; + unsigned int size; } MonoBundledAssembly; MONO_API void mono_register_bundled_assemblies (const MonoBundledAssembly **assemblies); diff --git a/mono/metadata/custom-attrs.c b/mono/metadata/custom-attrs.c index 1ab39ac311f..ea1d7e240d3 100644 --- a/mono/metadata/custom-attrs.c +++ b/mono/metadata/custom-attrs.c @@ -1413,6 +1413,7 @@ create_custom_attr_data (MonoImage *image, MonoCustomAttrEntry *cattr, MonoError if (!ctor) { MonoMethod *tmp = mono_class_get_method_from_name_checked (cattr_data, ".ctor", 4, 0, error); mono_error_assert_ok (error); + g_assert (tmp); mono_memory_barrier (); //safe publish! ctor = tmp; diff --git a/mono/metadata/mono-route.c b/mono/metadata/mono-route.c index d4a7ffe3c2b..685d5ce1249 100644 --- a/mono/metadata/mono-route.c +++ b/mono/metadata/mono-route.c @@ -9,6 +9,9 @@ #include <config.h> +#include <mono/metadata/object.h> +#include <mono/metadata/mono-route.h> + #if defined(HOST_DARWIN) || defined(HOST_BSD) #include <sys/socket.h> #include <net/if.h> @@ -18,8 +21,6 @@ #include <sys/sysctl.h> #include <stdlib.h> #include <string.h> -#include <mono/metadata/object.h> -#include <mono/metadata/mono-route.h> extern MonoBoolean ves_icall_System_Net_NetworkInformation_MacOsIPInterfaceProperties_ParseRouteInfo_internal(MonoString *iface, MonoArray **gw_addr_list) { @@ -132,4 +133,13 @@ in_addr_t gateway_from_rtm(struct rt_msghdr *rtm) return 0; } +#else + +MonoBoolean +ves_icall_System_Net_NetworkInformation_MacOsIPInterfaceProperties_ParseRouteInfo_internal(MonoString *iface, MonoArray **gw_addr_list) +{ + g_assert_not_reached (); + return FALSE; +} + #endif /* #if defined(HOST_DARWIN) || defined(HOST_BSD) */ diff --git a/mono/metadata/mono-route.h b/mono/metadata/mono-route.h index dbe432855bb..e713d5c47c1 100644 --- a/mono/metadata/mono-route.h +++ b/mono/metadata/mono-route.h @@ -17,14 +17,15 @@ #include <net/route.h> #endif +in_addr_t gateway_from_rtm (struct rt_msghdr *rtm); + +#endif /* #if defined(HOST_DARWIN) || defined(HOST_BSD) */ + #include <mono/metadata/object-internals.h> #include <mono/metadata/icalls.h> -in_addr_t gateway_from_rtm (struct rt_msghdr *rtm); - /* Category icalls */ ICALL_EXPORT MonoBoolean ves_icall_System_Net_NetworkInformation_MacOsIPInterfaceProperties_ParseRouteInfo_internal (MonoString *iface, MonoArray **gw_addr_list); -#endif /* #if defined(HOST_DARWIN) || defined(HOST_BSD) */ #endif /* __MONO_ROUTE_H__ */ diff --git a/mono/mini/builtin-types.cs b/mono/mini/builtin-types.cs index 0596116571e..53b97a15c6d 100644 --- a/mono/mini/builtin-types.cs +++ b/mono/mini/builtin-types.cs @@ -382,7 +382,7 @@ public class BuiltinTests { } } - public int test_0_nint_fieldload () + static int test_0_nint_fieldload () { var x = new SomeNativeStructWithNint ((nint) 20f); @@ -783,7 +783,7 @@ public class BuiltinTests { } } - public int test_0_nuint_fieldload () + static int test_0_nuint_fieldload () { var x = new SomeNativeStructWithNuint ((nuint) 20f); @@ -1268,7 +1268,7 @@ public class BuiltinTests { } } - public int test_0_nfloat_fieldload () + static int test_0_nfloat_fieldload () { var x = new SomeNativeStructWithNfloat ((nfloat) 20f); diff --git a/mono/utils/mono-mmap.c b/mono/utils/mono-mmap.c index 05aa7a5c7a7..debf2ae37e6 100644 --- a/mono/utils/mono-mmap.c +++ b/mono/utils/mono-mmap.c @@ -250,6 +250,13 @@ mono_valloc (void *addr, size_t length, int flags, MonoMemAccountType type) mflags |= MAP_FIXED; if (flags & MONO_MMAP_32BIT) mflags |= MAP_32BIT; + +#ifdef HOST_WASM + if (length == 0) + /* emscripten throws an exception on 0 length */ + return NULL; +#endif + #if defined(__APPLE__) && defined(MAP_JIT) if (flags & MONO_MMAP_JIT) { if (get_darwin_version () >= DARWIN_VERSION_MOJAVE) { @@ -330,6 +337,12 @@ mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_hand if (flags & MONO_MMAP_32BIT) mflags |= MAP_32BIT; +#ifdef HOST_WASM + if (length == 0) + /* emscripten throws an exception on 0 length */ + return NULL; +#endif + BEGIN_CRITICAL_SECTION; ptr = mmap (0, length, prot, mflags, fd, offset); END_CRITICAL_SECTION; diff --git a/scripts/ci/run-jenkins.sh b/scripts/ci/run-jenkins.sh index a27594e5467..af98d05a07c 100755 --- a/scripts/ci/run-jenkins.sh +++ b/scripts/ci/run-jenkins.sh @@ -186,6 +186,8 @@ if [[ ${CI_TAGS} == *'webassembly'* ]]; echo "ENABLE_CXX=1" >> sdks/Make.config fi + export aot_test_suites="System.Core" + ${TESTCMD} --label=archive --timeout=180m --fatal make -j ${CI_CPU_COUNT} --output-sync=recurse --trace -C sdks/builds archive-wasm NINJA= ${TESTCMD} --label=wasm-build --timeout=60m --fatal make -j ${CI_CPU_COUNT} -C sdks/wasm build @@ -201,6 +203,9 @@ if [[ ${CI_TAGS} == *'webassembly'* ]]; ${TESTCMD} --label=v8-system-core --timeout=60m make -C sdks/wasm run-v8-system-core ${TESTCMD} --label=sm-system-core --timeout=60m make -C sdks/wasm run-sm-system-core ${TESTCMD} --label=jsc-system-core --timeout=60m make -C sdks/wasm run-jsc-system-core + ${TESTCMD} --label=aot-mini --timeout=60m make -j ${CI_CPU_COUNT} -C sdks/wasm run-aot-mini + ${TESTCMD} --label=build-aot-all --timeout=60m make -j ${CI_CPU_COUNT} -C sdks/wasm build-aot-all + for suite in ${aot_test_suites}; do ${TESTCMD} --label=run-aot-${suite} --timeout=10m make -C sdks/wasm run-aot-${suite}; done #${TESTCMD} --label=check-aot --timeout=60m make -C sdks/wasm check-aot ${TESTCMD} --label=package --timeout=60m make -C sdks/wasm package exit 0 diff --git a/sdks/builds/runtime.mk b/sdks/builds/runtime.mk index 81feed55af3..f4758d386d6 100644 --- a/sdks/builds/runtime.mk +++ b/sdks/builds/runtime.mk @@ -139,8 +139,8 @@ _cross-runtime_$(1)_CONFIGURE_FLAGS= \ $$(TOP)/sdks/builds/$(1)-$$(CONFIGURATION)/$(3).h: .stamp-$(1)-$$(CONFIGURATION)-configure $$(TOP)/tools/offsets-tool/MonoAotOffsetsDumper.exe | configure-$(4) cd $$(TOP)/sdks/builds/$(1)-$$(CONFIGURATION) && \ - MONO_PATH=$$(TOP)/tools/offsets-tool/CppSharp/$$(if $$(filter $$(UNAME),Darwin),osx_64,$$(if $$(filter $$(UNAME),Linux),linux_64,$$(error "Unknown UNAME='$$(UNAME)'"))) \ - mono --debug "$$(TOP)/tools/offsets-tool/MonoAotOffsetsDumper.exe" \ + MONO_PATH=$$(TOP)/tools/offsets-tool/CppSharp/$$(if $$(filter $$(UNAME),Darwin),osx_32,$$(if $$(filter $$(UNAME),Linux),linux_64,$$(error "Unknown UNAME='$$(UNAME)'"))) \ + mono $$(if $$(filter $$(UNAME),Darwin),--arch=32) --debug "$$(TOP)/tools/offsets-tool/MonoAotOffsetsDumper.exe" \ --abi $(6) --outfile "$$@" --mono "$$(TOP)" --targetdir "$$(TOP)/sdks/builds/$(4)-$$(CONFIGURATION)" \ $$(_$(1)_OFFSETS_DUMPER_ARGS) diff --git a/sdks/builds/wasm.mk b/sdks/builds/wasm.mk index 5c55bf9d469..ebca4bc8574 100644 --- a/sdks/builds/wasm.mk +++ b/sdks/builds/wasm.mk @@ -34,6 +34,7 @@ WASM_RUNTIME_CONFIGURE_FLAGS = \ --enable-llvm-runtime \ --enable-icall-export \ --disable-icall-tables \ + --disable-crash-reporting \ --with-bitcode=yes \ $(if $(ENABLE_CXX),--enable-cxx) \ CFLAGS="-fexceptions" diff --git a/sdks/wasm/Makefile b/sdks/wasm/Makefile index 5787e0fc792..9a01c374ac7 100644 --- a/sdks/wasm/Makefile +++ b/sdks/wasm/Makefile @@ -17,6 +17,7 @@ DRIVER_CONF=release EMSCRIPTEN_SDKDIR=$(TOP)/sdks/builds/toolchains/emsdk EMCC=source $(TOP)/sdks/builds/toolchains/emsdk/emsdk_env.sh && emcc WASM_BCL_DIR=$(TOP)/sdks/out/wasm-bcl/wasm +WASM_RUNTIME_DIR=$(TOP)/sdks/out/wasm-runtime-release MINI_PATH=$(TOP)/mono/mini CSC= MONO_PATH=$(TOP)/mcs/class/lib/build $(TOP)/sdks/builds/bcl/runtime/mono-wrapper $(CSC_LOCATION) CSC_FLAGS := /debug:portable /noconfig /nostdlib /nologo /langversion:latest @@ -69,7 +70,7 @@ jsup: toolchain: .stamp-jsvu driver.o: driver.c - $(EMCC) -g -Os -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s "BINARYEN_TRAP_MODE='clamp'" -s ALIASING_FUNCTION_POINTERS=0 driver.c -c -o driver.o + $(EMCC) -g -Os -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s "BINARYEN_TRAP_MODE='clamp'" -s ALIASING_FUNCTION_POINTERS=0 -I$(WASM_RUNTIME_DIR)/include/mono-2.0 driver.c -c -o driver.o debug/: mkdir -p $@ @@ -90,6 +91,9 @@ release/.stamp-build: driver.o library_mono.js binding_support.js dotnet_support $(WASM_BCL_DIR)/monolinker.exe: $(TOP)/mcs/class/lib/build/monolinker.exe cp $< $@ +$(WASM_BCL_DIR)/Mono.Cecil.dll: $(TOP)/mcs/class/lib/build/Mono.Cecil.dll + cp $< $@ + build-native: debug/.stamp-build release/.stamp-build do-runtime: @@ -142,18 +146,57 @@ TEST_ASSEMBLIES = $(WASM_BCL_DIR)/nunitlite.dll $(WASM_BCL_DIR)/tests/wasm_corli ninja -v -C obj/test-suite touch $@ -aot-sample: $(DRIVER_CONF)/.stamp-build packager.exe mini_tests.dll main.exe runtime.js - mono packager.exe --emscripten-sdkdir=$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$(PWD)/../out -appdir=bin/aot-sample --nobinding --builddir=obj/aot-sample --aot --template=runtime-tests.js mini_tests.dll +# For development +aot-sample: packager.exe mini_tests.dll main.exe runtime.js + mono packager.exe --emscripten-sdkdir=$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$(TOP)/sdks/out -appdir=bin/aot-sample --nobinding --builddir=obj/aot-sample --aot --template=runtime-tests.js mini_tests.dll ninja -v -C obj/aot-sample do-aot-sample: aot-sample (cd bin/aot-sample && $(SM) runtime.js --regression mini_tests.dll) +build-aot-mini: packager.exe mini_tests.dll main.exe runtime.js + mono packager.exe --emscripten-sdkdir=$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$(TOP)/sdks/out -appdir=bin/aot-mini --nobinding --builddir=obj/aot-mini --aot --template=runtime-tests.js mini_tests.dll + ninja -v -C obj/aot-mini + +check-aot-mini run-aot-mini: build-aot-mini + (cd bin/aot-mini && $(SM) runtime.js --regression mini_tests.dll) + +## +# Parameters: +# $(1) - make target suffix +# $(2) - test assembly filename +# $(3) - main.exe argument +define AotTestTemplate + +build-aot-$(1): packager.exe runtime-tests.js main.exe WebAssembly.Bindings.dll binding_tests.dll $$(WASM_BCL_DIR)/nunitlite.dll $$(WASM_BCL_DIR)/tests/$(2) + mono packager.exe --emscripten-sdkdir=$$(EMSCRIPTEN_SDKDIR) --mono-sdkdir=$$(TOP)/sdks/out -appdir=bin/aot-$(1) --nobinding --builddir=obj/aot-$(1) --aot --template=runtime-tests.js main.exe WebAssembly.Bindings.dll binding_tests.dll $$(WASM_BCL_DIR)/tests/$(2) + ninja -v -C obj/aot-$(1) + +clean-aot-$(1): + $(RM) -r obj/aot-$(1) bin/aot-$(1) + +check-aot-$(1) run-aot-$(1): build-aot-$(1) + (cd bin/aot-$(1) && $$(SM) runtime.js $(3)) + +endef + +$(eval $(call AotTestTemplate,corlib,wasm_corlib_test.dll,corlib)) +$(eval $(call AotTestTemplate,System.Core,wasm_System.Core_test.dll,system-core)) +$(eval $(call AotTestTemplate,System,wasm_System_test.dll,system)) + +AOT_TEST_SUITES=corlib System.Core + +build-aot-all: + $(MAKE) $(patsubst %,build-aot-%,$(AOT_TEST_SUITES)) + +run-aot-all: + for suite in System.Core; do make run-aot-$$suite || exit 1; done + build-debug-sample: .stamp-build-debug-sample build-test-suite: .stamp-build-test-suite -build-managed: build-debug-sample build-test-suite $(WASM_BCL_DIR)/monolinker.exe +build-managed: build-debug-sample build-test-suite $(WASM_BCL_DIR)/monolinker.exe $(WASM_BCL_DIR)/Mono.Cecil.dll build-dbg-proxy: dotnet build ProxyDriver diff --git a/sdks/wasm/README.md b/sdks/wasm/README.md index 6107cf8b7f5..60eae68156b 100644 --- a/sdks/wasm/README.md +++ b/sdks/wasm/README.md @@ -110,6 +110,12 @@ make -C sdks/wasm aot-sample make -C sdks/wasm link-sample ``` +To build and run AOT test suites: +``` +make -C sdks/wasm build-aot-<suite name> +make -C sdks/wasm check-aot-<suite name> +``` + # Notes [1]: https://github.com/kripken/emscripten diff --git a/sdks/wasm/aot-driver.js b/sdks/wasm/aot-driver.js deleted file mode 100644 index 8f0385f083f..00000000000 --- a/sdks/wasm/aot-driver.js +++ /dev/null @@ -1,126 +0,0 @@ -//glue code to deal with the differences between ch, d8, jsc and sm. -if (print == undefined) - print = console.log; - - -if (console != undefined) { - var has_console_warn = false; - try { - if (console.warn != undefined) - has_console_warn = true; - } catch(e) {} - - if (!has_console_warn) - console.warn = console.log; -} - -fail_exec = function(reason) { - print (reason); - throw "FAIL"; -} - -try { - arguments = WScript.Arguments; - load = WScript.LoadScriptFile; - read = WScript.LoadBinaryFile; - fail_exec = function(reason) { - print (reason); - WScript.Quit(1); - } -} catch(e) {} - -try { - if (scriptArgs !== undefined) - arguments = scriptArgs; -} catch(e) {} - - -// load("runtime.js") - -var App = { - init: function () { print ("runtime init finished"); } -}; - -function ResolveEagerPromise(value) { - this.then = function(cb) { - var res = cb (value); - return new ResolveEagerPromise(res); - } -} - -var Module = { - onRuntimeInitialized: function () { - print("initing the runtime"); - MONO.mono_load_runtime_and_bcl ( - "managed", - "managed", - 0, - [ "mscorlib.dll", "mini_tests_basic.dll", ], - function () { App.init (); }, - function (file) { - // print("loading " + file) - return new ResolveEagerPromise ({ - ok: true, - url: file, - arrayBuffer: function() { return read (file, 'binary') } - }) - }); - }, - - print: function(x) { print ("WASM: " + x) }, - printErr: function(x) { print ("WASM-ERR: " + x) }, - - totalDependencies: 0, - monitorRunDependencies: function(left) { - this.totalDependencies = Math.max(this.totalDependencies, left); - print("STATUS: "+ (left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.')); - }, - - instantiateWasm: function (env, receiveInstance) { - //merge Module's env with emcc's env - env.env = Object.assign({}, env.env, this.env); - var module = new WebAssembly.Module (read ('mono.wasm', 'binary')) - this.wasm_instance = new WebAssembly.Instance (module, env); - this.em_cb = receiveInstance; - return this - }, - - finish_loading: function () { - this.em_cb (this.wasm_instance); - }, - - env: { - }, - -}; - - -load("mono.js") -Module.finish_loading (); - -function not_null(value) { - if (!value) - throw "error"; - return value; -} - -var assembly_load = Module.cwrap ('mono_wasm_assembly_load', 'number', ['string']) -var find_class = Module.cwrap ('mono_wasm_assembly_find_class', 'number', ['number', 'string', 'string']) -var find_method = Module.cwrap ('mono_wasm_assembly_find_method', 'number', ['number', 'string', 'number']) -var mono_runtime_invoke = Module.cwrap ('mono_wasm_invoke_method', 'number', ['number', 'number', 'number', 'number']); -var mono_unbox_int = Module.cwrap ('mono_unbox_int', 'number', ['number']); -const IGNORE_PARAM_COUNT = -1; - -var test_suite = not_null (assembly_load("mini_tests_basic")) -var basic_tests = not_null (find_class (test_suite, "", "BasicTests")) -var test_0_return = not_null (find_method (basic_tests, "test_0_return", IGNORE_PARAM_COUNT)) - -var eh_throw = Module._malloc (4); -Module.setValue (eh_throw, 0, "i32"); -var res = mono_unbox_int (mono_runtime_invoke (test_0_return, 0, 0, eh_throw)); -var eh_res = Module.getValue (eh_throw, "i32"); -print ("res is " + res + " eh is " + eh_res); - - - - diff --git a/sdks/wasm/driver.c b/sdks/wasm/driver.c index c501fe316c7..20cf98b915b 100644 --- a/sdks/wasm/driver.c +++ b/sdks/wasm/driver.c @@ -4,86 +4,9 @@ #include <string.h> #include <stdint.h> -typedef enum { - /* Disables AOT mode */ - MONO_AOT_MODE_NONE, - /* Enables normal AOT mode, equivalent to mono_jit_set_aot_only (false) */ - MONO_AOT_MODE_NORMAL, - /* Enables hybrid AOT mode, JIT can still be used for wrappers */ - MONO_AOT_MODE_HYBRID, - /* Enables full AOT mode, JIT is disabled and not allowed, - * equivalent to mono_jit_set_aot_only (true) */ - MONO_AOT_MODE_FULL, - /* Same as full, but use only llvm compiled code */ - MONO_AOT_MODE_LLVMONLY, - /* Uses Interpreter, JIT is disabled and not allowed, - * equivalent to "--full-aot --interpreter" */ - MONO_AOT_MODE_INTERP, - /* Same as INTERP, but use only llvm compiled code */ - MONO_AOT_MODE_INTERP_LLVMONLY, -} MonoAotMode; - -typedef enum { - MONO_TYPE_END = 0x00, /* End of List */ - MONO_TYPE_VOID = 0x01, - MONO_TYPE_BOOLEAN = 0x02, - MONO_TYPE_CHAR = 0x03, - MONO_TYPE_I1 = 0x04, - MONO_TYPE_U1 = 0x05, - MONO_TYPE_I2 = 0x06, - MONO_TYPE_U2 = 0x07, - MONO_TYPE_I4 = 0x08, - MONO_TYPE_U4 = 0x09, - MONO_TYPE_I8 = 0x0a, - MONO_TYPE_U8 = 0x0b, - MONO_TYPE_R4 = 0x0c, - MONO_TYPE_R8 = 0x0d, - MONO_TYPE_STRING = 0x0e, - MONO_TYPE_PTR = 0x0f, /* arg: <type> token */ - MONO_TYPE_BYREF = 0x10, /* arg: <type> token */ - MONO_TYPE_VALUETYPE = 0x11, /* arg: <type> token */ - MONO_TYPE_CLASS = 0x12, /* arg: <type> token */ - MONO_TYPE_VAR = 0x13, /* number */ - MONO_TYPE_ARRAY = 0x14, /* type, rank, boundsCount, bound1, loCount, lo1 */ - MONO_TYPE_GENERICINST= 0x15, /* <type> <type-arg-count> <type-1> \x{2026} <type-n> */ - MONO_TYPE_TYPEDBYREF = 0x16, - MONO_TYPE_I = 0x18, - MONO_TYPE_U = 0x19, - MONO_TYPE_FNPTR = 0x1b, /* arg: full method signature */ - MONO_TYPE_OBJECT = 0x1c, - MONO_TYPE_SZARRAY = 0x1d, /* 0-based one-dim-array */ - MONO_TYPE_MVAR = 0x1e, /* number */ - MONO_TYPE_CMOD_REQD = 0x1f, /* arg: typedef or typeref token */ - MONO_TYPE_CMOD_OPT = 0x20, /* optional arg: typedef or typref token */ - MONO_TYPE_INTERNAL = 0x21, /* CLR internal type */ - - MONO_TYPE_MODIFIER = 0x40, /* Or with the following types */ - MONO_TYPE_SENTINEL = 0x41, /* Sentinel for varargs method signature */ - MONO_TYPE_PINNED = 0x45, /* Local var that points to pinned object */ - - MONO_TYPE_ENUM = 0x55 /* an enumeration */ -} MonoTypeEnum; - -typedef enum { - MONO_IMAGE_OK, - MONO_IMAGE_ERROR_ERRNO, - MONO_IMAGE_MISSING_ASSEMBLYREF, - MONO_IMAGE_IMAGE_INVALID -} MonoImageOpenStatus; - -typedef struct MonoType_ MonoType; -typedef struct MonoDomain_ MonoDomain; -typedef struct MonoAssembly_ MonoAssembly; -typedef struct MonoMethod_ MonoMethod; -typedef struct MonoException_ MonoException; -typedef struct MonoString_ MonoString; -typedef struct MonoClass_ MonoClass; -typedef struct MonoImage_ MonoImage; -typedef struct MonoObject_ MonoObject; -typedef struct MonoArray_ MonoArray; -typedef struct MonoThread_ MonoThread; -typedef struct _MonoAssemblyName MonoAssemblyName; - +#include <mono/metadata/assembly.h> +#include <mono/jit/jit.h> +#include <mono/utils/mono-logger.h> //JS funcs extern MonoObject* mono_wasm_invoke_js_with_args (int js_handle, MonoString *method, MonoArray *args, int *is_exception); @@ -94,91 +17,21 @@ extern MonoObject* mono_wasm_get_global_object (MonoString *globalName, int *is_ // Blazor specific custom routines - see dotnet_support.js for backing code extern void* mono_wasm_invoke_js_marshalled (MonoString **exceptionMessage, void *asyncHandleLongPtr, MonoString *funcName, MonoString *argsJson); extern void* mono_wasm_invoke_js_unmarshalled (MonoString **exceptionMessage, MonoString *funcName, void* arg0, void* arg1, void* arg2); -void mono_aot_register_module (void **aot_info); -void mono_jit_set_aot_mode (MonoAotMode mode); -MonoDomain* mono_jit_init_version (const char *root_domain_name, const char *runtime_version); + +void mono_wasm_enable_debugging (void); + void mono_ee_interp_init (const char *opts); void mono_marshal_ilgen_init (void); void mono_method_builder_ilgen_init (void); void mono_sgen_mono_ilgen_init (void); void mono_icall_table_init (void); -MonoAssembly* mono_assembly_open (const char *filename, MonoImageOpenStatus *status); -int mono_jit_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]); -void mono_set_assemblies_path (const char* path); +void mono_aot_register_module (void **aot_info); +char *monoeg_g_getenv(const char *variable); int monoeg_g_setenv(const char *variable, const char *value, int overwrite); void mono_free (void*); -MonoString* mono_string_new (MonoDomain *domain, const char *text); -MonoDomain* mono_domain_get (void); -MonoClass* mono_class_from_name (MonoImage *image, const char* name_space, const char *name); -MonoMethod* mono_class_get_method_from_name (MonoClass *klass, const char *name, int param_count); -MonoType* mono_class_get_type (MonoClass *klass); -MonoClass* mono_object_get_class (MonoObject *obj); -int mono_type_get_type (MonoType *type); -int mono_type_is_reference (MonoType *type); - -MonoString* mono_object_to_string (MonoObject *obj, MonoObject **exc);//FIXME Use MonoError variant -char* mono_string_to_utf8 (MonoString *string_obj); -MonoObject* mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc); -void* mono_object_unbox (MonoObject *obj); - -MonoImage* mono_assembly_get_image (MonoAssembly *assembly); -MonoAssembly* mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status); - -MonoAssemblyName* mono_assembly_name_new (const char *name); -void mono_assembly_name_free (MonoAssemblyName *aname); - -const char* mono_image_get_name (MonoImage *image); -uint32_t mono_image_get_entry_point (MonoImage *image); - -MonoMethod* mono_get_method (MonoImage *image, uint32_t token, MonoClass *klass); - -MonoString* mono_string_new (MonoDomain *domain, const char *text); -void mono_add_internal_call (const char *name, const void* method); -MonoString * mono_string_from_utf16 (char *data); -MonoString* mono_string_new (MonoDomain *domain, const char *text); -void mono_wasm_enable_debugging (void); -MonoArray* mono_array_new (MonoDomain *domain, MonoClass *eclass, int n); -MonoClass* mono_get_object_class (void); -MonoClass* mono_get_string_class (void); -int mono_class_is_delegate (MonoClass* klass); -const char* mono_class_get_name (MonoClass *klass); -const char* mono_class_get_namespace (MonoClass *klass); -MonoClass* mono_get_byte_class (void); -MonoClass* mono_get_sbyte_class (void); -MonoClass* mono_get_int16_class (void); -MonoClass* mono_get_uint16_class (void); -MonoClass* mono_get_int32_class (void); -MonoClass* mono_get_uint32_class (void); -MonoClass* mono_get_single_class (void); -MonoClass* mono_get_double_class (void); -MonoClass* mono_class_get_element_class(MonoClass *klass); -int mono_regression_test_step (int verbose_level, char *image, char *method_name); -int mono_class_is_enum (MonoClass *klass); -MonoType* mono_type_get_underlying_type (MonoType *type); -void mono_register_symfile_for_assembly (const char *assembly_name, const unsigned char *raw_contents, int size); - -#define mono_array_get(array,type,index) ( *(type*)mono_array_addr ((array), type, (index)) ) -#define mono_array_addr(array,type,index) ((type*)(void*) mono_array_addr_with_size (array, sizeof (type), index)) -#define mono_array_setref(array,index,value) \ - do { \ - void **__p = (void **) mono_array_addr ((array), void*, (index)); \ - mono_gc_wbarrier_set_arrayref ((array), __p, (MonoObject*)(value)); \ - /* *__p = (value);*/ \ - } while (0) - - -char* mono_array_addr_with_size (MonoArray *array, int size, int idx); -int mono_array_length (MonoArray *array); -int mono_array_element_size(MonoClass *klass); -void mono_gc_wbarrier_set_arrayref (MonoArray *arr, void* slot_ptr, MonoObject* value); - -typedef struct { - const char *name; - const unsigned char *data; - unsigned int size; -} MonoBundledAssembly; -void mono_register_bundled_assemblies (const MonoBundledAssembly **assemblies); +int mono_regression_test_step (int verbose_level, char *image, char *method_name); +void mono_trace_init (void); static char* m_strdup (const char *str) @@ -201,7 +54,7 @@ mono_wasm_invoke_js (MonoString *str, int *is_exception) return NULL; char *native_val = mono_string_to_utf8 (str); - char *native_res = (char*)EM_ASM_INT ({ + mono_unichar2 *native_res = (mono_unichar2*)EM_ASM_INT ({ var str = UTF8ToString ($0); try { var res = eval (str); @@ -230,6 +83,24 @@ mono_wasm_invoke_js (MonoString *str, int *is_exception) return res; } +static void +wasm_logger (const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data) +{ + if (fatal) { + EM_ASM( + var err = new Error(); + print ("Stacktrace: \n"); + print (err.stack); + ); + + fprintf (stderr, "%s", message); + + abort (); + } else { + fprintf (stdout, "%s\n", message); + } +} + #ifdef ENABLE_AOT #include "driver-gen.c" #endif @@ -249,10 +120,10 @@ mono_wasm_add_assembly (const char *name, const unsigned char *data, unsigned in { int len = strlen (name); if (!strcasecmp (".pdb", &name [len - 4])) { - name = m_strdup (name); + char *new_name = m_strdup (name); //FIXME handle debugging assemblies with .exe extension - strcpy (&name [len - 3], "dll"); - mono_register_symfile_for_assembly (name, data, size); + strcpy (&new_name [len - 3], "dll"); + mono_register_symfile_for_assembly (new_name, data, size); return; } WasmAssembly *entry = (WasmAssembly *)malloc(sizeof (MonoBundledAssembly)); @@ -265,10 +136,16 @@ mono_wasm_add_assembly (const char *name, const unsigned char *data, unsigned in } EMSCRIPTEN_KEEPALIVE void +mono_wasm_setenv (const char *name, const char *value) +{ + monoeg_g_setenv (strdup (name), strdup (value), 1); +} + +EMSCRIPTEN_KEEPALIVE void mono_wasm_load_runtime (const char *managed_path, int enable_debugging) { - monoeg_g_setenv ("MONO_LOG_LEVEL", "debug", 1); - monoeg_g_setenv ("MONO_LOG_MASK", "gc", 1); + monoeg_g_setenv ("MONO_LOG_LEVEL", "debug", 0); + monoeg_g_setenv ("MONO_LOG_MASK", "gc", 0); #ifdef ENABLE_AOT // Defined in driver-gen.c @@ -302,6 +179,8 @@ mono_wasm_load_runtime (const char *managed_path, int enable_debugging) mono_register_bundled_assemblies ((const MonoBundledAssembly**)bundle_array); } + mono_trace_init (); + mono_trace_set_log_handler (wasm_logger, NULL); mono_set_assemblies_path (m_strdup (managed_path)); root_domain = mono_jit_init_version ("mono", "v4.0.30319"); @@ -664,3 +543,8 @@ mono_wasm_unbox_enum (MonoObject *obj) } } +EMSCRIPTEN_KEEPALIVE int +mono_wasm_exit (int exit_code) +{ + exit (exit_code); +} diff --git a/sdks/wasm/incrementalrunner.cs b/sdks/wasm/incrementalrunner.cs index b5ac1b0d1cb..c43816bf0cf 100644 --- a/sdks/wasm/incrementalrunner.cs +++ b/sdks/wasm/incrementalrunner.cs @@ -24,7 +24,7 @@ public class MyListener : ITestListener else ++count; if (!test.IsSuite) - Console.WriteLine ("{0} {1}/{2}", test.Name, scount, count); + Console.WriteLine ("{0} {1}/{2}", test.FullName, scount, count); } public void TestFinished(ITestResult result) diff --git a/sdks/wasm/main.cs b/sdks/wasm/main.cs index 4a2fc59833e..261f61a048e 100644 --- a/sdks/wasm/main.cs +++ b/sdks/wasm/main.cs @@ -215,7 +215,7 @@ public class Driver { // if (test_name != null) // testRunner.RunTest (test_name); - testRunner.Exclude ("NotWasm,WASM,NotWorking,ValueAdd,CAS,InetAccess,NotWorkingRuntimeInterpreter,MultiThreaded"); + testRunner.Exclude ("NotWasm,WASM,NotWorking,ValueAdd,CAS,InetAccess,NotWorkingRuntimeInterpreter,MultiThreaded,StackWalk,GetCallingAssembly"); testRunner.Add (Assembly.LoadFrom (baseDir + "/" + testsuite_name)); // testRunner.RunOnly ("MonoTests.System.Threading.AutoResetEventTest.MultipleSet"); diff --git a/sdks/wasm/packager.cs b/sdks/wasm/packager.cs index d81eac96782..dceb70331fe 100644 --- a/sdks/wasm/packager.cs +++ b/sdks/wasm/packager.cs @@ -296,7 +296,7 @@ class Driver { if (add_binding || true) config += "\tadd_bindings: function() { " + $"Module.mono_bindings_init (\"[{BINDINGS_ASM_NAME}]{BINDINGS_RUNTIME_CLASS_NAME}\");" + " }\n"; config += "}\n"; - var config_js = Path.Combine (emit_ninja ? builddir : out_prefix, "config.js"); + var config_js = Path.Combine (emit_ninja ? builddir : out_prefix, "mono-config.js"); File.Delete (config_js); File.WriteAllText (config_js, config); @@ -358,7 +358,7 @@ class Driver { ninja.WriteLine ($"wasm_runtime_dir = {runtime_dir}"); ninja.WriteLine ($"deploy_prefix = {deploy_prefix}"); ninja.WriteLine ($"bcl_dir = {bcl_prefix}"); - ninja.WriteLine ("cross = $mono_sdkdir/wasm-cross-release/bin/wasm32-mono-sgen"); + ninja.WriteLine ("cross = $mono_sdkdir/wasm-cross-release/bin/wasm32-unknown-none-mono-sgen"); ninja.WriteLine ("emcc = source $emscripten_sdkdir/emsdk_env.sh && emcc"); // -s ASSERTIONS=2 is very slow ninja.WriteLine ("emcc_flags = -Os -g -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=1 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s \"BINARYEN_TRAP_MODE=\'clamp\'\" -s TOTAL_MEMORY=134217728 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s \"EXTRA_EXPORTED_RUNTIME_METHODS=[\'ccall\', \'FS_createPath\', \'FS_createDataFile\', \'cwrap\', \'setValue\', \'getValue\', \'UTF8ToString\']\""); @@ -380,21 +380,21 @@ class Driver { ninja.WriteLine (" description = [EMCC-LINK] $in -> $out"); ninja.WriteLine ("rule linker"); - ninja.WriteLine (" command = mono $bcl_dir/monolinker.exe -out $builddir/linker-out -l none --exclude-feature com --exclude-feature remoting $linker_args; for f in $out; do if test ! -f $$f; then echo > empty.cs; csc /out:$$f /target:library empty.cs; fi; done"); + ninja.WriteLine (" command = mono $bcl_dir/monolinker.exe -out $builddir/linker-out -l none --exclude-feature com --exclude-feature remoting $linker_args || exit 1; for f in $out; do if test ! -f $$f; then echo > empty.cs; csc /out:$$f /target:library empty.cs; fi; done"); ninja.WriteLine (" description = [IL-LINK]"); // Targets ninja.WriteLine ("build $appdir: mkdir"); ninja.WriteLine ("build $appdir/$deploy_prefix: mkdir"); ninja.WriteLine ("build $appdir/runtime.js: cpifdiff $builddir/runtime.js"); - ninja.WriteLine ("build $appdir/config.js: cpifdiff $builddir/config.js"); + ninja.WriteLine ("build $appdir/mono-config.js: cpifdiff $builddir/mono-config.js"); if (enable_aot) { var source_file = Path.GetFullPath (Path.Combine (tool_prefix, "driver.c")); ninja.WriteLine ($"build $builddir/driver.c: cpifdiff {source_file}"); ninja.WriteLine ($"build $builddir/driver-gen.c: cpifdiff $builddir/driver-gen.c.in"); ninja.WriteLine ("build $builddir/driver.o: emcc $builddir/driver.c | $builddir/driver-gen.c"); - ninja.WriteLine (" flags = -DENABLE_AOT=1"); + ninja.WriteLine (" flags = -DENABLE_AOT=1 -I$mono_sdkdir/wasm-runtime-release/include/mono-2.0"); } else { ninja.WriteLine ("build $appdir/mono.js: cpifdiff $wasm_runtime_dir/mono.js"); diff --git a/sdks/wasm/runtime-tests.js b/sdks/wasm/runtime-tests.js index 04c643808ff..c6075aceea2 100644 --- a/sdks/wasm/runtime-tests.js +++ b/sdks/wasm/runtime-tests.js @@ -24,7 +24,7 @@ if (typeof console !== "undefined") { fail_exec = function(reason) { print (reason); - throw "FAIL"; + wasm_exit (1); } try { @@ -33,7 +33,7 @@ try { read = WScript.LoadBinaryFile; fail_exec = function(reason) { print (reason); - WScript.Quit(1); + wasm_exit (1); } } catch(e) {} @@ -55,13 +55,43 @@ function inspect_object (o){ return r; } -load ("config.js"); +// Preprocess arguments +var args = testArguments; +print("Arguments: " + testArguments); +profilers = []; +setenv = {}; +while (true) { + if (args [0].startsWith ("--profile=")) { + var arg = args [0].substring ("--profile=".length); + + profilers.push (arg); + + args = args.slice (1); + } else if (args [0].startsWith ("--setenv=")) { + var arg = args [0].substring ("--setenv=".length); + var parts = arg.split ('='); + if (parts.length != 2) + fail_exec ("Error: malformed argument: '" + args [0]); + setenv [parts [0]] = parts [1]; + args = args.slice (1); + } else { + break; + } +} + +load ("mono-config.js"); var Module = { print: function(x) { print ("WASM: " + x) }, printErr: function(x) { print ("WASM-ERR: " + x) }, onRuntimeInitialized: function () { + // Have to set env vars here to enable setting MONO_LOG_LEVEL etc. + var wasm_setenv = Module.cwrap ('mono_wasm_setenv', 'void', ['string', 'string']); + for (var variable in setenv) { + wasm_setenv (variable, setenv [variable]); + } + MONO.mono_load_runtime_and_bcl ( config.vfs_prefix, config.deploy_prefix, @@ -104,6 +134,8 @@ var assembly_get_entry_point = Module.cwrap ('mono_wasm_assembly_get_entry_point var string_get_utf8 = Module.cwrap ('mono_wasm_string_get_utf8', 'string', ['number']); var string_array_new = Module.cwrap ('mono_wasm_string_array_new', 'number', ['number']); var obj_array_set = Module.cwrap ('mono_wasm_obj_array_set', 'void', ['number', 'number', 'number']); +var wasm_exit = Module.cwrap ('mono_wasm_exit', 'void', ['number']); +var wasm_setenv = Module.cwrap ('mono_wasm_setenv', 'void', ['string', 'string']); const IGNORE_PARAM_COUNT = -1; @@ -111,18 +143,11 @@ var App = { init: function () { Module.print("Initializing....."); - Module.print("Arguments: " + testArguments); - - var args = testArguments; - if (args [0].startsWith ("--profile=")) { - var arg = args [0].substring ("--profile=".length); - - var init = Module.cwrap ('mono_wasm_load_profiler_' + arg, 'void', ['string']) + for (var i = 0; i < profilers.length; ++i) { + var init = Module.cwrap ('mono_wasm_load_profiler_' + profilers [i], 'void', ['string']) init (""); - - args = args.slice (1); } if (args[0] == "--regression") { |