Skip to content

Commit d025d13

Browse files
committed
Merge remote-tracking branch 'upstream/main' into handle_pthread_cancel_during_futext_wait
2 parents e9b3e5d + 6ad2f5e commit d025d13

4 files changed

Lines changed: 34 additions & 5 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Regression test: fpcast-emu must run before directize (inside -O2).
3+
* Otherwise directize sees the type-mismatched call_indirect (calling a
4+
* 1-arg function through a 2-arg pointer) and replaces it with unreachable.
5+
*/
6+
#include <stdio.h>
7+
8+
typedef void (*two_arg_fn)(void *, void *);
9+
10+
static void one_arg(void *p) { printf("OK\n"); }
11+
12+
static two_arg_fn hide_cast(void (*fn)(void *)) {
13+
two_arg_fn result = (two_arg_fn)fn;
14+
__asm__("" : "+r"(result));
15+
return result;
16+
}
17+
18+
int main(void) {
19+
two_arg_fn fn = hide_cast(one_arg);
20+
fn((void *)1, (void *)2);
21+
return 0;
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK

test/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7307,6 +7307,12 @@ def test_emulate_function_pointer_casts(self):
73077307
self.set_setting('EMULATE_FUNCTION_POINTER_CASTS')
73087308
self.do_core_test('test_emulate_function_pointer_casts.cpp', cflags=['-Wno-deprecated'])
73097309

7310+
def test_emulate_function_pointer_casts_directize(self):
7311+
# Regression test: directize (inside -O2) must not replace type-mismatched
7312+
# call_indirect with unreachable when fpcast-emu will fix them.
7313+
# https://github.com/WebAssembly/binaryen/pull/8475
7314+
self.do_core_test('test_emulate_function_pointer_casts_directize.c', cflags=['-sEMULATE_FUNCTION_POINTER_CASTS'])
7315+
73107316
@no_wasm2js('TODO: nicely printed names in wasm2js')
73117317
@no_bun('https://github.com/emscripten-core/emscripten/issues/26197')
73127318
@parameterized({

tools/link.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ def get_binaryen_passes(options):
344344
# safe heap must run before post-emscripten, so post-emscripten can apply the sbrk ptr
345345
if settings.SAFE_HEAP:
346346
passes += ['--safe-heap']
347+
if settings.EMULATE_FUNCTION_POINTER_CASTS:
348+
# fpcast-emu must run before -Ox so that directize (inside -Ox) sees
349+
# the rewritten table entries with matching types. It must also run
350+
# before asyncify so the byn$fpcast-emu thunks get instrumented.
351+
passes += ['--fpcast-emu']
347352
if optimizing:
348353
# wasm-emscripten-finalize will strip the features section for us
349354
# automatically, but if we did not modify the wasm then we didn't run it,
@@ -372,11 +377,6 @@ def get_binaryen_passes(options):
372377
# legalize it again now, as the instrumentation may need it
373378
passes += ['--legalize-js-interface']
374379
passes += building.js_legalization_pass_flags()
375-
if settings.EMULATE_FUNCTION_POINTER_CASTS:
376-
# note that this pass must run before asyncify, as if it runs afterwards we only
377-
# generate the byn$fpcast_emu functions after asyncify runs, and so we wouldn't
378-
# be able to further process them.
379-
passes += ['--fpcast-emu']
380380
if settings.ASYNCIFY == 1:
381381
passes += ['--asyncify']
382382
if settings.MAIN_MODULE:

0 commit comments

Comments
 (0)