summaryrefslogtreecommitdiff
path: root/src/wasm
Commit message (Collapse)AuthorAgeFilesLines
* Rename atomic wait/notify instructions (#1972)Heejin Ahn2019-03-304-18/+18
| | | | | | | | This renames the following: - `i32.wait` -> `i32.atomic.wait` - `i64.wait` -> `i64.atomic.wait` - `wake` -> `atomic.notify` to match the spec.
* avoid risky iterator addition (#1970)Alon Zakai2019-03-291-1/+1
| | | Not an actual problem, but hits an assertion in D_GLIBCXX_DEBUG, and is likely UB.
* remove getString, which is not used, and was insecure to boot (#1966)Alon Zakai2019-03-261-8/+0
|
* More validation tests and fixes for SIMD (#1964)Thomas Lively2019-03-251-0/+8
| | | | | Moves the feature validation unit test file to a new directory, 'unit', and adds new tests for SIMD and sign-ext. Adds validation for v128 globals and v128.const.
* Update v128.const text formats (#1934)Thomas Lively2019-03-192-28/+30
| | | | | Parse the formats allowed by the spec proposal and emit the i32x4 canonical format.
* Validate that types match features (#1949)Thomas Lively2019-03-182-0/+13
| | | | | | Refactors features into a new wasm-features.h file and updates the validator to check that all types are allowed. Currently this is only relevant for the v128 SIMD type, but new types will be added in the future. The test for this change is in #1948.
* Allow tools to read from stdin (#1950)Thomas Lively2019-03-181-7/+39
| | | | This is necessary to write tests that don't require temporary files, such as in #1948, and is generally useful.
* Add strip-target-features pass (#1946)Thomas Lively2019-03-141-0/+1
| | | And run it in wasm-emscripten-finalize. This will prevent the emscripten output from changing when the target features section lands in LLVM.
* Add some checking in EmscriptenGlueGenerator::generateStackInitialization ↵Sam Clegg2019-03-131-4/+12
| | | | | | | | | (#1944) We expect the stack pointer to be of a certain type. This fixes a segfault we are seeing when passed a binary which doesn't quite meet our expectations.
* wasm-emscripten-finalize: Remove JSCall thunk generation (#1938)Sam Clegg2019-03-121-119/+2
| | | | We now implement addFunction by creating a wasm module to wrap that JS function and simply adding it to the table.
* Don't create already-existing dynCalls (#1932)Alon Zakai2019-03-061-2/+8
| | | | | This can happen in emscripten if we run fpcast-emu after previous passes created dynCalls already. If so, it's fine to just do nothing. Fixes emscripten-core/emscripten#8229
* Align v128 text format with WABT (#1930)Daniel Wirtz2019-03-041-3/+8
| | | | | | | | This PR changes the formatting of v128.const literals in text format / stack ir like so - v128.const i32 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x80 + v128.const i32 0x04030201 0x08070605 0x0c0b0a09 0x800f0e0d Recently hit this when trying to load Binaryen generated text format with WABT, which errored with `error: unexpected token 0x5, expected ).
* Consistently optimize small added constants into load/store offsets (#1924)Alon Zakai2019-03-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | See #1919 - we did not do this consistently before. This adds a lowMemoryUnused option to PassOptions. It can be passed on the commandline with --low-memory-unused. If enabled, we run the new optimize-added-constants pass, which does the real work here, replacing older code in post-emscripten. Aside from running at the proper time (unlike the old pass, see #1919), this also has a -propagate mode, which can do stuff like this: y = x + 10 [..] load(y) [..] load(y) => y = x + 10 [..] load(x, offset=10) [..] load(x, offset=10) That is, it can propagate such offsets to the loads/stores. This pattern is common in big interpreter loops, where the pointers are offsets into a big struct of state. The pass does this propagation by using a new feature of LocalGraph, which can verify which locals are in SSA mode. Binaryen IR is not SSA (intentionally, since it's a later IR), but if a local only has a single set for all gets, that means that local is in such a state, and can be optimized. The tricky thing is that all locals are initialized to zero, so there are at minimum two sets. But if we verify that the real set dominates all the gets, then the zero initialization cannot reach them, and we are safe. This PR also makes safe-heap aware of lowMemoryUnused. If so, we check for not just an access of 0, but the range 0-1023. This makes zlib 5% faster, with either the wasm backend or asm2wasm. It also makes it 0.5% smaller. Also helps sqlite (1.5% faster) and lua (1% faster)
* Fix memory leaks (#1925)Bohdan2019-02-281-0/+12
| | | | | | Fixes #1921 Signed-off-by: Bogdan Vaneev <warchantua@gmail.com>
* Remove reference to old __wasm_nullptr function (#1928)Sam Clegg2019-02-281-5/+1
|
* NaN fuzzing improvements (#1913)Alon Zakai2019-02-191-0/+11
| | | | | | | | | * make DE_NAN avoid creating nan literals in the first place * add a reducer option `--denan` to not introduce nans in destructive reduction * add a `Literal::isNaN()` method * also remove the default exception logging from the fuzzer js glue, which is a source of non-useful VM differences (like nan nondeterminism) * added an option `--no-fuzz-nans` to make it easy to avoid nans when fuzzing (without hacking the source and recompiling). Background: trying to get fuzzing on jsc working despite this open issue: https://bugs.webkit.org/show_bug.cgi?id=175691
* Fix a fuzz bug with peeking forward in binary reading. (#1902)Alon Zakai2019-02-071-2/+1
| | | Fixes #1900
* wasm-emscripten-finalize: separateDataSegments() fix (#1897)Alon Zakai2019-02-061-1/+2
| | | | | We should emit a file with only the data segments, starting from the global base, and not starting from zero (the data before is unneeded, and the emscripten loading code assumes it isn't there). Also fix the auto updater to work properly on .mem test updating.
* throw an early error in s-expr-parsing makeBlock, if not inside a function ↵Alon Zakai2019-02-061-0/+1
| | | | | (#1894) Fixes #1893
* Bulk memory operations (#1892)Thomas Lively2019-02-054-2/+168
| | | | | | Bulk memory operations The only parts missing are the interpreter implementation and spec tests.
* Strip the producers section in --strip-producers (#1875)Alon Zakai2019-01-312-1/+2
| | | | | | | | WebAssembly/tool-conventions#93 has a summary of emscripten's current thinking on this. For Binaryen, we don't want to do anything to the producers section by default, but do want it to be possible to optionally remove it. To achieve that, this PR * creates a --strip-producers pass that removes that section. * creates a --strip-debug pass that removes debug info, same as the old --strip, which is still around but deprecated. A followup in emscripten will use this pass by default.
* wasm-emscripten-finalize: Emit illegal dynCalls, and legalize them (#1890)Alon Zakai2019-01-291-9/+0
| | | Before this, we just did not emit illegal dynCalls. This was wrong as we do need them (e.g. if a function with a setjmp call calls a function with an i64 param - we'll have an invoke with that signature there). We just need to legalize them. This fixes that by first emitting them, and second by running legalization late, after dynCalls have been generated, so it legalizes them too.
* Handle EM_ASM/EM_JS in LLVM wasm backend O0 output (#1888)Alon Zakai2019-01-281-10/+47
| | | | | | | See emscripten-core/emscripten#7928 - we have been optimizing all wasms until now, and noticed this when the wasm object file path did not do so. When not optimizing, our methods of handling EM_ASM and EM_JS fail since the patterns are different. Specifically, for EM_ASM we hunt for emscripten_asm_const(X, where X is a constant, but without opts it may be a get of a local. For EM_JS, the function body may not just contain a const, but a block with a set of the const and a return of a get later. This adds logic to track gets and sets in basic blocks, which is sufficient to handle this.
* validate all function indexes in binary reading (#1887)Alon Zakai2019-01-241-3/+3
| | | fixes bug reported in comment on e63c4a7 , #1885 (comment) , #1879 (comment)
* Validate unique local names, and use validation in wasm2js. Fixes #1885 (#1886)Alon Zakai2019-01-231-0/+6
| | | | | * Also fixes some bugs in wasm2js tests that did not validate. * Rename FeatureOptions => ToolOptions, as they now contain all the basic stuff each tool needs for commandline options (validation yes or no, and which features if so).
* More misc ASAN fixes (#1882)Alon Zakai2019-01-222-0/+6
| | | | | | | | | | * fix buffer overflow in simple_ast.h printing. * check wasm binary format reading of function export indexes for errors. * check if s-expr format imports have a non-empty module and base. Fixes #1876 Fixes #1877 Fixes #1879
* Show a proper error on an invalid type in binary reading ; fixes #1872 (#1874)Alon Zakai2019-01-191-2/+2
|
* Emscripten stack simplification (#1870)Alon Zakai2019-01-161-12/+2
| | | | | | This takes advantage of the recent memory simplification in emscripten, where JS static allocation is done at compile time. That means we know the stack's initial location at compile time, and can apply it. This is the binaryen side of that: * asm2wasm support for asm.js globals with an initial value var X = Y; where Y is not 0 (which is what the stack now is). * wasm-emscripten-finalize support for a flag --initial-stack-pointer=X, and remove the old code to import the stack's initial location.
* Misc minor ASAN fixes (#1869)Alon Zakai2019-01-162-7/+14
| | | | | | | | | | * handle end of input in skipWhitespace in s-parser. fixes #1863 * ignore debug locations when not in a function ; fixes #1867 * error properly on invalid user section sizes ; fixes #1866 * throw a proper error on invalid call offsets in binary reading ; fixes #1865
* Code style improvements (#1868)Alon Zakai2019-01-151-2/+2
| | | | * Use modern T p = v; notation to initialize class fields * Use modern X() = default; notation for empty class constructors
* Require unique_ptr to Module::addFunctionType() (#1672)Paweł Bylica2019-01-103-7/+9
| | | | | This fixes the memory leak in WasmBinaryBuilder::readSignatures() caused probably the exception thrown there before the FunctionType object is safe. This also makes it clear that the Module becomes the owner of the FunctionType objects.
* Massive renaming (#1855)Thomas Lively2019-01-074-24/+24
| | | | | | Automated renaming according to https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329.
* Refactor Features code (#1848)Alon Zakai2019-01-021-3/+3
| | | Add features.h which centralizes all the feature detection code. (I'll need this in another place than the validator which is where it was til now.)
* Minor code style cleanups (#1844)Alon Zakai2019-01-021-1/+1
|
* Fix fuzzing JS glue code (#1843)Alon Zakai2018-12-271-0/+3
| | | | | | | | | After we added logging to the fuzzer, we forgot to add to the JS glue code the necessary imports so it can be run there too. Also adds legalization for the JS glue code imports and exports. Also adds a missing validator check on imports having a function type (the fuzzing code was missing one). Fixes #1842
* Rename `idx` to `index` in SIMD code for consistency (#1836)Thomas Lively2018-12-184-53/+53
|
* Fuzzing v128 and associated bug fixes (#1827)Thomas Lively2018-12-142-2/+10
| | | | * Fuzzing v128 and associated bug fixes
* wasm-emscripten-finalize: Delay function creation until after module walk ↵Sam Clegg2018-12-141-2/+11
| | | | | | | (#1828) This fixes a crash where startSave/stackRestore could be created while iterating through `module.functions`.
* wasm-emscripten-finalize: Add tableSize to metadata (#1826)Sam Clegg2018-12-141-0/+1
| | | | This allows emscripten to generate table of the correct size. Right now is simply defaults to creating a table to size 1024.
* wasm-emscripten-finalize: Don't add a table max if none is present in the ↵Sam Clegg2018-12-141-3/+6
| | | | | | input (#1825)
* SIMD (#1820)Thomas Lively2018-12-135-32/+1402
| | | | | | | | | Implement and test the following functionality for SIMD. - Parsing and printing - Assembling and disassembling - Interpretation - C API - JS API
* Don't error on too many locals - just oom (#1822)Alon Zakai2018-12-131-8/+0
| | | I think I added this error for fuzzing, but it is harmful as it prevents a module with too many locals from being loaded - if we could load it, we might be able to optimize it to have fewer locals...
* Update wrap and demote literal op names (#1817)Thomas Lively2018-12-121-11/+6
| | | | | | * Update literal op names * Remove `demoteToF32` in favor of `demote`
* wasm-emscripten-finalize: import env.STACKTOP, like asm2wasm doesAlon Zakai2018-12-111-5/+23
|
* wasm-emscripten-finalize: Fix type in JSON output (#1812)Sam Clegg2018-12-071-1/+1
|
* Add function rename utility (#1805)Alon Zakai2018-12-051-21/+1
| | | And use it in wasm-emscripten
* Format metadata json using mutliple lines for readability (#1804)Sam Clegg2018-12-051-56/+60
|
* Warn if linking section is present, as we cannot handle it yet (#1798)Alon Zakai2018-12-042-1/+4
|
* Implement nontrapping float-to-int instructions (#1780)Thomas Lively2018-12-044-29/+193
|
* Feature options (#1797)Thomas Lively2018-12-031-9/+9
| | | | Add feature flags and struct interface. Default feature set has all feature enabled.