From 250aba6874b847457a55003af786bcf6a4ffe230 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 14 Oct 2021 15:48:45 +0800 Subject: [PATCH 1/2] Sync up with wabt latest modification (#296) (#786) - Remove "--enable-reference-types" and "--enable-bulk-memory" for wat2wasm to support finished proposals. - Ignore invalid module in the thread spec repo: ``` wast ;; my_elem.wast (module (table $t 10 funcref) (func $f) (elem $t (i32.const 0) 0) (elem $t (i32.const 0) $f $f) (elem $t (offset (i32.const 0)) $f $f) ) ``` run with reference interpreter under spec/interpreter: ``` shell $ ./wasm ../../../my_elem.wast ../../../my_elem.wast:5.9-5.11: syntax error: duplicate elem segment $t ``` - use a specific commit instead of the latest commit on the thread spec repo --- .github/workflows/spec_test.yml | 4 ++++ .../spec-test-script/runtest.py | 7 +++---- .../thread_proposal_ignore_cases.patch | 17 ++++++++++++++++- tests/wamr-test-suites/test_wamr.sh | 3 ++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/spec_test.yml b/.github/workflows/spec_test.yml index 5567db10c7..f910a72e21 100644 --- a/.github/workflows/spec_test.yml +++ b/.github/workflows/spec_test.yml @@ -11,6 +11,8 @@ on: - "core/shared/**" - "wamr-compiler/**" - "product-mini/**" + - "tests/wamr-test-suites/spec-test-script/**" + - "tests/wamr-test-suites/test_wamr.sh" # will be triggered on push events push: paths: @@ -19,6 +21,8 @@ on: - "core/shared/**" - "wamr-compiler/**" - "product-mini/**" + - "tests/wamr-test-suites/spec-test-script/**" + - "tests/wamr-test-suites/test_wamr.sh" # allow to be triggered manually workflow_dispatch: diff --git a/tests/wamr-test-suites/spec-test-script/runtest.py b/tests/wamr-test-suites/spec-test-script/runtest.py index f795784830..2e378e8b7c 100755 --- a/tests/wamr-test-suites/spec-test-script/runtest.py +++ b/tests/wamr-test-suites/spec-test-script/runtest.py @@ -901,10 +901,9 @@ def compile_wast_to_wasm(form, wast_tempfile, wasm_tempfile, opts): "--no-check", wast_tempfile, "-o", wasm_tempfile ] - # optional arguments - if opts.ref_types: - cmd.append("--enable-reference-types") - cmd.append("--enable-bulk-memory") + # remove reference-type and bulk-memory enabling options since a WABT + # commit 30c1e983d30b33a8004b39fd60cbd64477a7956c + # Enable reference types by default (#1729) log("Running: %s" % " ".join(cmd)) try: diff --git a/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch b/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch index 4734318495..41a0d25b8e 100644 --- a/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch +++ b/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch @@ -163,9 +163,24 @@ index b9fa438c..a5711dd3 100644 ;; 1 elem segment declared, 2 given (assert_malformed diff --git a/test/core/elem.wast b/test/core/elem.wast -index 1ea2b061..f5440e07 100644 +index 1ea2b061..8eded377 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast +@@ -12,10 +12,10 @@ + (elem 0x0 (i32.const 0) $f $f) + (elem 0x000 (offset (i32.const 0))) + (elem 0 (offset (i32.const 0)) $f $f) +- (elem $t (i32.const 0)) +- (elem $t (i32.const 0) $f $f) +- (elem $t (offset (i32.const 0))) +- (elem $t (offset (i32.const 0)) $f $f) ++ (elem (i32.const 0)) ++ (elem (i32.const 0) $f $f) ++ (elem (offset (i32.const 0))) ++ (elem (offset (i32.const 0)) $f $f) + ) + + ;; Basic use @@ -354,6 +354,7 @@ (assert_return (invoke $module1 "call-8") (i32.const 65)) (assert_return (invoke $module1 "call-9") (i32.const 66)) diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 25333545d9..19b9f5e16e 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -290,7 +290,8 @@ function spec_test() # fetch spec for threads proposal git fetch threads - git reset --hard HEAD + # [interpreter] Threading (#179) Fri Aug 6 18:02:59 2021 +0200 + git reset --hard 0d115b494d640eb0c1c352941fd14ca0bad926d3 git checkout threads/main git apply ../../spec-test-script/thread_proposal_ignore_cases.patch From dd9b4e021e73c43ca9d4a0c6e2bc20ea61f7166e Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 14 Oct 2021 14:56:30 +0100 Subject: [PATCH 2/2] Fix WASI type/macro misalignments (#766) Some of the WASI definitions in libc-wasi are out of sync with those of [wasi-libc](https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h). This PR fixed the misalignments of type __wasi_dirnamlen_t, __wasi_linkcount_t and __wasi_dirent_t, and WASI RIGHT related macros. --- .../include/wasmtime_ssp.h | 79 ++++++++++--------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h index 7c241d8806..ace6616376 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h @@ -62,6 +62,8 @@ typedef uint64_t __wasi_device_t; typedef uint64_t __wasi_dircookie_t; #define __WASI_DIRCOOKIE_START (0) +typedef uint32_t __wasi_dirnamlen_t; + typedef uint16_t __wasi_errno_t; #define __WASI_ESUCCESS (0) #define __WASI_E2BIG (1) @@ -182,7 +184,7 @@ typedef uint16_t __wasi_fstflags_t; typedef uint64_t __wasi_inode_t; -typedef uint32_t __wasi_linkcount_t; +typedef uint64_t __wasi_linkcount_t __attribute__((aligned(8))); typedef uint32_t __wasi_lookupflags_t; #define __WASI_LOOKUP_SYMLINK_FOLLOW (0x00000001) @@ -198,35 +200,38 @@ typedef uint16_t __wasi_riflags_t; #define __WASI_SOCK_RECV_WAITALL (0x0002) typedef uint64_t __wasi_rights_t; -#define __WASI_RIGHT_FD_DATASYNC (0x0000000000000001) -#define __WASI_RIGHT_FD_READ (0x0000000000000002) -#define __WASI_RIGHT_FD_SEEK (0x0000000000000004) -#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS (0x0000000000000008) -#define __WASI_RIGHT_FD_SYNC (0x0000000000000010) -#define __WASI_RIGHT_FD_TELL (0x0000000000000020) -#define __WASI_RIGHT_FD_WRITE (0x0000000000000040) -#define __WASI_RIGHT_FD_ADVISE (0x0000000000000080) -#define __WASI_RIGHT_FD_ALLOCATE (0x0000000000000100) -#define __WASI_RIGHT_PATH_CREATE_DIRECTORY (0x0000000000000200) -#define __WASI_RIGHT_PATH_CREATE_FILE (0x0000000000000400) -#define __WASI_RIGHT_PATH_LINK_SOURCE (0x0000000000000800) -#define __WASI_RIGHT_PATH_LINK_TARGET (0x0000000000001000) -#define __WASI_RIGHT_PATH_OPEN (0x0000000000002000) -#define __WASI_RIGHT_FD_READDIR (0x0000000000004000) -#define __WASI_RIGHT_PATH_READLINK (0x0000000000008000) -#define __WASI_RIGHT_PATH_RENAME_SOURCE (0x0000000000010000) -#define __WASI_RIGHT_PATH_RENAME_TARGET (0x0000000000020000) -#define __WASI_RIGHT_PATH_FILESTAT_GET (0x0000000000040000) -#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE (0x0000000000080000) -#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES (0x0000000000100000) -#define __WASI_RIGHT_FD_FILESTAT_GET (0x0000000000200000) -#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE (0x0000000000400000) -#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES (0x0000000000800000) -#define __WASI_RIGHT_PATH_SYMLINK (0x0000000001000000) -#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY (0x0000000002000000) -#define __WASI_RIGHT_PATH_UNLINK_FILE (0x0000000004000000) -#define __WASI_RIGHT_POLL_FD_READWRITE (0x0000000008000000) -#define __WASI_RIGHT_SOCK_SHUTDOWN (0x0000000010000000) + +// Observe that WASI defines rights in the plural form +// TODO - re-factor to use RIGHTS instead of RIGHT +#define __WASI_RIGHT_FD_DATASYNC ((__wasi_rights_t)(1 << 0)) +#define __WASI_RIGHT_FD_READ ((__wasi_rights_t)(1 << 1)) +#define __WASI_RIGHT_FD_SEEK ((__wasi_rights_t)(1 << 2)) +#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3)) +#define __WASI_RIGHT_FD_SYNC ((__wasi_rights_t)(1 << 4)) +#define __WASI_RIGHT_FD_TELL ((__wasi_rights_t)(1 << 5)) +#define __WASI_RIGHT_FD_WRITE ((__wasi_rights_t)(1 << 6)) +#define __WASI_RIGHT_FD_ADVISE ((__wasi_rights_t)(1 << 7)) +#define __WASI_RIGHT_FD_ALLOCATE ((__wasi_rights_t)(1 << 8)) +#define __WASI_RIGHT_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9)) +#define __WASI_RIGHT_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10)) +#define __WASI_RIGHT_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11)) +#define __WASI_RIGHT_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12)) +#define __WASI_RIGHT_PATH_OPEN ((__wasi_rights_t)(1 << 13)) +#define __WASI_RIGHT_FD_READDIR ((__wasi_rights_t)(1 << 14)) +#define __WASI_RIGHT_PATH_READLINK ((__wasi_rights_t)(1 << 15)) +#define __WASI_RIGHT_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16)) +#define __WASI_RIGHT_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17)) +#define __WASI_RIGHT_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18)) +#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19)) +#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20)) +#define __WASI_RIGHT_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21)) +#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22)) +#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23)) +#define __WASI_RIGHT_PATH_SYMLINK ((__wasi_rights_t)(1 << 24)) +#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25)) +#define __WASI_RIGHT_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26)) +#define __WASI_RIGHT_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27)) +#define __WASI_RIGHT_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28)) typedef uint16_t __wasi_roflags_t; #define __WASI_SOCK_RECV_DATA_TRUNCATED (0x0001) @@ -292,7 +297,7 @@ struct argv_environ_values; typedef struct __wasi_dirent_t { __wasi_dircookie_t d_next; __wasi_inode_t d_ino; - uint32_t d_namlen; + __wasi_dirnamlen_t d_namlen; __wasi_filetype_t d_type; } __wasi_dirent_t __attribute__((aligned(8))); _Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout"); @@ -380,16 +385,16 @@ _Static_assert(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout") _Static_assert( offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_nlink) == 20, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_nlink) == 24, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_size) == 24, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_size) == 32, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_atim) == 32, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_atim) == 40, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_mtim) == 40, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_mtim) == 48, "non-wasi data layout"); _Static_assert( - offsetof(__wasi_filestat_t, st_ctim) == 48, "non-wasi data layout"); -_Static_assert(sizeof(__wasi_filestat_t) == 56, "non-wasi data layout"); + offsetof(__wasi_filestat_t, st_ctim) == 56, "non-wasi data layout"); +_Static_assert(sizeof(__wasi_filestat_t) == 64, "non-wasi data layout"); _Static_assert(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout"); typedef struct __wasi_ciovec_t {