Commit Graph

559 Commits

Author SHA1 Message Date
Crypt Keeper
b98a11e9c3 Refactors host function tests to stub with wasm (#710)
This refactors host functions with no-op or constant returns to be
implemented with wasm instead of the host function bridge. This allows
better performance.

This also breaks up and makes WASI tests consistent, in a way that shows
parameter name drifts easier.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-21 15:49:55 +08:00
Takeshi Yoneda
303b14e67c moremath: align NaN handling with amd64/arm64 compilers (#705)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-21 12:03:05 +09:00
Crypt Keeper
0da1af2d51 Supports mix of wasm and go funcs in the same module (#707)
This removes the constraint of a module being exclusively wasm or host
functions. Later pull requests can optimize special imports to be
implemented in wasm, particularly useful for disabled logging callbacks.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-19 11:55:37 +08:00
Crypt Keeper
0d76b11d66 Adds Emscripten integration (#678)
This adds a toehold integration for emscripten users, so they don't
have to define the memory growth function.

Fixes #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-18 07:51:48 +08:00
Crypt Keeper
b1f4ced425 Uses Zig 0.10.0-dev for cc, adding the name section (#706)
This manually installs in CI until 0.10.0 is released.

Here's the example wasm trace output from cat.c:
```
--> ._start.command_export()
	--> .__wasm_call_ctors()
		--> .__wasilibc_populate_preopens()
			==> wasi_snapshot_preview1.fd_prestat_get(fd=3,result.prestat=1048568)
			<== ESUCCESS
			--> .dlmalloc(2)
			<-- (1051568)
			==> wasi_snapshot_preview1.fd_prestat_dir_name(fd=3,path=1051568,path_len=1)
			<== ESUCCESS
			--> .dlmalloc(32)
			<-- (1051584)
			--> .memset(32,0,1051584)
			<-- (1051584)
			--> .memcpy(0,0,1051584)
			<-- (1051584)
			--> .free(0)
			<-- ()
			--> .dlmalloc(1)
			<-- (1051632)
			--> .memcpy(1,1051569,1051632)
			<-- (1051632)
			--> .free(1051568)
			<-- ()
			==> wasi_snapshot_preview1.fd_prestat_get(fd=4,result.prestat=1048568)
			<== EBADF
		<-- ()
	<-- ()
	--> ._start()
		--> .__original_main()
			==> wasi_snapshot_preview1.args_sizes_get(result.argc=1048024,result.argv_buf_size=1048028)
			<== ESUCCESS
			--> .dlmalloc(15)
			<-- (1051648)
			--> .dlmalloc(12)
			<-- (1051568)
			--> .memset(12,0,1051568)
			<-- (1051568)
			==> wasi_snapshot_preview1.args_get(argv=1051568,argv_buf=1051648)
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_fdstat_get(fd=3,result.stat=1048544)
			<== ESUCCESS
			==> wasi_snapshot_preview1.path_open(fd=3,dirflags=1,path=1051654,path_len=8,oflags=0,fs_rights_base=0,fs_rights_inheriting=0,fdflags=0,result.opened_fd=1048572)
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_read(fd=4,iovs=1048544,iovs_len=1,result.size=1048572)
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_write(fd=1,iovs=1048544,iovs_len=1,result.size=1048572)
greet filesystem
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_read(fd=4,iovs=1048544,iovs_len=1,result.size=1048572)
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_close(fd=4)
			<== ESUCCESS
		<-- (0)
	<-- ()
	--> .__wasm_call_dtors()
		--> .__stdio_exit()
		<-- ()
	<-- ()
<-- ()

```

Special thanks to @Luukdegram for supporting the `--export` linker
argument even if this particular example doesn't use it.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-16 15:53:53 +08:00
Takeshi Yoneda
ff4a7ff4f9 interpreter: fixes i32x4/i16x8 bit mask (#704)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 16:07:49 +09:00
Takeshi Yoneda
a536716495 validation: not modify loop block type on unreachable br_table (#703)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 13:26:58 +09:00
Takeshi Yoneda
a76d531f1f validation: correct expected types on loop with params (#702)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 12:52:18 +09:00
Takeshi Yoneda
2d0ed54931 interpreter: signed-extend to 32-bit in SignExtend32 (#701)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 10:56:38 +09:00
Takeshi Yoneda
9e3dda2429 ir: rename NeedsAccess* -> Has*, and make them module-scoped (#699)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 08:54:00 +09:00
Crypt Keeper
5f92e37d19 Makes ExportedFunctions unique (#698)
Exported functions are easier to use as a map vs making the callers do
it.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-14 18:05:12 +08:00
Crypt Keeper
040736caac Adds function names to host functions and improves logging listener (#697)
This improves the experimental logging listener to show parameter name
and values like so:

```
--> ._start.command_export()
        	--> .__wasm_call_ctors()
        		--> .__wasilibc_initialize_environ()
        			==> wasi_snapshot_preview1.environ_sizes_get(result.environc=1048572,result.environBufSize=1048568)
        			<== ESUCCESS
        		<-- ()
        		==> wasi_snapshot_preview1.fd_prestat_get(fd=3,result.prestat=1048568)
        		<== ESUCCESS
        		--> .dlmalloc(2)
        			--> .sbrk(0)
        			<-- (1114112)
        		<-- (1060080)
--snip--
```

The convention `==>` implies it was a host function call
(def.IsHostFunction). This also improves the lifecycle by creating
listeners during compile. Finally, this backfills param names for
assemblyscript and wasi.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-14 16:43:25 +08:00
Takeshi Yoneda
0ae4254f21 Support for select instructions on vector values (#696)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-14 14:45:17 +09:00
Takeshi Yoneda
48d6e6f2e1 compiler(amd64),interpreter: signed-extend to 32-bit in V128ExtractLane. (#695)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-14 12:47:44 +09:00
Takeshi Yoneda
7474308111 func_validation: do not modify original types in unreachable state (#693)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-14 09:48:15 +09:00
Takeshi Yoneda
03b0c03a81 interpreter: remove unnecessary pc advancing in V128ITruncSatFromF (#692)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 16:55:46 +09:00
Takeshi Yoneda
a6927d58ed Read unsigned leb128 for the index of ref.func in global initializer (#691)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 15:21:21 +09:00
Crypt Keeper
49e5bcb8c7 Top-levels FunctionDefinition to allow access to all function metadata (#686)
This top-levels `api.FunctionDefinition` which was formerly
experimental, and also adds import metadata to it. Now, it holds all
metadata known at compile time.

Here are the public API visible changes:
* api.ExportedFunction - replaced with api.FunctionDefinition as it is
  usable for all types of functions.
* api.Function - `.ParamTypes/ResultTypes()` are replaced with
  `.Definition().
* api.FunctionDefinition - extracted from experimental and adds
  `.Import()` to get the any imported module and function name.
* experimental.FunctionDefinition - replaced with
  api.FunctionDefinition.
* experimental.FunctionListenerFactory - adds first arg of the
  instantiated module name, as it can be different than compiled.
* wazero.CompiledModule - Adds `.ImportedFunctions()` and changes result
  type of `.ExportedFunctions()` to api.FunctionDefinition.

Internally, logic to create function definition are consolidated between
host and wasm-defined functions, notably wasm.Module now includes
`.BuildFunctionDefinitions()` which reduces duplication in
wasm.ModuleInstance `.BuildFunctions()`,

This obviates #681 by deleting the `ExportedFunction` type which
overlaps with this information.

This fixes #637 as it includes more metadata including imports.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 14:16:18 +08:00
Takeshi Yoneda
e85e713eb3 ir: correctly ignores unreachable br_table instructions (part2) (#690)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 15:02:12 +09:00
Takeshi Yoneda
f80893901d ir: correctly ignores unreachable br_table instructions (#689)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 12:29:33 +09:00
Takeshi Yoneda
84adbc9b9d Fixes a bug with funcref in block type (#688)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 10:57:34 +09:00
Takeshi Yoneda
372b93ade0 Allow externref in table validation (#687)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 09:43:44 +09:00
Takeshi Yoneda
aebfab8961 Fixes error message on validate/applyData elements (#685)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 09:07:59 +09:00
Takeshi Yoneda
e848d35244 ir: fixes a range for drop operation on vector values (#683)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 09:05:47 +09:00
Takeshi Yoneda
7e3d965dcd binary: allow externref in element segments (#684)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 09:05:23 +09:00
Takeshi Yoneda
9f178f9202 ir: correctly ignore unreachable br/br_if (#682)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-12 17:45:40 +09:00
Takeshi Yoneda
a0478f0c5c Adds ExportedFunctions API on CompiledModule. (#681)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-12 12:21:56 +09:00
Crypt Keeper
14d892d310 Removes api.ImportRenamer for a different approach to "env" (#680)
Before, we introduced a type `api.ImportRenamer` to resolve conflicts
where the "env" module was shared between AssemblyScript and
user-defined functions. This API was never used in GitHub, and is
complicated.

AssemblyScript also isn't the only ABI to share the "env" module, as
other web APIs like Emscripten do also. The less complicated approach is
to have packages that need to share "env" use
`ModuleBuilder.ExportFunctions` instead, and use namespaces as needed if
there is overlap.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-11 14:57:26 +08:00
Takeshi Yoneda
09a8aa6030 example(wasi): fixes link drifts (#679)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-11 07:33:41 +08:00
Crypt Keeper
f0e05fb95b examples: adds rust build and WASI example (#676)
This fixes where our pull requests didn't check the rust source in
examples were valid. It also adds an example of wasi with rust.

This uses cargo-wasi because the default target creates almost 2MB of
wasm for a simple cat program.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-08 10:49:50 +08:00
Anuraag Agrawal
66d43a2a52 Fix computation of offset in arm64 compiler (#677)
* Fix computation of offset in arm64 compiler

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-07-07 16:13:00 +09:00
Crypt Keeper
8c2f0928bc Panics caller on exit error (#673)
This changes the AssemblyScript abort handler and WASI proc_exit
implementation to panic the caller which eventually invoked close.

This ensures no code executes afterwards, For example, LLVM inserts
unreachable instructions after calls to exit.

See https://github.com/emscripten-core/emscripten/issues/12322
See #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-06 16:30:31 +08:00
Crypt Keeper
273013d7ce adds image syncer (#675)
This adds an image sync script similar to what we had in func-e as the
amount of matrix jobs that use qemu are hitting rate-limit problems.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-06 13:46:56 +08:00
Anuraag Agrawal
bd1f742cb2 Enable wasm 2.0 support in tinygo examples to allow running with wasm… (#672)
* Enable wasm 2.0 support in tinygo examples to allow running with wasm built with latest

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-07-05 15:23:38 +09:00
Crypt Keeper
891761ac1e Adds support for FreeBSD (#671)
FreeBSD was disabled due to lack of testing. This works around the
compilation problems. Note: We can't currently test arm64 automatically!

Notes:

* GitHub Actions doesn’t support FreeBSD, and may never.
* We could use Travis to run FreeBSD, but it would split our CI config.
* Using Vagrant directly is easier to debug than vmactions/freebsd-vm.
* GitHub Actions only supports virtualization on MacOS.
* GitHub Actions removed vagrant from the image starting with macos-11.
* Since VirtualBox doesn't work on arm64, freebsd/arm64 is untestabl

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-01 18:59:19 +08:00
Takeshi Yoneda
63f6b22311 compiler: cleanup arch specific files (#670)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-30 14:24:17 +09:00
Takeshi Yoneda
c5f1d84914 asm: backfills unit tests and fixes node formatting (#669)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-30 11:07:35 +09:00
Crypt Keeper
fe1cde140d Removes redundant error handling (#668)
This consolidates to use EBADF in places go uses it in syscalls to
reduce where we formally returned both bool and err. This also removes
the redundant panic type handling as go will already panic with a
similar message.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-30 07:33:24 +08:00
Takeshi Yoneda
8688f3fcb4 compiler: fix stackPointerCeil calculation (#667)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-29 13:19:06 +09:00
Takeshi Yoneda
cbe6170473 compiler: always allocate register to save conditional values (#666)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-29 09:26:50 +09:00
Crypt Keeper
512096cdbf Fixes experimental listener (#640)
There was a bug peeking values that was only visible if the entrypoint
function had parameters. This fixes the bug and backfills a relevant
call-site.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-29 06:47:47 +08:00
Takeshi Yoneda
29e1dead13 spectest: precise assertion on (canonical,arithmetic) NaNs (#664)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 20:47:02 +09:00
Takeshi Yoneda
2fa67b83bf asm(amd64): resolve NOP padding TODO after golang-asm removal (#663)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 09:39:19 +09:00
Takeshi Yoneda
b8c94fd0b9 asm: remove integration tests with golang-asm (#659)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 09:19:21 +09:00
Crypt Keeper
798ff20f81 Removes WithWorkDirFS and "." resolution (#660)
This removes WithWorkDirFS and any other attempts to resolve the current directory (".") in host functions. This is a reaction to reality of compilers who track this inside wasm (not via host functions). One nice side effect is substantially simpler internal implementation of file-systems.

This also allows experimental.WithFS to block file access via passing nil.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-27 13:29:35 +08:00
Takeshi Yoneda
fb911b811c amd64: fix unsigned extension of i32 globals (#658)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-27 10:30:45 +09:00
Takeshi Yoneda
fd318d4be9 asm: unexport arm64 pkg implementations (#657)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-26 20:26:22 +09:00
Takeshi Yoneda
1489a9f19f arm64: remove golang-asm integeration test (#655)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-24 14:49:50 +09:00
Takeshi Yoneda
70a69c24d0 arm64: remove CompileJumpToMemory (#654)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-24 12:14:56 +09:00
Takeshi Yoneda
e6f08a86fd arm64: remove NOP insertion at the beginning (#653)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-24 09:39:47 +09:00