Closed satoshinm closed 7 years ago
https://github.com/kripken/emscripten/blob/master/src/settings.js#L670-L672
var BINARYEN_IMPRECISE = 0; // Whether to apply imprecise/unsafe binaryen optimizations. If enabled,
// code will run faster, but some types of undefined behavior might
// trap in wasm.
hmm, CMakeLists.txt:
if (WASM)
add_definitions(-DBUILD_WASM)
set_property(TARGET craft APPEND_STRING PROPERTY LINK_FLAGS " -s WASM=1")
set_property(TARGET craft APPEND_STRING PROPERTY LINK_FLAGS " -s BINARYEN_IMPRECISE=1")
set_target_properties(craft PROPERTIES OUTPUT_NAME "craftw")
endif ()
fail with emscripten 1.37.12:
[ 4%] Linking C executable craftw.html
WARNING:root:Assigning a non-existent settings attribute "BINARYEN_IMPRECISE"
WARNING:root: - did you mean one of BINARYEN_PASSES, BINARYEN_METHOD, BINARYEN_MEM_MAX?
WARNING:root: - perhaps a typo in emcc's -s X=Y notation?
WARNING:root: - (see src/settings.js for valid values)
[100%] Built target craft
The option has been renamed in incoming: https://github.com/kripken/emscripten/blob/2edfe1b2c0af7e832e0076938f089f7115804985/src/settings.js#L704-L711
var BINARYEN_TRAP_MODE = "allow"; // How we handle wasm operations that may trap, which includes integer
// div/rem of 0 and float-to-int of values too large to fit in an int.
// js: do exactly what js does. this can be slower.
// clamp: avoid traps by clamping to a reasonable value. this can be
// faster than "js".
// allow: allow creating operations that can trap. this is the most
// compact, as we just emit a single wasm operation, with no
// guards to trapping values, and also often the fastest.
Setting BINARYEN_TRAP_MODE to clamp (see long discussion in https://github.com/kripken/emscripten/issues/4625 what this means) works for now, but really should identify and fix this division by zero. According to Douglas Crockford there was a Cray machine in which 0/0 returned 2. In JavaScript it returns NaN but in WebAssembly it traps!
When using wasm-build to connect to an online server (passed
#localhost
in URL), it divides by zero and fails to load: