summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/Print.cpp6
-rw-r--r--src/support/name.h7
-rw-r--r--src/tools/wasm-merge.cpp34
-rw-r--r--test/merge/dylib.wasm.combined1
-rw-r--r--test/merge/dylib.wasm.combined.finalized1
-rw-r--r--test/merge/dylib.wasm.combined.finalized.opt1
-rw-r--r--test/merge/dylib.wasm.combined.opt1
-rw-r--r--test/merge/fusing.wast.combined1
-rw-r--r--test/merge/fusing.wast.combined.finalized1
-rw-r--r--test/merge/fusing.wast.combined.finalized.opt1
-rw-r--r--test/merge/fusing.wast.combined.opt1
-rw-r--r--test/merge/global-init.wast.combined1
-rw-r--r--test/merge/global-init.wast.combined.finalized1
-rw-r--r--test/merge/global-init.wast.combined.finalized.opt1
-rw-r--r--test/merge/global-init.wast.combined.opt1
-rw-r--r--test/merge/noBases.wast34
-rw-r--r--test/merge/noBases.wast.combined88
-rw-r--r--test/merge/noBases.wast.combined.finalized88
-rw-r--r--test/merge/noBases.wast.combined.finalized.opt73
-rw-r--r--test/merge/noBases.wast.combined.finalized.opt.stdout3
-rw-r--r--test/merge/noBases.wast.combined.finalized.stdout3
-rw-r--r--test/merge/noBases.wast.combined.opt76
-rw-r--r--test/merge/noBases.wast.combined.opt.stdout3
-rw-r--r--test/merge/noBases.wast.combined.stdout3
-rw-r--r--test/merge/noBases.wast.toMerge35
-rw-r--r--test/merge/printf.wast.combined1
-rw-r--r--test/merge/printf.wast.combined.finalized1
-rw-r--r--test/merge/printf.wast.combined.finalized.opt1
-rw-r--r--test/merge/printf.wast.combined.opt1
29 files changed, 440 insertions, 29 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 2f7588b37..cfdfc09dd 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -741,20 +741,18 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
printTableHeader(curr);
o << maybeNewLine;
}
- if (curr->segments.empty()) return;
- doIndent(o, indent);
for (auto& segment : curr->segments) {
// Don't print empty segments
if (segment.data.empty()) continue;
+ doIndent(o, indent);
printOpening(o, "elem ", true);
visit(segment.offset);
for (auto name : segment.data) {
o << ' ';
printName(name);
}
- o << ')';
+ o << ")\n";
}
- o << maybeNewLine;
}
void printMemoryHeader(Memory* curr) {
printOpening(o, "memory") << ' ';
diff --git a/src/support/name.h b/src/support/name.h
index b77397555..ae01db787 100644
--- a/src/support/name.h
+++ b/src/support/name.h
@@ -40,8 +40,11 @@ struct Name : public cashew::IString {
Name(const std::string& str) : cashew::IString(str.c_str(), false) {}
friend std::ostream& operator<<(std::ostream& o, Name name) {
- assert(name.str);
- return o << '$' << name.str; // reference interpreter requires we prefix all names
+ if (name.str) {
+ return o << '$' << name.str; // reference interpreter requires we prefix all names
+ } else {
+ return o << "(null Name)";
+ }
}
static Name fromInt(size_t i) {
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);
diff --git a/test/merge/dylib.wasm.combined b/test/merge/dylib.wasm.combined
index df76e61bf..cb892e5cd 100644
--- a/test/merge/dylib.wasm.combined
+++ b/test/merge/dylib.wasm.combined
@@ -18,7 +18,6 @@
(global $global$2 i32 (i32.const 0))
(global $global$0$0 (mut i32) (i32.const 0))
(global $global$1$0 (mut i32) (i32.const 0))
-
(data (get_global $import$0) "hello, world!\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(export "__post_instantiate" (func $__post_instantiate))
(export "_main" (func $_main))
diff --git a/test/merge/dylib.wasm.combined.finalized b/test/merge/dylib.wasm.combined.finalized
index a60c12ea4..12952d0a4 100644
--- a/test/merge/dylib.wasm.combined.finalized
+++ b/test/merge/dylib.wasm.combined.finalized
@@ -18,7 +18,6 @@
(global $global$2 i32 (i32.const 0))
(global $global$0$0 (mut i32) (i32.const 0))
(global $global$1$0 (mut i32) (i32.const 0))
-
(data (i32.const 1024) "hello, world!\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(export "__post_instantiate" (func $__post_instantiate))
(export "_main" (func $_main))
diff --git a/test/merge/dylib.wasm.combined.finalized.opt b/test/merge/dylib.wasm.combined.finalized.opt
index 37a66bea8..228bbeb67 100644
--- a/test/merge/dylib.wasm.combined.finalized.opt
+++ b/test/merge/dylib.wasm.combined.finalized.opt
@@ -10,7 +10,6 @@
(global $global$2 i32 (i32.const 0))
(global $global$0$0 (mut i32) (i32.const 0))
(global $global$1$0 (mut i32) (i32.const 0))
-
(data (i32.const 1024) "hello, world!")
(export "__post_instantiate" (func $__post_instantiate))
(export "_main" (func $_main))
diff --git a/test/merge/dylib.wasm.combined.opt b/test/merge/dylib.wasm.combined.opt
index 316bb2121..eab9c2ec3 100644
--- a/test/merge/dylib.wasm.combined.opt
+++ b/test/merge/dylib.wasm.combined.opt
@@ -13,7 +13,6 @@
(global $global$2 i32 (i32.const 0))
(global $global$0$0 (mut i32) (i32.const 0))
(global $global$1$0 (mut i32) (i32.const 0))
-
(data (get_global $import$0) "hello, world!")
(export "__post_instantiate" (func $__post_instantiate))
(export "_main" (func $_main))
diff --git a/test/merge/fusing.wast.combined b/test/merge/fusing.wast.combined
index 37f0358ec..d3d0bbed3 100644
--- a/test/merge/fusing.wast.combined
+++ b/test/merge/fusing.wast.combined
@@ -9,7 +9,6 @@
(import "env" "tableBase" (global $tableBase$0 i32))
(global $a-global i32 (i32.const 0))
(global $b-global f64 (f64.const 2.14281428))
-
(data (get_global $memoryBase) "")
(export "foo" (func $foo-func))
(export "aglobal" (global $a-global))
diff --git a/test/merge/fusing.wast.combined.finalized b/test/merge/fusing.wast.combined.finalized
index 2675454bd..0473302d3 100644
--- a/test/merge/fusing.wast.combined.finalized
+++ b/test/merge/fusing.wast.combined.finalized
@@ -9,7 +9,6 @@
(import "env" "tableBase" (global $tableBase$0 i32))
(global $a-global i32 (i32.const 0))
(global $b-global f64 (f64.const 2.14281428))
-
(data (i32.const 1024) "")
(export "foo" (func $foo-func))
(export "aglobal" (global $a-global))
diff --git a/test/merge/fusing.wast.combined.finalized.opt b/test/merge/fusing.wast.combined.finalized.opt
index 2e8a19ebf..409fe83c4 100644
--- a/test/merge/fusing.wast.combined.finalized.opt
+++ b/test/merge/fusing.wast.combined.finalized.opt
@@ -4,7 +4,6 @@
(import "env" "table" (table 8 anyfunc))
(global $a-global i32 (i32.const 0))
(global $b-global f64 (f64.const 2.14281428))
-
(export "foo" (func $foo-func))
(export "aglobal" (global $a-global))
(export "bar" (func $bar-func))
diff --git a/test/merge/fusing.wast.combined.opt b/test/merge/fusing.wast.combined.opt
index b48bc0534..d2fed3cbd 100644
--- a/test/merge/fusing.wast.combined.opt
+++ b/test/merge/fusing.wast.combined.opt
@@ -6,7 +6,6 @@
(import "env" "table" (table 0 anyfunc))
(global $a-global i32 (i32.const 0))
(global $b-global f64 (f64.const 2.14281428))
-
(data (get_global $memoryBase) "")
(export "foo" (func $foo-func))
(export "aglobal" (global $a-global))
diff --git a/test/merge/global-init.wast.combined b/test/merge/global-init.wast.combined
index 95b339968..0361e567f 100644
--- a/test/merge/global-init.wast.combined
+++ b/test/merge/global-init.wast.combined
@@ -11,6 +11,5 @@
(global $g-collide i32 (get_global $i-collide))
(global $b f64 (get_global $i-collide$0))
(global $g-collide$0 f64 (get_global $i-collide$0))
-
(data (get_global $memoryBase) "")
)
diff --git a/test/merge/global-init.wast.combined.finalized b/test/merge/global-init.wast.combined.finalized
index 40a5066fa..c60d28850 100644
--- a/test/merge/global-init.wast.combined.finalized
+++ b/test/merge/global-init.wast.combined.finalized
@@ -11,6 +11,5 @@
(global $g-collide i32 (get_global $i-collide))
(global $b f64 (get_global $i-collide$0))
(global $g-collide$0 f64 (get_global $i-collide$0))
-
(data (i32.const 1024) "")
)
diff --git a/test/merge/global-init.wast.combined.finalized.opt b/test/merge/global-init.wast.combined.finalized.opt
index 02a0900f5..f6e309c94 100644
--- a/test/merge/global-init.wast.combined.finalized.opt
+++ b/test/merge/global-init.wast.combined.finalized.opt
@@ -1,5 +1,4 @@
(module
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 8 anyfunc))
-
)
diff --git a/test/merge/global-init.wast.combined.opt b/test/merge/global-init.wast.combined.opt
index 44c047693..604f3ede8 100644
--- a/test/merge/global-init.wast.combined.opt
+++ b/test/merge/global-init.wast.combined.opt
@@ -3,6 +3,5 @@
(import "env" "tableBase" (global $tableBase i32))
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 0 anyfunc))
-
(data (get_global $memoryBase) "")
)
diff --git a/test/merge/noBases.wast b/test/merge/noBases.wast
new file mode 100644
index 000000000..8616c64e7
--- /dev/null
+++ b/test/merge/noBases.wast
@@ -0,0 +1,34 @@
+(module
+ (type $ii (func (param i32 i32)))
+ (import "env" "memory" (memory $0 256))
+ (import "env" "table" (table 1000 anyfunc))
+ (import "env" "some-func" (func $some-func))
+ (import "env" "some-collide" (func $some-collide))
+ (data (i32.const 100) "hello, A!\n")
+ (global $global-collide i32 (i32.const 0))
+ (global $global-collide-mut (mut i32) (i32.const 0))
+ (global $global-a i32 (i32.const 1))
+ (elem (i32.const 10) $only-a $willCollide $some-func $some-collide $only-a)
+ (export "exp-a" (func $only-a))
+ (export "exp-collide" (func $only-a))
+ (export "exp-collide2" (func $willCollide))
+ (func $only-a
+ (drop (i32.const 100))
+ (call $only-a)
+ (call_import $some-func)
+ (call_import $some-collide)
+ (call_indirect (type $ii)
+ (i32.const 123)
+ (i32.const 456)
+ (i32.const 789)
+ )
+ (drop (get_global $global-collide))
+ (drop (get_global $global-a))
+ (set_global $global-collide-mut (i32.const 1234))
+ )
+ (func $willCollide
+ (drop (i32.const 200))
+ (call $willCollide)
+ )
+)
+
diff --git a/test/merge/noBases.wast.combined b/test/merge/noBases.wast.combined
new file mode 100644
index 000000000..c25a5ca19
--- /dev/null
+++ b/test/merge/noBases.wast.combined
@@ -0,0 +1,88 @@
+(module
+ (type $ii (func (param i32 i32)))
+ (type $FUNCSIG$v (func))
+ (type $ii$0 (func (param i32 i32)))
+ (type $FUNCSIG$v$0 (func))
+ (import "env" "memory" (memory $0 256))
+ (import "env" "table" (table 1000 anyfunc))
+ (import "env" "some-func" (func $some-func))
+ (import "env" "some-collide" (func $some-collide))
+ (import "env" "memoryBase" (global $memoryBase i32))
+ (import "env" "tableBase" (global $tableBase i32))
+ (import "env" "some-func-b" (func $some-func-b))
+ (import "env" "some-collide" (func $some-collide$0))
+ (import "env" "memoryBase" (global $memoryBase$0 i32))
+ (import "env" "tableBase" (global $tableBase$0 i32))
+ (global $global-collide i32 (i32.const 0))
+ (global $global-collide-mut (mut i32) (i32.const 0))
+ (global $global-a i32 (i32.const 1))
+ (global $global-collide$0 i32 (i32.const 0))
+ (global $global-collide-mut$0 (mut i32) (i32.const 0))
+ (global $global-b i32 (i32.const 1))
+ (elem (i32.const 10) $only-a $willCollide $some-func $some-collide $only-a)
+ (elem (i32.const 20) $only-b $willCollide $some-func-b $some-collide)
+ (data (i32.const 100) "hello, A!\n")
+ (data (get_global $memoryBase) "")
+ (data (i32.const 200) "hello, B!\n")
+ (export "exp-a" (func $only-a))
+ (export "exp-collide" (func $only-a))
+ (export "exp-collide2" (func $willCollide))
+ (export "exp-b" (func $only-b))
+ (export "exp-b-nameCollided" (func $willCollide$0))
+ (func $only-a (; 4 ;) (type $FUNCSIG$v)
+ (drop
+ (i32.const 100)
+ )
+ (call $only-a)
+ (call $some-func)
+ (call $some-collide)
+ (call_indirect (type $ii)
+ (i32.const 123)
+ (i32.const 456)
+ (i32.const 789)
+ )
+ (drop
+ (get_global $global-collide)
+ )
+ (drop
+ (get_global $global-a)
+ )
+ (set_global $global-collide-mut
+ (i32.const 1234)
+ )
+ )
+ (func $willCollide (; 5 ;) (type $FUNCSIG$v)
+ (drop
+ (i32.const 200)
+ )
+ (call $willCollide)
+ )
+ (func $only-b (; 6 ;) (type $FUNCSIG$v$0)
+ (drop
+ (i32.const 111)
+ )
+ (call $only-b)
+ (call $some-func-b)
+ (call $some-collide$0)
+ (call_indirect (type $ii$0)
+ (i32.const 12)
+ (i32.const 34)
+ (i32.const 56)
+ )
+ (drop
+ (get_global $global-collide$0)
+ )
+ (drop
+ (get_global $global-b)
+ )
+ (set_global $global-collide-mut$0
+ (i32.const 5678)
+ )
+ )
+ (func $willCollide$0 (; 7 ;) (type $FUNCSIG$v$0)
+ (drop
+ (i32.const 222)
+ )
+ (call $willCollide$0)
+ )
+)
diff --git a/test/merge/noBases.wast.combined.finalized b/test/merge/noBases.wast.combined.finalized
new file mode 100644
index 000000000..b9f066f44
--- /dev/null
+++ b/test/merge/noBases.wast.combined.finalized
@@ -0,0 +1,88 @@
+(module
+ (type $ii (func (param i32 i32)))
+ (type $FUNCSIG$v (func))
+ (type $ii$0 (func (param i32 i32)))
+ (type $FUNCSIG$v$0 (func))
+ (import "env" "memory" (memory $0 256))
+ (import "env" "table" (table 1000 anyfunc))
+ (import "env" "some-func" (func $some-func))
+ (import "env" "some-collide" (func $some-collide))
+ (import "env" "memoryBase" (global $memoryBase i32))
+ (import "env" "tableBase" (global $tableBase i32))
+ (import "env" "some-func-b" (func $some-func-b))
+ (import "env" "some-collide" (func $some-collide$0))
+ (import "env" "memoryBase" (global $memoryBase$0 i32))
+ (import "env" "tableBase" (global $tableBase$0 i32))
+ (global $global-collide i32 (i32.const 0))
+ (global $global-collide-mut (mut i32) (i32.const 0))
+ (global $global-a i32 (i32.const 1))
+ (global $global-collide$0 i32 (i32.const 0))
+ (global $global-collide-mut$0 (mut i32) (i32.const 0))
+ (global $global-b i32 (i32.const 1))
+ (elem (i32.const 10) $only-a $willCollide $some-func $some-collide $only-a)
+ (elem (i32.const 20) $only-b $willCollide $some-func-b $some-collide)
+ (data (i32.const 100) "hello, A!\n")
+ (data (i32.const 1024) "")
+ (data (i32.const 200) "hello, B!\n")
+ (export "exp-a" (func $only-a))
+ (export "exp-collide" (func $only-a))
+ (export "exp-collide2" (func $willCollide))
+ (export "exp-b" (func $only-b))
+ (export "exp-b-nameCollided" (func $willCollide$0))
+ (func $only-a (; 4 ;) (type $FUNCSIG$v)
+ (drop
+ (i32.const 100)
+ )
+ (call $only-a)
+ (call $some-func)
+ (call $some-collide)
+ (call_indirect (type $ii)
+ (i32.const 123)
+ (i32.const 456)
+ (i32.const 789)
+ )
+ (drop
+ (get_global $global-collide)
+ )
+ (drop
+ (get_global $global-a)
+ )
+ (set_global $global-collide-mut
+ (i32.const 1234)
+ )
+ )
+ (func $willCollide (; 5 ;) (type $FUNCSIG$v)
+ (drop
+ (i32.const 200)
+ )
+ (call $willCollide)
+ )
+ (func $only-b (; 6 ;) (type $FUNCSIG$v$0)
+ (drop
+ (i32.const 111)
+ )
+ (call $only-b)
+ (call $some-func-b)
+ (call $some-collide$0)
+ (call_indirect (type $ii$0)
+ (i32.const 12)
+ (i32.const 34)
+ (i32.const 56)
+ )
+ (drop
+ (get_global $global-collide$0)
+ )
+ (drop
+ (get_global $global-b)
+ )
+ (set_global $global-collide-mut$0
+ (i32.const 5678)
+ )
+ )
+ (func $willCollide$0 (; 7 ;) (type $FUNCSIG$v$0)
+ (drop
+ (i32.const 222)
+ )
+ (call $willCollide$0)
+ )
+)
diff --git a/test/merge/noBases.wast.combined.finalized.opt b/test/merge/noBases.wast.combined.finalized.opt
new file mode 100644
index 000000000..95e42c10d
--- /dev/null
+++ b/test/merge/noBases.wast.combined.finalized.opt
@@ -0,0 +1,73 @@
+(module
+ (type $ii (func (param i32 i32)))
+ (type $FUNCSIG$v (func))
+ (import "env" "memory" (memory $0 256))
+ (import "env" "table" (table 1000 anyfunc))
+ (import "env" "some-func" (func $some-func))
+ (import "env" "some-collide" (func $some-collide))
+ (import "env" "some-func-b" (func $some-func-b))
+ (import "env" "some-collide" (func $some-collide$0))
+ (global $global-collide i32 (i32.const 0))
+ (global $global-collide-mut (mut i32) (i32.const 0))
+ (global $global-a i32 (i32.const 1))
+ (global $global-collide$0 i32 (i32.const 0))
+ (global $global-collide-mut$0 (mut i32) (i32.const 0))
+ (global $global-b i32 (i32.const 1))
+ (elem (i32.const 10) $only-a $willCollide $some-func $some-collide $only-a)
+ (elem (i32.const 20) $only-b $willCollide $some-func-b $some-collide)
+ (data (i32.const 100) "hello, A!\n")
+ (data (i32.const 200) "hello, B!\n")
+ (export "exp-a" (func $only-a))
+ (export "exp-collide" (func $only-a))
+ (export "exp-collide2" (func $willCollide))
+ (export "exp-b" (func $only-b))
+ (export "exp-b-nameCollided" (func $willCollide$0))
+ (func $only-a (; 4 ;) (type $FUNCSIG$v)
+ (nop)
+ (call $only-a)
+ (call $some-func)
+ (call $some-collide)
+ (call_indirect (type $ii)
+ (i32.const 123)
+ (i32.const 456)
+ (i32.const 789)
+ )
+ (drop
+ (get_global $global-collide)
+ )
+ (drop
+ (get_global $global-a)
+ )
+ (set_global $global-collide-mut
+ (i32.const 1234)
+ )
+ )
+ (func $willCollide (; 5 ;) (type $FUNCSIG$v)
+ (nop)
+ (call $willCollide)
+ )
+ (func $only-b (; 6 ;) (type $FUNCSIG$v)
+ (nop)
+ (call $only-b)
+ (call $some-func-b)
+ (call $some-collide$0)
+ (call_indirect (type $ii)
+ (i32.const 12)
+ (i32.const 34)
+ (i32.const 56)
+ )
+ (drop
+ (get_global $global-collide$0)
+ )
+ (drop
+ (get_global $global-b)
+ )
+ (set_global $global-collide-mut$0
+ (i32.const 5678)
+ )
+ )
+ (func $willCollide$0 (; 7 ;) (type $FUNCSIG$v)
+ (nop)
+ (call $willCollide$0)
+ )
+)
diff --git a/test/merge/noBases.wast.combined.finalized.opt.stdout b/test/merge/noBases.wast.combined.finalized.opt.stdout
new file mode 100644
index 000000000..793188b23
--- /dev/null
+++ b/test/merge/noBases.wast.combined.finalized.opt.stdout
@@ -0,0 +1,3 @@
+merged total memory size: 10
+merged total table size: 5
+merged functions: 4
diff --git a/test/merge/noBases.wast.combined.finalized.stdout b/test/merge/noBases.wast.combined.finalized.stdout
new file mode 100644
index 000000000..793188b23
--- /dev/null
+++ b/test/merge/noBases.wast.combined.finalized.stdout
@@ -0,0 +1,3 @@
+merged total memory size: 10
+merged total table size: 5
+merged functions: 4
diff --git a/test/merge/noBases.wast.combined.opt b/test/merge/noBases.wast.combined.opt
new file mode 100644
index 000000000..d844aa292
--- /dev/null
+++ b/test/merge/noBases.wast.combined.opt
@@ -0,0 +1,76 @@
+(module
+ (type $ii (func (param i32 i32)))
+ (type $FUNCSIG$v (func))
+ (import "env" "memory" (memory $0 256))
+ (import "env" "table" (table 1000 anyfunc))
+ (import "env" "some-func" (func $some-func))
+ (import "env" "some-collide" (func $some-collide))
+ (import "env" "memoryBase" (global $memoryBase i32))
+ (import "env" "tableBase" (global $tableBase i32))
+ (import "env" "some-func-b" (func $some-func-b))
+ (import "env" "some-collide" (func $some-collide$0))
+ (global $global-collide i32 (i32.const 0))
+ (global $global-collide-mut (mut i32) (i32.const 0))
+ (global $global-a i32 (i32.const 1))
+ (global $global-collide$0 i32 (i32.const 0))
+ (global $global-collide-mut$0 (mut i32) (i32.const 0))
+ (global $global-b i32 (i32.const 1))
+ (elem (i32.const 10) $only-a $willCollide $some-func $some-collide $only-a)
+ (elem (i32.const 20) $only-b $willCollide $some-func-b $some-collide)
+ (data (i32.const 100) "hello, A!\n")
+ (data (get_global $memoryBase) "")
+ (data (i32.const 200) "hello, B!\n")
+ (export "exp-a" (func $only-a))
+ (export "exp-collide" (func $only-a))
+ (export "exp-collide2" (func $willCollide))
+ (export "exp-b" (func $only-b))
+ (export "exp-b-nameCollided" (func $willCollide$0))
+ (func $only-a (; 4 ;) (type $FUNCSIG$v)
+ (nop)
+ (call $only-a)
+ (call $some-func)
+ (call $some-collide)
+ (call_indirect (type $ii)
+ (i32.const 123)
+ (i32.const 456)
+ (i32.const 789)
+ )
+ (drop
+ (get_global $global-collide)
+ )
+ (drop
+ (get_global $global-a)
+ )
+ (set_global $global-collide-mut
+ (i32.const 1234)
+ )
+ )
+ (func $willCollide (; 5 ;) (type $FUNCSIG$v)
+ (nop)
+ (call $willCollide)
+ )
+ (func $only-b (; 6 ;) (type $FUNCSIG$v)
+ (nop)
+ (call $only-b)
+ (call $some-func-b)
+ (call $some-collide$0)
+ (call_indirect (type $ii)
+ (i32.const 12)
+ (i32.const 34)
+ (i32.const 56)
+ )
+ (drop
+ (get_global $global-collide$0)
+ )
+ (drop
+ (get_global $global-b)
+ )
+ (set_global $global-collide-mut$0
+ (i32.const 5678)
+ )
+ )
+ (func $willCollide$0 (; 7 ;) (type $FUNCSIG$v)
+ (nop)
+ (call $willCollide$0)
+ )
+)
diff --git a/test/merge/noBases.wast.combined.opt.stdout b/test/merge/noBases.wast.combined.opt.stdout
new file mode 100644
index 000000000..793188b23
--- /dev/null
+++ b/test/merge/noBases.wast.combined.opt.stdout
@@ -0,0 +1,3 @@
+merged total memory size: 10
+merged total table size: 5
+merged functions: 4
diff --git a/test/merge/noBases.wast.combined.stdout b/test/merge/noBases.wast.combined.stdout
new file mode 100644
index 000000000..793188b23
--- /dev/null
+++ b/test/merge/noBases.wast.combined.stdout
@@ -0,0 +1,3 @@
+merged total memory size: 10
+merged total table size: 5
+merged functions: 4
diff --git a/test/merge/noBases.wast.toMerge b/test/merge/noBases.wast.toMerge
new file mode 100644
index 000000000..313b5fb73
--- /dev/null
+++ b/test/merge/noBases.wast.toMerge
@@ -0,0 +1,35 @@
+(module
+ (type $ii (func (param i32 i32)))
+ (import "env" "memory" (memory $0 256))
+ (import "env" "table" (table 1000 anyfunc))
+ (import "env" "some-func-b" (func $some-func-b))
+ (import "env" "some-collide" (func $some-collide))
+ (data (i32.const 200) "hello, B!\n")
+ (global $global-collide i32 (i32.const 0))
+ (global $global-collide-mut (mut i32) (i32.const 0))
+ (global $global-b i32 (i32.const 1))
+ (elem (i32.const 20) $only-b $willCollide $some-func-b $some-collide)
+ (export "exp-b" (func $only-b))
+ (export "exp-collide" (func $only-b))
+ (export "exp-collide2" (func $willCollide))
+ (export "exp-b-nameCollided" (func $willCollide))
+ (func $only-b
+ (drop (i32.const 111))
+ (call $only-b)
+ (call $some-func-b)
+ (call_import $some-collide)
+ (call_indirect (type $ii)
+ (i32.const 12)
+ (i32.const 34)
+ (i32.const 56)
+ )
+ (drop (get_global $global-collide))
+ (drop (get_global $global-b))
+ (set_global $global-collide-mut (i32.const 5678))
+ )
+ (func $willCollide
+ (drop (i32.const 222))
+ (call $willCollide)
+ )
+)
+
diff --git a/test/merge/printf.wast.combined b/test/merge/printf.wast.combined
index 6ea657750..dfaa49d8a 100644
--- a/test/merge/printf.wast.combined
+++ b/test/merge/printf.wast.combined
@@ -11,7 +11,6 @@
(import "env" "memoryBase" (global $memoryBase$0 i32))
(import "env" "tableBase" (global $tableBase$0 i32))
(import "env" "globally" (global $i-collide$0 f64))
-
(data (get_global $memoryBase) "")
(export "_printf" (func $625))
(func $625 (; 1 ;) (type $FUNCSIG$iii) (param $var$0 i32) (param $var$1 i32) (result i32)
diff --git a/test/merge/printf.wast.combined.finalized b/test/merge/printf.wast.combined.finalized
index 7ec67f602..364da8b95 100644
--- a/test/merge/printf.wast.combined.finalized
+++ b/test/merge/printf.wast.combined.finalized
@@ -11,7 +11,6 @@
(import "env" "memoryBase" (global $memoryBase$0 i32))
(import "env" "tableBase" (global $tableBase$0 i32))
(import "env" "globally" (global $i-collide$0 f64))
-
(data (i32.const 1024) "")
(export "_printf" (func $625))
(func $625 (; 1 ;) (type $FUNCSIG$iii) (param $var$0 i32) (param $var$1 i32) (result i32)
diff --git a/test/merge/printf.wast.combined.finalized.opt b/test/merge/printf.wast.combined.finalized.opt
index 52276eed8..8d191bb39 100644
--- a/test/merge/printf.wast.combined.finalized.opt
+++ b/test/merge/printf.wast.combined.finalized.opt
@@ -2,7 +2,6 @@
(type $FUNCSIG$iii (func (param i32 i32) (result i32)))
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 8 anyfunc))
-
(export "_printf" (func $625))
(func $625 (; 0 ;) (type $FUNCSIG$iii) (param $var$0 i32) (param $var$1 i32) (result i32)
(i32.const 102030)
diff --git a/test/merge/printf.wast.combined.opt b/test/merge/printf.wast.combined.opt
index e3471d636..a6ebd316e 100644
--- a/test/merge/printf.wast.combined.opt
+++ b/test/merge/printf.wast.combined.opt
@@ -4,7 +4,6 @@
(import "env" "tableBase" (global $tableBase i32))
(import "env" "memory" (memory $0 256))
(import "env" "table" (table 0 anyfunc))
-
(data (get_global $memoryBase) "")
(export "_printf" (func $625))
(func $625 (; 0 ;) (type $FUNCSIG$iii) (param $var$0 i32) (param $var$1 i32) (result i32)