summaryrefslogtreecommitdiff
path: root/src/wasm-emscripten.h
Commit message (Collapse)AuthorAgeFilesLines
* Move --separate-data-segments into a pass so it can be run from wasm-opt (#6088)Sam Clegg2023-11-081-6/+0
| | | | | | | | Because we currently strip some data segments (i.e. EM_JS strings) during `--post-emscripten` this is too late as `--separate-data-segments` always runs in `wasm-emscripten-finalize`. Once emscripten switches over to using the pass directly we can remove the support from `wasm-emscripten-finalize`
* Remove metadata generation from wasm-emscripten-finalize (#4863)Sam Clegg2022-08-071-2/+0
| | | | This is no longer needed by emscripten as of: https://github.com/emscripten-core/emscripten/pull/16529
* Remove renameMainArgcArgv from wasm-emscripten-finalize (#4700)Sam Clegg2022-05-311-6/+0
| | | | | | | | | This part to finalize is currently not used and was added in preparation for https://reviews.llvm.org/D75277. However, the better solution to dealing with this alternative name for main is on the emscripten side. The main reason for this is that doing the rename here in binaryen would require finalize to always re-write the binary, which is expensive.
* finalize: remove initializers from metadata output (#3479)Sam Clegg2021-01-111-1/+1
| | | See https://github.com/emscripten-core/emscripten/pull/13208
* finalize: there can only ever be a single initializer function. NFC. (#3452)Sam Clegg2020-12-181-2/+1
|
* wasm-emscripten-finalize: Remove staticBump from metadata (#3300)Sam Clegg2020-10-291-2/+1
| | | | | | Emscripten no longer needs this information as of https://github.com/emscripten-core/emscripten/pull/12643. This also removes the need to export __data_end.
* Remove support for emscripten legacy PIC ABI (#3299)Sam Clegg2020-10-291-3/+0
|
* Remove now-redundant stack pointer manipulation passes (#3251)Sam Clegg2020-10-181-4/+0
| | | | The use of these passes was removed on the emscripten side in https://github.com/emscripten-core/emscripten/pull/12536.
* Let GenerateDynCalls generate dynCalls for invokes (#3192)Heejin Ahn2020-10-021-5/+0
| | | | | | This moves dynCall generating functionaity for invokes from `EmscriptenGlueGenerator` to `GenerateDynCalls` pass. So now `GenerateDynCalls` pass will take care of all cases we need dynCalls: functions in tables and invokes.
* Stop generating __growWasmMemory (#3180)Sam Clegg2020-10-011-1/+0
| | | This depends on https://github.com/emscripten-core/emscripten/pull/12391
* wasm-emscripten-finalize: Add flags to limit dynCall creation (#3070)Sam Clegg2020-08-261-9/+6
| | | | | | Two new flags here, one to completely removes dynCalls, and another to limit them to only signatures that contains i64. See #3043
* wasm-emscripten-finalize: Make EM_ASM modifications optional (#3044)Alon Zakai2020-08-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | 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
* Move generateDynCallThunks into its own pass. NFC. (#3000)Sam Clegg2020-08-041-6/+2
| | | | | | 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.
* Move stack-check into its own pass (#2994)Sam Clegg2020-07-271-4/+0
| | | | | 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-2/+0
| | | | This should not be needed since in emscripten standalone mode we always include a crt1.o that includes _start.
* Move ReplaceStackPoint into a pass (#2984)Sam Clegg2020-07-241-4/+0
| | | First step in making wasm-emscripten-finalize use more passes.
* Support new clang mangling of main (__main_argc_argv) (#2671)Sam Clegg2020-06-101-0/+6
| | | | | | | | | The plan is that for standlone mode we can function just like wasi-sdk and call the correct main from crt1.c. For non-standalone mode we still want to export can call main directly so we rename __main_argc_argv back to main as part of finalize. See https://reviews.llvm.org/D70700
* Remove stackSave/stackAlloc/stackRestore code generation (#2852)Sam Clegg2020-05-201-6/+0
| | | | | | | These are now implemented in assembly as part of emscripten's compiler-rt. See: https://github.com/emscripten-core/emscripten/pull/11166
* Add stack-pointer argument to post-emscripten pass. (#2823)Sam Clegg2020-05-011-1/+2
| | | | | | | This allows emscripten to statically set the initial value of the stack pointer. Should allow use to avoid doing it dynamically at startup: https://github.com/emscripten-core/emscripten/pull/11031
* Avoid fp$ access in MAIN_MODULES (#2704)Alon Zakai2020-03-271-0/+2
| | | | | | | | | | | | | | | | Depends on emscripten-core/emscripten#10741 which ensures that table indexes are unique. With that guarantee, a main module can just add its function pointers into the table, and use them based on that index. The loader will then see them in the table and then give other modules the identical function pointer for a function, ensuring function pointer equality. This avoids calling fp$ functions during startup for the main module's own functions (which are slow). We do still call fp$s of things we import from outside, as we don't have anything to put in the table for them, we depend on the loader for that. I suspect this can also be done with SIDE_MODULES, but did not want to try too much at once.
* Support stack overflow checks in standalone mode (#2525)Alon Zakai2019-12-121-0/+3
| | | | | | | | | In normal mode we call a JS import, but we can't import from JS in standalone mode. Instead, just trap in that case with an unreachable. (The error reporting is not as good in this case, but at least it catches all errors and halts, and the emitted wasm is valid for standalone mode.) Helps emscripten-core/emscripten#10019
* Remove FunctionType (#2510)Thomas Lively2019-12-111-2/+2
| | | | | | | | | | | | | | | | | Function signatures were previously redundantly stored on Function objects as well as on FunctionType objects. These two signature representations had to always be kept in sync, which was error-prone and needlessly complex. This PR takes advantage of the new ability of Type to represent multiple value types by consolidating function signatures as a pair of Types (params and results) stored on the Function object. Since there are no longer module-global named function types, significant changes had to be made to the printing and emitting of function types, as well as their parsing and manipulation in various passes. The C and JS APIs and their tests also had to be updated to remove named function types.
* Add a --standalone-wasm flag to wasm-emscripten-finalize (#2333)Alon Zakai2019-09-181-0/+2
| | | The flag indicates that we want to run the wasm by itself, without JS support. In that case we don't emit JS dynCalls etc., and we also emit a wasi _start if there is a main, i.e., we try to use the current conventions in the wasm-only space.
* Implement --check-stack-overflow flag for wasm-emscripten-finalize (#2278)Guanzhong Chen2019-08-021-1/+5
|
* wasm-emscripten-finalize: Internalize mutable __stack_pointer import (#2213)Sam Clegg2019-07-101-0/+4
| | | | | | | | | | | 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-1/+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
* Generate `dynCall` function for all signature used by `invoke` functions. ↵Sam Clegg2019-05-101-0/+4
| | | | | | | | | (#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).
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-12/+10
| | | 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
* Move features from passOptions to Module (#2001)Thomas Lively2019-04-121-2/+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.
* Add feature options to emscripten metadata (#1982)Thomas Lively2019-04-051-1/+2
| | | 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: Improve shared library support (#1961)Sam Clegg2019-04-021-0/+2
| | | | | | | | | | | | | | | | | 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.
* wasm-emscripten-finalize: Remove JSCall thunk generation (#1938)Sam Clegg2019-03-121-7/+1
| | | | We now implement addFunction by creating a wasm module to wrap that JS function and simply adding it to the table.
* wasm-emscripten-finalize: separateDataSegments() fix (#1897)Alon Zakai2019-02-061-1/+4
| | | | | 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.
* Emscripten stack simplification (#1870)Alon Zakai2019-01-161-1/+1
| | | | | | 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.
* Massive renaming (#1855)Thomas Lively2019-01-071-1/+1
| | | | | | Automated renaming according to https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329.
* wasm-emscripten-finalize: import env.STACKTOP, like asm2wasm doesAlon Zakai2018-12-111-0/+1
|
* wasm-emscripten-finalize: Remove stack pointer global from shared libs (#1791)Sam Clegg2018-11-301-0/+4
| | | | | | | | | | | | | 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-3/+0
| | | | In this case we won't want generate any of the normal memory helper functions (they come from the main module).
* Add wasm-emscripten-finalize flag to separate data segments into a file (#1741)Derek Schuff2018-11-141-0/+4
| | | | This writes the data section into a file suitable for use with emscripten's --memory-init-file flag
* Remove s2wasm (#1607)Sam Clegg2018-06-281-8/+0
| | | | s2wasm is no longer used my emscripten and as far as I know now as no other users.
* Move the renaming of llvm-generated __invoke_XX functions from s2wasm into ↵Sam Clegg2018-05-101-0/+2
| | | | | | | | | wasm-emscripten (#1539) This allows the same functionality to be used also in wasm-emscripten-finalize (i.e. the lld path).
* Emscripten addFunction support for Wasm backend (#1395)Heejin Ahn2018-02-071-2/+9
| | | This adds necessary command line options for addFunction support, and generates required jsCall imports and generates jsCall thunk functions.
* First pass at LLD support for Emscripten (#1346)Jacob Gravelle2018-01-221-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Skeleton of a beginning of o2wasm, WIP and probably not going to be used * Get building post-cherry-pick * ast->ir, remove commented out code, include a debug module print because linking * Read linking section, print emscripten metadata json * WasmBinaryWriter emits user sections on Module * Remove debugging prints, everything that isn't needed to build metadata * Rename o2wasm to lld-metadata * lld-metadata support for outputting to file * Use tables index instead of function index for initializer functions * Add lld-emscripten tool to add emscripten-runtime functions to wasm modules (built with lld) * Handle EM_ASM in lld-emscripten * Add a list of functions to forcibly export (for initializer functions) * Disable incorrect initializer function reading * Add error printing when parsing .o files in lld-metadata * Remove ';; METADATA: ' prefix from lld-metadata, output is now standalone json * Support em_asm consts that aren't at the start of a segment * Initial test framework for lld-metadata tool * Add em_asm test * Add support for WASM_INIT_FUNCS in the linking section * Remove reloc section parsing because it's unused * lld-emscripten can read and write text * Add test harness for lld-emscripten * Export all functions for now * Add missing lld test output * Add support for reading object files differently Only difference so far is in importing mutable globals being an object file representation for symbols, but invalid wasm. * Update help strings * Update linking tests for stackAlloc fix * Rename lld-emscripten,lld-metadata to wasm-emscripten-finalize,wasm-link-metadata * Add help text to header comments * auto& instead of auto & * Extract LinkType to abi/wasm-object.h * Remove special handling for wasm object file reading, allow mutable globals * Add braces around default switch case * Fix flake8 errors * Handle generating dyncall thunks for imports as well * Use explicit bool for stackPointerGlobal * Use glob patterns for lld file iteration * Use __wasm_call_ctors for all initializer functions
* Optimize out memory and table when possible (#1352)Alon Zakai2018-01-101-1/+1
| | | We can remove the memory/table (itself, or an import if imported) if they are not used. This is pretty minor on a large wasm file, but when reading small wasts it's very noticeable to have an unused memory and table all the time.
* Decouple wasm-linker from Emscripten glue (#1293)Jacob Gravelle2017-11-151-13/+33
|
* S2wasm runtime funcs (#1027)jgravelle-google2017-06-051-0/+3
| | | | | | | | | | | | | | | | * Generate stackSave function in s2wasm * Generate stackAlloc in s2wasm * Generate stackRestore in s2wasm * Update dot_s tests for runtime functions * Add s2wasm check for exporting runtime functions * Fix flake8 for s2wasm.py * Rename wasmBuilder to builder
* Make header guards consistent (#997)Sam Clegg2017-05-041-3/+3
|
* Generate global imports separately from emscripten glue (#852)jgravelle-google2016-12-011-2/+0
|
* Handle importing globals in s2wasm (#843)jgravelle-google2016-11-301-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Handle importing globals in s2wasm * Make importedGlobals a set of Names, make Names hashable * Revert "Make importedGlobals a set of Names, make Names hashable" This reverts commit 1d0ca7a5e3839b15ca60593330979864c9c3ed60. * Refactor relocation parsing to handle expressions directly * PR Feedback - Move comment where it belongs - Add comment about ownership to addRelocation - Remove do-nothing parseImportGlobal * Reword "imported globals" to "imported objects" - Flip isObjectImported to isObjectImplemented, for consistency * Add tests for s2wasm globals. Also implement import relocation expression handling * Simplify globals.s test * Fix memory leak of relocation * Use unique_ptr instead of delete in getRelocatableExpression
* Add flag to s2wasm to export __growWasmMemory function (#696)jgravelle-google2016-09-091-0/+42
* Add a flag to s2wasm to export grow_memory Binaryen's wasm.js-post.js calls back in to wasm in order to grow the linear memory, via a function that asm2wasm exports called __growWasmMemory. This changes exposes that method through s2wasm when invoked with a flag. * Move AsmConstWalker from wasm-linker to wasm-emscripten * Add test for memory growth in s2wasm * Move makeDynCallThunks into wasm-emscripten module * Move mutation in getTableSegment into a separate method * Move emscripten metadata generation into wasm-emscripten Also make AsmConstWalker internal to the wasm-emscripten module, as it's only used for the metadata pass.