summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-emscripten.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* wasm-emscripten-finalize: Remove reliance on name section (#2285)Sam Clegg2019-08-061-3/+4
| | | | | | | | There were a couple of places where we were relying on internal names and therefore a name section. After this change wasm-emscripten-finalize works correctly on binaries without a name section at all and only relies on the names of imports and exports.
* Implement --check-stack-overflow flag for wasm-emscripten-finalize (#2278)Guanzhong Chen2019-08-021-3/+118
|
* Revert "Fix EM_ASM not working with setjmp/longjmp (#2271)" (#2277)Alon Zakai2019-08-011-128/+30
| | | | | This reverts commit 692f4666fd116fb7827b53348978f29bba253d47. See details in the reverted PR.
* Fix EM_ASM not working with setjmp/longjmp (#2271)Guanzhong Chen2019-07-311-30/+128
| | | | | This fix does not handle dynamic linking, which requires additional work. Refs https://github.com/emscripten-core/emscripten/issues/8894.
* wasm-emscripten-finalize: Add mainReadsParams metadata (#2247)Alon Zakai2019-07-221-1/+17
| | | | | | | The new flag indicates whether main reads the argc/argv parameters. If it does not, we can avoid emitting code to generate those arguments in the JS, which is not trivial in small programs - it requires some string conversion code. Nicely the existing test inputs were enough for testing this (see outputs). This depends on an emscripten change to land first, as emscripten.py asserts on metadata fields it doesn't recognize.
* Generalize EM_JS parsing code. (#2233)Alon Zakai2019-07-181-27/+6
| | | | | The key thing is that there is a single constant, which may or may not be saved/loaded from a local, and may or may not get an added global if in relocatable code. Fixes emscripten-core/emscripten#8993
* Handle passive segments in wasm-emscripten-finalize (#2217)Thomas Lively2019-07-111-2/+36
|
* Don't minify __stack_pointer import (#2219)Sam Clegg2019-07-111-1/+1
| | | This is core import like __memory_base and __table_base.
* wasm-emscripten-finalize: Internalize mutable __stack_pointer import (#2213)Sam Clegg2019-07-101-0/+26
| | | | | | | | | | | I'm working on a change to lld that will cause `-pie` binaries to import __stack_pointer, just like -shared do already. Because we don't yet support mutable globals everywhere this change will internalize the import and create a new immutable import that is used to initialize the internal one. This change is part of the fix for: https://github.com/emscripten-core/emscripten/issues/8915
* Ignore --initial-stack-pointer arg to wasm-emscripten-finalize (#2201)Sam Clegg2019-07-101-9/+0
| | | | | | | | | | | | | We were passing bad value in --initial-stack-pointer which did not include the STATIC_BUMP (since STATIC_BUMP is determinted by the output of finalize). If emscripten wants to set the stack pointer position it can do so by calling the stackRestore() function at startup. This argument will be removed completely once we stop passing it on the emscripten side. See https://github.com/emscripten-core/emscripten/issues/8905
* Reflect instruction renaming in code (#2128)Heejin Ahn2019-05-211-21/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Reflected new renamed instruction names in code and tests: - `get_local` -> `local.get` - `set_local` -> `local.set` - `tee_local` -> `local.tee` - `get_global` -> `global.get` - `set_global` -> `global.set` - `current_memory` -> `memory.size` - `grow_memory` -> `memory.grow` - Removed APIs related to old instruction names in Binaryen.js and added APIs with new names if they are missing. - Renamed `typedef SortedVector LocalSet` to `SetsOfLocals` to prevent name clashes. - Resolved several TODO renaming items in wasm-binary.h: - `TableSwitch` -> `BrTable` - `I32ConvertI64` -> `I32WrapI64` - `I64STruncI32` -> `I64SExtendI32` - `I64UTruncI32` -> `I64UExtendI32` - `F32ConvertF64` -> `F32DemoteI64` - `F64ConvertF32` -> `F64PromoteF32` - Renamed `BinaryenGetFeatures` and `BinaryenSetFeatures` to `BinaryenModuleGetFeatures` and `BinaryenModuleSetFeatures` for consistency.
* rename some C++ locals to camelCase for consistency (#2122)Alon Zakai2019-05-171-15/+15
|
* Generate `dynCall` function for all signature used by `invoke` functions. ↵Sam Clegg2019-05-101-29/+37
| | | | | | | | | (#2095) Previously we were only creating `dynCall` functions for signatures that we have statically in the table. However for dynamic linking we may need to invoke functions that we don't have table entries for (e.g. table entries from a different module).
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-11/+21
| | | Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
* Proper errors on unsupported segment types in ↵Alon Zakai2019-05-011-1/+6
| | | | EmscriptenGlueGenerator::separateDataSegments (#2068)
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-76/+85
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* Remove f32 legalization from LegalizeJSInterface (#2052)Sam Clegg2019-04-251-0/+3
| | | | | As well as i64 splitting this pass was also converting f32 to f64 at the wasm boundry. However it appears this is not actually useful and makes somethings (such as dynamic linking) harder.
* wasm-emscripten-finalize: Handle relocatable code in AsmConstWalker (#2035)Sam Clegg2019-04-221-21/+28
| | | | | | | | | When replacing the first argument to an asm call, allow more complex expressions for expressing the address. This fixes the case where the first argument might be the result of adding a constant to __memory_base.
* Change default feature set to MVP (#1993)Thomas Lively2019-04-161-1/+0
| | | | | In the absence of the target features section or command line flags. When there are command line flags, it is an error if they do not exactly match the target features section, except if --detect-features has been provided. Also adds a --print-features pass to print the command line flags for all enabled options and uses it to make the feature tests more rigorous.
* Make sure we always add signature to `fp$` functions (#1994)Sam Clegg2019-04-161-3/+13
| | | | | | | | Previously we were searching for the function by name but this doesn't work when the internal name for the function is different. In order to repro such a case the shared.c test was converted to C++ since then binaryen's internal name is different since it comes from the de-mangled name section.
* Move features from passOptions to Module (#2001)Thomas Lively2019-04-121-3/+2
| | | | | This allows us to emit a (potentially modified) target features section and conditionally emit other sections such as the DataCount section based on the presence of features.
* Handle relocatable code in AsmConstWalker (#1992)Sam Clegg2019-04-101-4/+17
| | | | | | In relocatable code the constant offset might be relative to __memory_base.
* wasm-emscripten-finalize: rename function pointer getter functions (#1988)Sam Clegg2019-04-081-4/+25
| | | | | | | | Turns out there was already a precedent in emscripten for using `fp$` for these functions. Also, improve the heuristics for guessing the stack pointer global. There are cases where we don't use have an explicit stack pointer at all but *do* have both imported and exported globals.
* Passive segments (#1976)Thomas Lively2019-04-051-0/+1
| | | | | Adds support for the bulk memory proposal's passive segments. Uses a new (data passive ...) s-expression syntax to mark sections as passive.
* Add missing comma in metadata JSON (#1983)Thomas Lively2019-04-051-1/+1
|
* Add feature options to emscripten metadata (#1982)Thomas Lively2019-04-051-1/+11
| | | Emscripten runs wasm-emscripten-finalize before running wasm-opt, so the target features section is stripped out before optimizations are run. One option would have been to add another wasm-opt invocation at the very end to strip the target features section, but dumping the features as metadata avoids the extra tool invocation. In the long run, it would be nice to have only as single binaryen invocation to do all the work that needs doing.
* wasm-emscripten-finalize: add namedGlobals to output metadata (#1979)Sam Clegg2019-04-041-2/+16
| | | | | | This key is used by emscripten when building with MAIN_MODULE in order to export global variables from the main module to the side modules.
* wasm-emscripten-finalize: Improve shared library support (#1961)Sam Clegg2019-04-021-22/+127
| | | | | | | | | | | | | | | | | Convert PIC code generated by llvm to work with the current emscripten ABI for dynamic linking: - Convert mutable global imports from GOT.mem and GOT.func into internal globals. - Initialize these globals on started up in g$foo and f$foo imported functions to calculate addresses at runtime. Also: - Add a test case for linking and finalizing a shared library - Allow __stack_pointer global to be non-existent as can be case for a shared library. - Allow __stack_pointer global to be an import, as can be the case for a shared library.
* 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
* Remove reference to old __wasm_nullptr function (#1928)Sam Clegg2019-02-281-5/+1
|
* 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.
* 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.
* 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.
* 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)
* 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
|
* wasm-emscripten-finalize: Remove stack pointer global from shared libs (#1791)Sam Clegg2018-11-301-8/+63
| | | | | | | | | | | | | The wasm backend uses a wasm global (__stack_pointer) for the shadow stack location. In order to make this work with shared libraries the main module would have to export this global and shared libraries would need to import it. This means we'd be relying of mutable globals which are not yet implemented in all browsers. This change allows is to move forward with shared libraries without mutable global support by replacing all stack pointer access in shared libraries with functions calls.
* wasm-emscripten-finalize: Initial support for handling shared libraries (#1746)Sam Clegg2018-11-151-9/+10
| | | | In this case we won't want generate any of the normal memory helper functions (they come from the main module).
* Handle EM_ASM functions in Tables (#1739)Jacob Gravelle2018-11-141-7/+27
| | | | | Not at all sure why we're seeing any there, but it's easy enough to handle that we might as well.
* Add wasm-emscripten-finalize flag to separate data segments into a file (#1741)Derek Schuff2018-11-141-0/+15
| | | | This writes the data section into a file suitable for use with emscripten's --memory-init-file flag
* Expand asmConsts metadata to fit the shape of proxying async EM_ASMs (no ↵Jacob Gravelle2018-10-251-0/+6
| | | | actual support) (#1711)
* More #1678 fixes (#1685)Alon Zakai2018-09-201-0/+3
| | | While debugging to fix the waterfall regressions I noticed that wasm-reduce regressed. We need to be more careful with visitFunction which now may visit an imported function - I found a few not-well-tested passes that also regressed that way.
* fix an iterator invalidation regression from #1678 (#1684)Alon Zakai2018-09-201-5/+24
| | | Fixes the 3 regressions mentioned in a comment on #1678