diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-12-05 10:41:06 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-05 10:41:06 -0800 |
commit | 42acc22254c89b035bbaba512c86c1784545278d (patch) | |
tree | 056fcbd8d9cebb3d355c9bf06e26217be056acd5 /src/tools/wasm-merge.cpp | |
parent | 0d5a39f17a854b4241c2704a1269620687bb6a07 (diff) | |
download | binaryen-42acc22254c89b035bbaba512c86c1784545278d.tar.gz binaryen-42acc22254c89b035bbaba512c86c1784545278d.tar.bz2 binaryen-42acc22254c89b035bbaba512c86c1784545278d.zip |
support fixed (non-relocatable) segments in wasm-merge. also a few printing fixes for multiple segments, which we never really printed that prettily (#1316)
Diffstat (limited to 'src/tools/wasm-merge.cpp')
-rw-r--r-- | src/tools/wasm-merge.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index 7a713675f..7fa5af137 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -123,13 +123,28 @@ struct Mergeable { memoryBaseGlobals.insert(name); }); if (memoryBaseGlobals.size() == 0) { - Fatal() << "no memory base was imported"; + // add one + auto* import = new Import; + import->name = MEMORY_BASE; + import->module = ENV; + import->base = MEMORY_BASE; + import->kind = ExternalKind::Global; + import->globalType = i32; + wasm.addImport(import); + memoryBaseGlobals.insert(import->name); } findImportsByBase(wasm, TABLE_BASE, [&](Name name) { tableBaseGlobals.insert(name); }); if (tableBaseGlobals.size() == 0) { - Fatal() << "no table base was imported"; + auto* import = new Import; + import->name = TABLE_BASE; + import->module = ENV; + import->base = TABLE_BASE; + import->kind = ExternalKind::Global; + import->globalType = i32; + wasm.addImport(import); + tableBaseGlobals.insert(import->name); } } @@ -169,7 +184,8 @@ struct Mergeable { // ensure a relocatable segment exists, of the proper size, including // the dylink bump applied into it, standardized into the form of // not using a dylink section and instead having enough zeros at - // the end. this makes linking much simpler. + // the end. this makes linking much simpler.ta + // there may be other non-relocatable segments too. template<typename T, typename U, typename Segment> void standardizeSegment(Module& wasm, T& what, Index size, U zero, Name globalName) { Segment* relocatable = nullptr; @@ -194,9 +210,10 @@ struct Mergeable { ensureSize(what, relocatable->data.size()); } - // copies a relocatable segment from the input to the output + // copies a relocatable segment from the input to the output, and + // copies the non-relocatable ones as well template<typename T, typename V> - void copySegment(T& output, T& input, V updater) { + void copySegments(T& output, T& input, V updater) { for (auto& inputSegment : input.segments) { Expression* inputOffset = inputSegment.offset; if (inputOffset->is<GetGlobal>()) { @@ -213,6 +230,9 @@ struct Mergeable { } } WASM_UNREACHABLE(); // we must find a relocatable one in the output, as we standardized + } else { + // this is a non-relocatable one. just copy it. + output.segments.push_back(inputSegment); } } } @@ -405,8 +425,8 @@ struct InputMergeable : public ExpressionStackWalker<InputMergeable, Visitor<Inp } // memory&table: we place the new memory segments at a higher position. after the existing ones. - copySegment(outputMergeable.wasm.memory, wasm.memory, [](char x) -> char { return x; }); - copySegment(outputMergeable.wasm.table, wasm.table, [&](Name x) -> Name { return fNames[x]; }); + copySegments(outputMergeable.wasm.memory, wasm.memory, [](char x) -> char { return x; }); + copySegments(outputMergeable.wasm.table, wasm.table, [&](Name x) -> Name { return fNames[x]; }); // update the new contents about to be merged in walkModule(&wasm); |