Skip to content

Commit c98c303

Browse files
committed
wasm2c: Add config macro and tests for disabling unused reads
1 parent 156483e commit c98c303

12 files changed

+26
-13
lines changed

.github/workflows/build.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ jobs:
172172
runs-on: ubuntu-latest
173173
env:
174174
USE_NINJA: "1"
175-
WASM2C_CFLAGS: "-DWASM_RT_USE_MMAP=1 -DWASM_RT_SKIP_SIGNAL_RECOVERY=1 -DWASM_RT_NONCONFORMING_STACK_UNCHECKED=1 -DWASM2C_TEST_EMBEDDER_SIGNAL_HANDLING"
175+
WASM2C_CFLAGS: "-DWASM_RT_USE_MMAP=1 -DWASM_RT_SKIP_SIGNAL_RECOVERY=1 -DWASM_RT_NONCONFORMING_STACK_UNCHECKED=1 -DWASM_RT_NONCONFORMING_DISABLE_FORCE_READ=1 -DWASM2C_TEST_EMBEDDER_SIGNAL_HANDLING"
176176
steps:
177177
- uses: actions/setup-python@v1
178178
with:
@@ -182,5 +182,5 @@ jobs:
182182
submodules: true
183183
- run: sudo apt-get install ninja-build
184184
- run: make clang-debug
185-
- name: tests (wasm2c tests excluding memory64 and stack exhaustion)
186-
run: ./test/run-tests.py *wasm2c* --exclude memory64 --exclude call.txt --exclude call_indirect.txt --exclude fac.txt --exclude skip-stack-guard-page.txt
185+
- name: tests (wasm2c tests excluding memory64, stack exhaustion, and unused read elimination)
186+
run: ./test/run-tests.py *wasm2c* --exclude memory64 --exclude call.txt --exclude call_indirect.txt --exclude fac.txt --exclude skip-stack-guard-page.txt --exclude address-overflow.txt --exclude address.txt --exclude address0.txt --exclude address1.txt --exclude traps.txt --exclude traps0.txt --exclude simd_address.txt

src/prebuilt/wasm2c_simd_source_declarations.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const char* s_simd_source_declarations = R"w2c_template(#if defined(__GNUC__) && defined(__x86_64__)
1+
const char* s_simd_source_declarations = R"w2c_template(#if defined(__GNUC__) && defined(__x86_64__) && \
2+
)w2c_template"
3+
R"w2c_template( !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
24
)w2c_template"
35
R"w2c_template(#define SIMD_FORCE_READ(var) __asm__("" ::"x"(var));
46
)w2c_template"

src/prebuilt/wasm2c_source_declarations.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ R"w2c_template(#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
135135
R"w2c_template(#endif
136136
)w2c_template"
137137
R"w2c_template(
138-
#ifdef __GNUC__
138+
#if defined(__GNUC__) && !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
139139
)w2c_template"
140140
R"w2c_template(#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
141141
)w2c_template"

src/template/wasm2c.declarations.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
7373
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
7474
#endif
7575

76-
#ifdef __GNUC__
76+
#if defined(__GNUC__) && !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
7777
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
7878
// Clang on Mips requires "f" constraints on floats
7979
// See https://github.com/llvm/llvm-project/issues/64241

src/template/wasm2c_simd.declarations.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#if defined(__GNUC__) && defined(__x86_64__)
1+
#if defined(__GNUC__) && defined(__x86_64__) && \
2+
!WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
23
#define SIMD_FORCE_READ(var) __asm__("" ::"x"(var));
34
#else
45
#define SIMD_FORCE_READ(var)

test/wasm2c/add.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
140140
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
141141
#endif
142142

143-
#ifdef __GNUC__
143+
#if defined(__GNUC__) && !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
144144
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
145145
// Clang on Mips requires "f" constraints on floats
146146
// See https://github.com/llvm/llvm-project/issues/64241

test/wasm2c/check-imports.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
163163
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
164164
#endif
165165

166-
#ifdef __GNUC__
166+
#if defined(__GNUC__) && !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
167167
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
168168
// Clang on Mips requires "f" constraints on floats
169169
// See https://github.com/llvm/llvm-project/issues/64241

test/wasm2c/export-names.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
163163
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
164164
#endif
165165

166-
#ifdef __GNUC__
166+
#if defined(__GNUC__) && !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
167167
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
168168
// Clang on Mips requires "f" constraints on floats
169169
// See https://github.com/llvm/llvm-project/issues/64241

test/wasm2c/hello.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
171171
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
172172
#endif
173173

174-
#ifdef __GNUC__
174+
#if defined(__GNUC__) && !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
175175
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
176176
// Clang on Mips requires "f" constraints on floats
177177
// See https://github.com/llvm/llvm-project/issues/64241

test/wasm2c/minimal.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
134134
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
135135
#endif
136136

137-
#ifdef __GNUC__
137+
#if defined(__GNUC__) && !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
138138
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
139139
// Clang on Mips requires "f" constraints on floats
140140
// See https://github.com/llvm/llvm-project/issues/64241

test/wasm2c/tail-calls.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
164164
#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t))
165165
#endif
166166

167-
#ifdef __GNUC__
167+
#if defined(__GNUC__) && !WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
168168
#define FORCE_READ_INT(var) __asm__("" ::"r"(var));
169169
// Clang on Mips requires "f" constraints on floats
170170
// See https://github.com/llvm/llvm-project/issues/64241

wasm2c/wasm-rt.h

+10
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ extern "C" {
174174
#define WASM_RT_NONCONFORMING_STACK_UNCHECKED 0
175175
#endif
176176

177+
/* This macro, if defined, allows the embedder to specify that wasm2c can remove
178+
* linear memory reads which are unused. Normally, Wasm requires does not allow
179+
* reads to be eliminated when using guard pages, as OOB reads must still trap.
180+
* This a non conformant configuration, i.e., this does not respect Wasm's
181+
* specification. Use with caution.
182+
*/
183+
#ifndef WASM_RT_NONCONFORMING_DISABLE_FORCE_READ
184+
#define WASM_RT_NONCONFORMING_DISABLE_FORCE_READ 0
185+
#endif
186+
177187
/* We need to detect and trap stack overflows. If we use a signal handler on
178188
* POSIX systems, this can detect call stack overflows. On windows, or platforms
179189
* without a signal handler, we use stack depth counting. */

0 commit comments

Comments
 (0)