Skip to content

Commit

Permalink
Document some emsdk patches (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalcde authored Dec 15, 2020
1 parent 0c91434 commit 9cd79f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions emsdk/patches/emulate_pointer.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
This fixes an upstream bug introduced in emscripten 1.38.34 that causes dlsym
to always return 0 for function pointers when EMULATE_FUNCTION_POINTER_CASTS is
enabled. This is a simple typo, since `mangled == "_" + symbol`. This piece of
code is no longer present in upstream master, hence there is no effort to
upstream the fix.

diff --git a/emsdk/fastcomp/emscripten/src/library.js b/emsdk/fastcomp/emscripten/src/library.js
index 97cca10..5c002d7 100644
--- a/emsdk/fastcomp/emscripten/src/library.js
Expand Down
22 changes: 22 additions & 0 deletions emsdk/patches/num_params.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
Quoting emscripten documentation:

> Function pointers must be called with the correct type: it is undefined
> behavior in C and C++ to cast a function pointer to another type and call it
> that way. This does work in most native platforms, however, despite it being
> UB, but in asm.js and in wasm it can fail.

Unfortunately, Python code exploits this behaviour quite a lot.

FuncCastEmulation is a wasm-opt pass that helps bypass this issue by
redefining every function to take a fixed number of i64s, and then manually
converting the arguments to feed into the original function.

To do so, the fixed number of i64s must be at least the number of actual
arguments our functions take, and binaryen decided that 16 is enough for
everyone. Turns out scipy has functions that take in a huge number of
arguments, so we bump it up to 61.

An upstream patch has been submitted and accepted that makes this number
configurable at runtime, and should be present in binaryen version_99:
https://github.com/WebAssembly/binaryen/pull/3411

--- a/emsdk/binaryen/src/passes/FuncCastEmulation.cpp 2019-04-03 11:30:13.556074729 -0400
+++ b/emsdk/binaryen/src/passes/FuncCastEmulation.cpp 2019-04-03 11:30:32.817143862 -0400
@@ -39,7 +39,7 @@
Expand Down

0 comments on commit 9cd79f4

Please sign in to comment.