summaryrefslogtreecommitdiff
path: root/src/wasm-linker.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Don't iterate over removed-but-not-erased functions (#961)jgravelle-google2017-04-071-1/+2
|
* Wasm h to cpp (#926)jgravelle-google2017-03-101-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | * Move WasmType function implementations to wasm.cpp * Move Literal methods to wasm.cpp * Reorder wasm.cpp shared constants back to top * Move expression functions to wasm.cpp * Finish moving things to wasm.cpp * Split out Literal into its own .h/.cpp. Also factor out common wasm-type module * Remove unneeded/transitive includes from wasm.h * Add comment to try/check methods * Rename tryX/checkX methods to getXOrNull * Add missing include that should fix appveyor build breakage * More appveyor
* clean up raw pointer import->functionType, make it a Name like everything ↵Alon Zakai2017-02-171-1/+1
| | | | else (#915)
* use MixedArena in asm.js astAlon Zakai (kripken)2017-01-311-2/+3
|
* Export memalign along with malloc and friends (#888)Derek Schuff2017-01-241-9/+5
| | | Emscripten's mmap2 syscall started using memalign instead of malloc with kripken/emscripten#4874, so we need to export that as well.
* Generate global imports separately from emscripten glue (#852)jgravelle-google2016-12-011-5/+19
|
* Handle importing globals in s2wasm (#843)jgravelle-google2016-11-301-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* Import memory instead of defining/exporting it when using emscripten glue (#777)Derek Schuff2016-10-141-5/+16
| | | | | The emscripten JS module code creates the memory using the native wasm APIs, and imports that into the wasm module.
* More binary updates for 0xc (#733)Derek Schuff2016-10-031-4/+5
| | | | | | | | | | | | | | | Refine tables to explicitly exist or not. Previously they were printed or encoded if it had any segments, or an initial or max size. However tables can be defined but empty, so we had a special hack that defined an empty segment when we really just wanted an empty table. Now, just make the existence explicit. Update Function table encoding for 0xc (Table and Element sections) Add end opcodes after function bodies (these are consumed by getMaybeBlock with the same behavior that it had before when it reached the function end, so no explicit decode) Update call_indirect encoding for 0xc (no arity, call target is last)
* Refactor Import::Kind and Export::Kind into an ExternalKind enum class (#725)Alon Zakai2016-10-031-2/+2
|
* Make the linker always create a table segment (#722)Derek Schuff2016-09-301-0/+2
| | | | | | | Previously a table was only created if there were any address-taken functions. New module validation rules require the existence of a table for any call-indirects to validate (even if they are dead and never called). However this use case seems common enough that we might want to make it continue to work. So the linker now always creates an empty table segment (indicating an empty table).
* Update s2wasm for 0xc changes (#698)Derek Schuff2016-09-151-9/+10
| | | | | | | | | | | Several updates for s2wasm and its tests: Add explicit drops where they are emitted by LLVM already Convert loops (which are still modeled in the old way by LLVM) to wrap them in an explicit block (for the exit label). This also allows simplifying the loop creation (no need to post-process the implicit block which is the loop's body). After the engines update to 0xc we should update LLVM to model loops in the 0xc way, but for now it remains compatible with 0xb and 0xc. Fix the order of the calls to setTee() when creating tee_locals Add an explicit drop when creating the _start entry function wrapper if needed Update dot_s and llvm_autogenerated tests to remove store-results optimization (and few other minor updates) Fix the test auto-updater to fail if subprocesses fail There still seems to be a validation failure when building libc (I think it's from the stricter drop rules, but it may be in the source rather than the compiler), but this at least makes Binaryen's tests pa
* Add flag to s2wasm to export __growWasmMemory function (#696)jgravelle-google2016-09-091-138/+31
| | | | | | | | | | | | | | | | | | | | | * 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.
* import type for globalsAlon Zakai2016-09-071-2/+2
|
* import kindsAlon Zakai2016-09-071-0/+2
|
* export kindsAlon Zakai2016-09-071-1/+6
|
* Asm.js-style setjmp/longjmp support for wasm (#681)Heejin Ahn2016-08-261-6/+9
| | | | | | | This needs to export realloc as well, in addition to malloc and free handled in #4469. To support asm.js style setjmp/longjmp, wasm needs to export realloc as well, in addition to malloc and free handled in #4469. saveSetjmp() uses realloc within it, and realloc is not implemented in JS glue code.
* offset support in tableAlon Zakai2016-08-151-9/+22
|
* support function table initial and max sizes, and new printing formatAlon Zakai2016-08-121-0/+3
|
* support expressions in segment offsetsAlon Zakai2016-08-121-1/+1
|
* Implement asm.js style exception handling for Wasm (#664)Heejin Ahn2016-08-111-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Implement asm.js style exception handling for Wasm Converts invoke wrapper names generated by LLVM backend to real invoke wrapper names that are expected by JavaScript glue code. This is required to support wasm exception handling (asm.js style). LLVM backend lowers invoke @func(arg1, arg2) to label %invoke.cont unwind label %lpad into ... (some code) call @invoke_SIG(func, arg1, arg2) ... (some code) SIG is a mangled string generated based on the LLVM IR-level function signature. In LLVM IR, types are not lowered yet, so this mangling scheme simply takes LLVM's string representtion of parameter types and concatenate them with '_'. For example, the name of an invoke wrapper for function void foo(struct mystruct*, int) will be "__invoke_void_%struct.mystruct*_int". This function converts the names of invoke wrappers based on their lowered argument types and a return type. In the example above, the resulting new wrapper name becomes "invoke_vii". * Address comments Change variable names to camelcase Add a small (semi-)handwritten test case * Export malloc and free from wasm when available * Add a test case for exporting malloc/free feature + cosmetic 'file' name change in text_before_type.s * fixInvokeWrapper -> fixEmExceptionInvoke * Add a TODO
* Create a dummy function to prevent NULL miscomparisons, if necessary (#658)Dominic Chen2016-08-031-16/+38
| | | Resolves WebAssembly/spec#312
* support pre-assigning indexes for functions that are called indirectly (#616)Dominic Chen2016-08-021-0/+21
| | | This patch adds support for an ".indidx" primitive that pre-assigns table indexes for functions that are called indirectly. It is used by the upstream LLVM WebAssembly backend to support fine-grained control-flow integrity for indirect function calls by emitting instrumentation at each indirect call site to check that the destination index is within certain ranges that correspond to disjoint equivalence classes of indirect call targets. The reason that this primitive is necessary is because the layout of the table section isn't determined until the WebAssembly linker is executed, but indirect function to table index mappings need to be known when opt is executed to generate the correct range checking in the LLVM IR.
* Handle aliases without size (e.g. weak symbol), add redefinition warnings (#630)Dominic Chen2016-07-131-0/+1
|
* add support for symbol assignments, closes #4422 (#615)Dominic Chen2016-07-111-5/+12
| | | Adds support for aliases to objects, to go along with the existing support for aliases to functions.
* make makeCallImport more similar to makeCall; do not assume all imports ↵Alon Zakai2016-06-261-1/+1
| | | | exist, let functions be created in a way independent from global state
* add shared-constants.h for wasm constantsAlon Zakai2016-06-261-7/+0
|
* make assertion error more useful (#597)Dominic Chen2016-06-231-1/+1
|
* Do not create dyncall thunks for functions with i64 results or params (#586)Derek Schuff2016-06-141-0/+9
| | | | | | Dyncall thunks are meant to be used with emscripten on the web; however on the web, functions with i64 results or params are not allowed to be exported.
* s2wasm: Validate the result module (#574)Derek Schuff2016-06-101-1/+1
| | | | Add an s2wasm option `--no-validate` to disable validation for debugging purposes. Also fix several validation errors by adding calls to `finalize()` after creating expressions, and ensuring that an import is created earlier in `Linker::getImportThunk`.
* Do not generate duplicate import thunks at link time. (#569)Derek Schuff2016-06-031-3/+5
| | | | | Previously every address-take of an import would cause a new thunk to be generated. Now check in getImportThunk if the thunk exists already and just return it if so.
* Generate thunks for address-taken imports (#554)Derek Schuff2016-06-021-11/+40
| | | | | | | | | | | Under emscripten, C code can take the address of a function implemented in Javascript (which is exposed via an import in wasm). Because imports do not have linear memory address in wasm, we need to generate a thunk to be the target of the indirect call; it call the import directly. This is facilited by a new .s directive (.functype) which declares the types of functions which are declared but not defined. Fixes https://github.com/WebAssembly/binaryen/issues/392
* refactor walk logic into walk* and doWalk* methods, for a more regular API ↵Alon Zakai2016-05-301-1/+1
| | | | that is clearer where it should be overridden (#551)
* Avoid a redundant return in dynCall functions. (#533)Dan Gohman2016-05-231-1/+1
|
* Avoid double dollarsigns in s2wasm local names. (#527)Dan Gohman2016-05-191-1/+1
| | | | | | | | | * Avoid double dollarsigns in s2wasm local names. Recognize '$' as part of the .s syntax for register names, and exclude it when forming the wasm local name. This changes names like "$$0" to "$0". * Fix a comment.
* Print a newline at the end of the METADATA line. (#521)Dan Gohman2016-05-171-1/+1
|
* Introduce a separate type for linear memory addresses (#477)Derek Schuff2016-05-111-6/+6
| | | | | | | We've been using size_t (and other things) for addresses, which is generally wrong because it depends on the host, when it should in fact depend on the target. This is a partial fix for #278 (i.e. it's the right fix, I don't think it's applied quite everywhere yet).
* [Linker] Make repeated passes over archive members (#440)Derek Schuff2016-05-051-15/+23
| | | | | | | | | An archive member can depend on any other archive member, so adding a member to the link can introduce new undefined references that must be satisfied. The linker must continue to iterate over the members until nothing new is added to the link.
* [Linker] Handle archive filesDerek Schuff2016-05-051-3/+23
| | | | | | | | Add a class to parse archive files. Support linking archive files, with archive semantics (i.e. an archive member is linked in if it satisfies an undefined reference). Archive files must be gnu-format archives containing .s files. Add tests for linking semantics.
* just use a simple vector in data segmentsAlon Zakai2016-04-271-4/+5
|
* allocate only expressions in arenas - functions, imports, exports, function ↵Alon Zakai2016-04-271-3/+3
| | | | types, can more simply be held by unique_ptrs on the owning module. this avoids need to coordinate arena allocation for their elements, and only the far more plentiful expression nodes are a perf factor anyhow
* Split construction, scanning, and building phases of S2WasmBuilder (#400)Derek Schuff2016-04-271-3/+33
| | | | | | | | | | | Instead of doing all of the S2Wasm work in the constructor, split construction, scanning (to determine implemented functions) and building of the wasm module. This allows the linker to get the symbol information (e.g. implemented functions) without having to build an entire module (which will be useful for archives) and to allow the linker to link a new object into the existing one by building the wasm module in place on the existing module.
* add an ArenaVector for internal array allocations in expression nodesAlon Zakai2016-04-261-9/+10
|
* ast_utils improvements (#399)Alon Zakai2016-04-261-4/+2
| | | | | | | | | * make EffectAnalyzer a little more fun to use * create a convert() method that can turn a node into a smaller node, reusing its memory, and use that in nop() * use convert in wasm-linker
* Defer creation of CallImports to link time (#395)Derek Schuff2016-04-261-1/+28
| | | s2wasm currently creates a Call AST node if the target is implemented in the current object (thus far assumed to be the final executable) and a CallImport node if not. In preparation for adding additional objects to the link before layout time, we make only Call nodes until link time, and then convert them to CallImport if they are undefined at that time.
* Separate LinkerObject from Linker (#383)Derek Schuff2016-04-251-44/+45
| | | | | Create the LinkerObject class, which has a wasm Module and represents the module plus the information needed to relocate and lay it out. Each Linker owns a "main executable" LinkerObject, and S2WasmBuilder requires a LinkerObject instead of just a Module because LLVM asm files require relocation/linking before they represent a full wasm module. No merging support yet, but the real functionality for #370 is coming soon.
* Simplify statics, segments, and relocations (#380)Derek Schuff2016-04-221-20/+27
| | | | Also defer address assignment until layout time in preparation for separating linker objects out from Linker
* Move wasm-linker into its own cpp file (#375)Derek Schuff2016-04-211-0/+277
Still making things nicer for #370 Pulling wasm-linker into its own file also necessitated pulling asm_v_wasm.h into a cpp file. It goes into a new lib directory, src/asmjs. No actual code changes in this PR.