summaryrefslogtreecommitdiff
path: root/src/tools
Commit message (Collapse)AuthorAgeFilesLines
* Interpreter: Add a limit to how much we try to grow memory, to avoid DOS (#3227)Alon Zakai2020-10-121-1/+1
| | | | | growMemory() now also returns whether we succeeded. Without this it could eventually start to swap etc., which is annoying.
* Fuzzer: Do not emit random global.get/sets of the hang limit global (#3229)Alon Zakai2020-10-121-3/+16
| | | | | | | | | That global is for internal use. If we emit random sets to it, we could prevent it from doing its job of preventing an infinite loop (normally it decreases each time a loop runs or we recurse, until we reach 0 - if we set it to a nonzero value in that code, that would be bad). Random gets are less of a problem, but may be confusing when debugging a testcase.
* Memory64 fuzzing preparations (#3223)Alon Zakai2020-10-121-7/+13
|
* Rename Emscripten EHSjLj functions in wasm backend (#3191)Heejin Ahn2020-10-101-2/+0
| | | | | | | | | | | Now that we are renaming invoke wrappers and `emscripten_longjmp_jmpbuf` in the wasm backend, this deletes all related renaming routines and relevant tests. Depends on #3192. Addresses: #3043 and #3081 Companions: https://reviews.llvm.org/D88697 emscripten-core/emscripten#12399
* Refactor naming convention for functions handling tuples (#3196)Max Graey2020-10-095-9/+9
| | | When there are two versions of a function, one handling tuples and the other handling non-tuple values, the previous naming convention was to have "Single" in the name of the non-tuple handling function. This PR simplifies the convention and shortens function names by making the names plural for the tuple-handling version and singular for the non-tuple-handling version.
* Add a little code to prepare exception handling support in fuzzer (#3207)Alon Zakai2020-10-091-4/+6
| | | | | | | fixLabels() in the fuzzer looks for invalid labels and fixes them up, after doing some random changes to existing wasm (which checks for types while doing so, but it may invalidate labels if we remove the target of a branch, for example). This adds trivial support for BrOnExn and Try there.
* Optimize getLoggableTypes in fuzzer, and add isLoggableType (#3208)Alon Zakai2020-10-091-7/+17
| | | | | | | Previously getLoggableType would allocate a vector every time. This caches it. Also add isLoggableType which will need this caching as I will be calling it quite a lot in a future patch to the fuzzer.
* Stop generating __growWasmMemory (#3180)Sam Clegg2020-10-011-1/+0
| | | This depends on https://github.com/emscripten-core/emscripten/pull/12391
* Add --fast-math mode (#3155)Alon Zakai2020-09-301-1/+7
| | | | | | | | | | | | Similar to clang and gcc, --fast-math makes us ignore corner cases of floating-point math like NaN changes and (not done yet) lack of associativity and so forth. In the future we may want to have separate fast math flags for each specific thing, like gcc and clang do. This undoes some changes (#2958 and #3096) where we assumed it was ok to not change NaN bits, but @binji corrected us. We can only do such things in fast math mode. This puts those optimizations behind that flag, adds tests for it, and restores the interpreter to the simpler code from before with no special cases.
* GC: Fuzzing support for i31 (#3169)Daniel Wirtz2020-09-291-8/+31
| | | Integrates `i31ref` types and instructions into the fuzzer, by assuming that `(i31.new (i32.const N))` is constant and hence suitable to be used in global initializers.
* Remove redundant allocator in Builder (#3144)Thomas Lively2020-09-221-1/+1
| | | | | | Builders gained a `Module` field in #3130 because they now require extra context to properly finalize some Expressions. Since modules contain allocators, the old allocator field on the builder became redundant after that change. This PR removes the redundant allocator field.
* Fuzz with negative zero more often (#3133)Alon Zakai2020-09-211-2/+4
| | | | We did so earlier sometimes, as we would pick 0 and then tweak it with a negation. But that favored positive 0. This makes coverage symmetric.
* GC: Add ref.eq instruction (#3145)Daniel Wirtz2020-09-211-0/+18
| | | With `eqref` now integrated, the `ref.eq` instruction can be implemented. The only valid LHS and RHS value is `(ref.null eq)` for now, but implementation and fuzzer integration is otherwise complete.
* GC: Integrate eqref and i31ref types (#3141)Daniel Wirtz2020-09-193-2/+50
| | | Adds the `eqref` and `i31ref` types to their respective code locations. Implements what can be implemented trivially and otherwise traps with a TODO for now. Integration of `eqref` is mostly complete due to it being nullable, just like `anyref`, but `i31ref` needs to remain disabled in the fuzzer because we are lacking the functionality to create trivial `i31ref` values, i.e. `(i31.new (i32.const 0))`, which is left for follow-ups to implement.
* Initial implementation of "Memory64" proposal (#3130)Wouter van Oortmerssen2020-09-182-1/+2
| | | Also includes a lot of new spec tests that eventually need to go into the spec repo
* Improve testing on Windows (#3142)Wouter van Oortmerssen2020-09-175-14/+9
| | | | | | This PR contains: - Changes that enable/disable tests on Windows to allow for better local testing. - Also changes many abort() into Fatal() when it is really just exiting on error. This is because abort() generates a dialog window on Windows which is not great in automated scripts. - Improvements to CMake to better work with the project in IDEs (VS).
* Add GC feature flag (#3135)Daniel Wirtz2020-09-172-14/+15
| | | Adds the `--enable-gc` feature flag, so far enabling the `anyref` type incl. subtyping, and removes the temporary `--enable-anyref` feature flag that it replaces.
* Implement module and local names in name section (#3115)Daniel Wirtz2020-09-141-2/+2
| | | | | | | | | | | | | | | Adds support for the module and local subsections of the name section plus the respective C and JS APIs to populate and obtain local names. C API: * BinaryenFunctionGetNumLocals(func) * BinaryenFunctionHasLocalName(func, index) * BinaryenFunctionGetLocalName(func, index) * BinaryenFunctionSetLocalName(func, index, name) JS API: * Function.getNumLocals(func) * Function.hasLocalName(func, index) * Function.getLocalName(func, index) * Function.setLocalName(func, index, name)
* Fix RefNull issues (#3123)Daniel Wirtz2020-09-131-2/+3
| | | | | | | | | * ExpressionAnalyzer: Fix `ref.null ht` equality check to include `ht`. * Precompute: Fix `ref.null ht` expression reuse to also update `ht`. * Fuzzing: Fix `ref.null func` becoming canonicalized to `ref.func $funcref` when evaluating execution results, by adding a check for `isNull`. * Fuzzing: Print actual and expected execution results when aborting. * Tests: Update `if-arms-subtype` test in `optimize-instructions` to check that identical `if` arms become folded while not identical arms are kept.
* wasm-emscripten-finalize: Add --new-pic-abi option (#3118)Sam Clegg2020-09-111-3/+16
| | | | | | | | This option skips the PIC ABI transforms that are normally done by wasm-emscripten-finalize and keeps the llvm PIC ABI in place. The LLVM abi uses mutable globals (GOT.mem.foo and GOT.func.bar) for data and function offsets rather than accessor functions (g$foo and g$bar)
* Add anyref feature and type (#3109)Daniel Wirtz2020-09-104-3/+39
| | | Adds `anyref` type, which is enabled by a new feature `--enable-anyref`. This type is primarily used for testing that passes correctly handle subtype relationships so that the codebase will continue to be prepared for future subtyping. Since `--enable-anyref` is meaningless without also using `--enable-reference-types`, this PR also makes it a validation error to pass only the former (and similarly makes it a validation error to enable exception handling without enabling reference types).
* Poppy IR wast parsing and validation (#3105)Thomas Lively2020-09-095-6/+15
| | | | | Adds an IR profile to each function so the validator can determine which validation rules to apply and adds a flag to have the wast parser set the profile to Poppy for testing purposes.
* Update reference types (#3084)Daniel Wirtz2020-09-094-47/+16
| | | | | | | Align with the current state of the reference types proposal: * Remove `nullref` * Remove `externref` and `funcref` subtyping * A `Literal` of a nullable reference type can now represent `null` (previously was type `nullref`) * Update the tests and temporarily comment out those tests relying on subtyping
* Improve inlining "heavyweight" (#3085)Max Graey2020-09-041-4/+4
| | | | | | | | | Split that mode into an option to check for loops (which indicate a function is "heavy") and a constant check for having calls. The case of calls is different as we would need more logic to avoid infinite recursion if we are willing to inling functions with calls. Practically, this renames allowHeavyweight to allowFunctionsWithLoops.
* wasm-emscripten-finalize: Don't rename the imported table (#3101)Alon Zakai2020-09-031-9/+4
| | | | | | | | | When minimizing wasm changes, leave it as __indirect_function_table which is what LLVM emits. This also removes the renaming of the memory. That was never needed as LLVM already emits "memory" there. See #3043
* Add allowHeavyweight inlining option (#3032)Max Graey2020-08-261-0/+7
| | | | | As discussed in #2921, this allows inlining of functions not identified as "lightweight" (that include a loop, for example).
* wasm-emscripten-finalize: Add flags to limit dynCall creation (#3070)Sam Clegg2020-08-261-5/+25
| | | | | | Two new flags here, one to completely removes dynCalls, and another to limit them to only signatures that contains i64. See #3043
* Add new compound Signature, Struct and Array types (#3012)Daniel Wirtz2020-08-243-9/+9
| | | | | Extends the `Type` hash-consing infrastructure to handle type-parameterized and constructed types introduced in the typed function references and GC proposals. This should be a non-functional change since the new types are not used anywhere yet. Recursive type construction and canonicalization is also left as future work. Co-authored-by: Thomas Lively <tlively@google.com>
* Remove old EM_ASM handling method (#3069)Alon Zakai2020-08-211-0/+1
| | | | | | | The minimizeWasmChanges flag now does nothing (but new changes are coming, so keep it around) - this moves us to always doing the new way of things. With that we can update the tests. See #3043
* Use const modifier when dealing with types (#3064)Daniel Wirtz2020-08-206-13/+13
| | | Since they make the code clearer and more self-documenting.
* Replace Type::expand() with an iterator-based approach (#3061)Daniel Wirtz2020-08-196-21/+21
| | | This leads to simpler code and is a prerequisite for #3012, which makes it so that not all `Type`s are backed by vectors that `expand` could return.
* wasm-emscripten-finalize: Make EM_ASM modifications optional (#3044)Alon Zakai2020-08-191-0/+11
| | | | | | | | | | | | | | | | | | | | | | wasm-emscripten-finalize renames EM_ASM calls to have the signature in the name. This isn't actually useful - emscripten doesn't benefit from that. I think it was optimized in fastcomp, and in upstream we copied the general form but not the optimizations, and then EM_JS came along which is easier to optimize anyhow. This PR makes those changes optional: when not doing them, it just leaves the calls as they are. Emscripten will need some changes to handle that, but those are simple. For convenience this adds a flag to "minimize wasm changes". The idea is that this flag avoids needing a double-roll or other inconvenience as the changes need to happen in tandem on the emscripten side. The same flag can be reused for later changes similar to this one. When they are all done we can remove the flag. (Note how the code ifdefed by the flag can be removed once we no longer need the old way of doing things - that is, the new approach is simpler on the binaryen side). See #3043
* Remove asm2wasm (#3042)Alon Zakai2020-08-171-296/+0
| | | | | | | Now that fastcomp has been removed from Emscripten, there is no need for the asm2wasm tool which it used to compile fastcomp's asm.js output to wasm. See emscripten-core/emscripten#11860
* Make wasm-emscripten-finalize's output optional (#3055)Alon Zakai2020-08-171-18/+22
| | | | | | | | | | This helps towards the goal of allowing emscripten to not always modify the wasm during link. Until now wasm-emscripten-finalize always wrote an output, while with this PR it only does so if it was asked to, either by giving it an output filename, or asking for text output. The only noticeable change from this should be to make what was an error before (not specify an output or ask for text) into a non-error (run and print metadata, but do not write the wasm).
* Prepare for compound types that are single but not basic (#3046)Daniel Wirtz2020-08-175-23/+36
| | | | | | | | | | | | | | As a follow-up to https://github.com/WebAssembly/binaryen/pull/3012#pullrequestreview-459686171 this PR prepares for the new compound Signature, Struct and Array types that are single but not basic. This includes: * Renames `Type::getSingle` to `Type::getBasic` (NFC). Previously, its name was not representing its implementation (`isSingle` excluded `none` and `unreachable` while `getSingle` didn't, i.e. `getSingle` really was `getBasic`). Note that a hypothetical `Type::getSingle` cannot return `ValueType` anyway (new compound types are single but don't map to `ValueType`), so I figured it's best to skip implementing it until we actually need it. * Marks locations where we are (still) assuming that all single types are basic types, as suggested in https://github.com/WebAssembly/binaryen/pull/3012#discussion_r465356708, but using a macro, so we get useful errors once we start implementing the new types and can quickly traverse the affected locations. The macro is added where * there used to be a `switch (type.getSingle())` or similar that handled any basic type (NFC), but in the future will also have to handle single types that are not basic types. * we are not dealing with `Unary`, `Binary`, `Load`, `Store` or `AtomicXY` instructions, since these don't deal with compound types anyway.
* Refactor wasm-emscripten-finalize to use a single pass runner (#2987)Sam Clegg2020-08-051-47/+41
|
* Move generateDynCallThunks into its own pass. NFC. (#3000)Sam Clegg2020-08-041-1/+3
| | | | | | The core logic is still living in EmscriptenGlueGenerator because its used also by fixInvokeFunctionNames. As a followup we can figure out how to make these more independent.
* Implement prototype v128.load{32,64}_zero instructions (#3011)Thomas Lively2020-08-031-0/+4
| | | | | | | | Specified in https://github.com/WebAssembly/simd/pull/237. Since these are just prototypes necessary for benchmarking, this PR does not add support for these instructions to the fuzzer or the C or JS APIs. This PR also renumbers the QFMA instructions that previously used the opcodes for these new instructions. The renumbering matches the renumbering in V8 and LLVM.
* Better const fuzzing (#2972)Alon Zakai2020-07-301-14/+35
| | | | | | | | Tweak floating-point numbers with not just a +-1 integer, but also a float in [-1, 1]. Apply a tweak to powers of 2 as well. This found bugs in various codebases, see WebAssembly/spec#1224
* wasm2js: Remove an incorrect optimization (#3004)Alon Zakai2020-07-291-6/+1
| | | | optimizeBoolean does not receive a boolean, it is done when the output flows into a boolean context.
* wasm2js: Don't remove an | 0 or >>> 0 in a boolean context (#2993)Alon Zakai2020-07-281-16/+26
| | | | | | | | | | | | | It is usually fine to do if (x | 0) => if (x) since it just cares if the value is 0 or not. However, if the cast turns it into 0, then that is incorrect, which the fuzzer found as -2147483648 + -2147483648 | 0 (the sum is 2^32, which | 0 is 0). We can maybe look into doing this in a safe way, but for now just remove it. It doesn't have a big impact on code size as this is pretty rare (e.g. the minimal runtime code size test is not broken by this).
* Move stack-check into its own pass (#2994)Sam Clegg2020-07-271-3/+10
| | | | | This new pass takes an optional stack-check-handler argument which is the name of the function to call on stack overflow. If no argument is passed then it just traps.
* wasm-emscripten-finalize: remove exportWasiStart (#2986)Sam Clegg2020-07-271-4/+1
| | | | This should not be needed since in emscripten standalone mode we always include a crt1.o that includes _start.
* Move emscripten PIC ABI conversion to a pass. NFC. (#2985)Sam Clegg2020-07-241-1/+5
| | | | Doing it this way happens to re-order the __assign_got_entries function in the module, but its otherwise NFC.
* Move ReplaceStackPoint into a pass (#2984)Sam Clegg2020-07-241-1/+3
| | | First step in making wasm-emscripten-finalize use more passes.
* Wasm2c fuzz support: only emit a call to the hang limit function if present ↵Alon Zakai2020-07-241-2/+7
| | | | | (#2977) It may not be present while reducing a testcase, if the reducer removed it.
* Add a builder.makeConst helper template (#2971)Alon Zakai2020-07-214-28/+22
|
* wasm2c signal handler fixes (#2957)Alon Zakai2020-07-141-1/+1
| | | | | | Use WASM_RT_SETJMP so we use sigsetjmp when we need to. Also disable signals in emcc+wasm2c in the fuzzer. emcc looks like unix, so it enters the ifdef to use signals, but wasm has no signals...
* wasm2js: Bulk memory support (#2923)Alon Zakai2020-06-221-1/+1
| | | | | | | | | | | | | | Adds a special helper functions for data.drop etc., as unlike most wasm instructions these are too big to emit inline. Track passive segments at runtime in var memorySegments whose indexes are the segment indexes. Emit var bufferView even if the memory exists even without memory segments, as we do still need the view in order to operate on it. Also adds a few constants for atomics that will be useful in future PRs (as this PR updates the constant lists anyhow).
* wasm2js testing improvements before bulk-memory (#2918)Alon Zakai2020-06-201-5/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Necessary preparations for a later PR that adds bulk memory support to wasm2js (splitting this out so the next PR is less big): * Fix logging of print functions in wasm2js spec tests, there was an extra space in the output (which console.log adds automatically between items). * Don't assume the output is always empty, as some tests (like bulk memory) do have expected output. * Rename test/bulk-memory.wast as it "conflicts" with test/spec/bulk-memory.wast - the problem is that we scan both places, and emit files in test/wasm2js/*, so those would collide if the names overlap. * Extend the parsing and emitting of JS for (assert.. ) lines such as (assert_return (invoke "foo" (i32.const 1)) (i32.const 2)) to also handle (invoke "foo" (i32.const 1)) (i32.const 2)) Without this, we skip (invoke ..) lines in spec tests, which normally is fine, but in bulk memory at least they have side effects we need - we must run them before the later assertions.