Skip to content

Commit

Permalink
wasm2c: Add macro and tests to disable Wasm's force_read
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanrn committed Dec 15, 2023
1 parent 9c09684 commit 4151fe0
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
runs-on: ubuntu-latest
env:
USE_NINJA: "1"
WASM2C_CFLAGS: "-DWASM_RT_USE_MMAP=1 -DWASM_RT_SKIP_SIGNAL_RECOVERY=1 -DWASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION=1 -DWASM2C_TEST_EMBEDDER_SIGNAL_HANDLING"
WASM2C_CFLAGS: "-DWASM_RT_USE_MMAP=1 -DWASM_RT_SKIP_SIGNAL_RECOVERY=1 -DWASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION=1 -DWASM2C_NONCONFORMING_LOAD_ELISION=1 -DWASM2C_TEST_EMBEDDER_SIGNAL_HANDLING"
steps:
- uses: actions/setup-python@v1
with:
Expand All @@ -182,5 +182,5 @@ jobs:
submodules: true
- run: sudo apt-get install ninja-build
- run: make clang-debug
- name: tests (wasm2c tests excluding memory64)
run: ./test/run-tests.py *wasm2c* --exclude-dir memory64
- name: tests (wasm2c tests excluding memory64 and unobserved read elimination)
run: ./test/run-tests.py *wasm2c* --exclude memory64 --exclude address-overflow.txt --exclude address.txt --exclude address0.txt --exclude address1.txt --exclude traps.txt --exclude traps0.txt --exclude simd_address.txt
4 changes: 3 additions & 1 deletion src/prebuilt/wasm2c_simd_source_declarations.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const char* s_simd_source_declarations = R"w2c_template(#if defined(__GNUC__) && defined(__x86_64__)
const char* s_simd_source_declarations = R"w2c_template(#if defined(__GNUC__) && defined(__x86_64__) && \
)w2c_template"
R"w2c_template( !WASM2C_NONCONFORMING_LOAD_ELISION
)w2c_template"
R"w2c_template(#define SIMD_FORCE_READ(var) __asm__("" ::"x"(var));
)w2c_template"
Expand Down
2 changes: 1 addition & 1 deletion src/prebuilt/wasm2c_source_declarations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ R"w2c_template(#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
R"w2c_template(#endif
)w2c_template"
R"w2c_template(
#ifdef __GNUC__
#if defined(__GNUC__) && !WASM2C_NONCONFORMING_LOAD_ELISION
)w2c_template"
R"w2c_template(#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
)w2c_template"
Expand Down
2 changes: 1 addition & 1 deletion src/template/wasm2c.declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
#endif

#ifdef __GNUC__
#if defined(__GNUC__) && !WASM2C_NONCONFORMING_LOAD_ELISION
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
// Clang on Mips requires "f" constraints on floats
// See https://github.com/llvm/llvm-project/issues/64241
Expand Down
3 changes: 2 additions & 1 deletion src/template/wasm2c_simd.declarations.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if defined(__GNUC__) && defined(__x86_64__)
#if defined(__GNUC__) && defined(__x86_64__) && \
!WASM2C_NONCONFORMING_LOAD_ELISION
#define SIMD_FORCE_READ(var) __asm__("" ::"x"(var));
#else
#define SIMD_FORCE_READ(var)
Expand Down
21 changes: 11 additions & 10 deletions test/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,18 @@ def _Clear(self):
sys.stderr.write('\r%s\r' % (' ' * self.last_length))


def FindTestFiles(ext, filter_pattern_re, exclude_dirs):
def FindTestFiles(ext, filter_pattern_re, excludes):
tests = []
for root, dirs, files in os.walk(TEST_DIR):
for ex in exclude_dirs:
for ex in excludes:
if ex in dirs:
# Filtering out dirs here causes os.walk not to descend into them
dirs.remove(ex)
for f in files:
path = os.path.join(root, f)
if os.path.splitext(f)[1] == ext:
tests.append(os.path.relpath(path, REPO_ROOT_DIR))
if f not in excludes:
path = os.path.join(root, f)
if os.path.splitext(f)[1] == ext:
tests.append(os.path.relpath(path, REPO_ROOT_DIR))
tests.sort()
return [test for test in tests if re.match(filter_pattern_re, test)]

Expand Down Expand Up @@ -928,10 +929,10 @@ def main(args):
action='store_true')
parser.add_argument('patterns', metavar='pattern', nargs='*',
help='test patterns.')
parser.add_argument('--exclude-dir', action='append', default=[],
help='directory to exclude.')
parser.add_argument('--exclude', action='append', default=[],
help='file or directory names to exclude.')
options = parser.parse_args(args)
exclude_dirs = options.exclude_dir
excludes = options.exclude

if options.jobs != 1:
if options.fail_fast:
Expand All @@ -947,9 +948,9 @@ def main(args):
# By default, exclude wasi tests because WASI support is not include
# by int the build by default.
# TODO(sbc): Find some way to detect the WASI support.
exclude_dirs += ['wasi']
excludes += ['wasi']

test_names = FindTestFiles('.txt', pattern_re, exclude_dirs)
test_names = FindTestFiles('.txt', pattern_re, excludes)

if options.list:
for test_name in test_names:
Expand Down
2 changes: 1 addition & 1 deletion test/wasm2c/add.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
#endif
#ifdef __GNUC__
#if defined(__GNUC__) && !WASM2C_NONCONFORMING_LOAD_ELISION
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
// Clang on Mips requires "f" constraints on floats
// See https://github.com/llvm/llvm-project/issues/64241
Expand Down
2 changes: 1 addition & 1 deletion test/wasm2c/check-imports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
#endif
#ifdef __GNUC__
#if defined(__GNUC__) && !WASM2C_NONCONFORMING_LOAD_ELISION
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
// Clang on Mips requires "f" constraints on floats
// See https://github.com/llvm/llvm-project/issues/64241
Expand Down
2 changes: 1 addition & 1 deletion test/wasm2c/export-names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
#endif
#ifdef __GNUC__
#if defined(__GNUC__) && !WASM2C_NONCONFORMING_LOAD_ELISION
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
// Clang on Mips requires "f" constraints on floats
// See https://github.com/llvm/llvm-project/issues/64241
Expand Down
2 changes: 1 addition & 1 deletion test/wasm2c/hello.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
#endif
#ifdef __GNUC__
#if defined(__GNUC__) && !WASM2C_NONCONFORMING_LOAD_ELISION
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
// Clang on Mips requires "f" constraints on floats
// See https://github.com/llvm/llvm-project/issues/64241
Expand Down
2 changes: 1 addition & 1 deletion test/wasm2c/minimal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
#endif
#ifdef __GNUC__
#if defined(__GNUC__) && !WASM2C_NONCONFORMING_LOAD_ELISION
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
// Clang on Mips requires "f" constraints on floats
// See https://github.com/llvm/llvm-project/issues/64241
Expand Down
2 changes: 1 addition & 1 deletion test/wasm2c/tail-calls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
#endif
#ifdef __GNUC__
#if defined(__GNUC__) && !WASM2C_NONCONFORMING_LOAD_ELISION
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
// Clang on Mips requires "f" constraints on floats
// See https://github.com/llvm/llvm-project/issues/64241
Expand Down
10 changes: 10 additions & 0 deletions wasm2c/wasm-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ extern "C" {
#define WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION 0
#endif

/* This macro, if defined, allows the embedder to specify that wasm2c can remove
* linear memory reads which are unused. Normally, Wasm requires does not allow
* reads to be eliminated when using guard pages, as OOB reads must still trap.
* This a non conformant configuration, i.e., this does not respect Wasm's
* specification. Use with caution.
*/
#ifndef WASM2C_NONCONFORMING_LOAD_ELISION
#define WASM2C_NONCONFORMING_LOAD_ELISION 0
#endif

/* We need to detect and trap stack overflows. If we use a signal handler on
* POSIX systems, this can detect call stack overflows. On windows, or platforms
* without a signal handler, we use stack depth counting. */
Expand Down

0 comments on commit 4151fe0

Please sign in to comment.