From cbe71a99f3b53db81cfd23f7a12f2010daeff65d Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 30 Sep 2016 10:47:52 -0700 Subject: Make the linker always create a table segment (#722) 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). --- src/passes/Print.cpp | 2 ++ src/wasm-linker.cpp | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 572732275..275d52888 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -634,6 +634,8 @@ struct PrintSExpression : public Visitor { } doIndent(o, indent); for (auto& segment : curr->segments) { + // Don't print empty segments + if (segment.data.empty()) continue; printOpening(o, "elem ", true); visit(segment.offset); for (auto name : segment.data) { diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 80374c1e4..6e3eae1fb 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -122,6 +122,7 @@ void Linker::layout() { // Pad the indirect function table with a dummy function makeDummyFunction(); + ensureTableIsPopulated(); // Pre-assign the function indexes for (auto& pair : out.indirectIndexes) { @@ -359,6 +360,7 @@ void Linker::makeDummyFunction() { break; } } + if (!create) return; wasm::Builder wasmBuilder(out.wasm); Expression *unreachable = wasmBuilder.makeUnreachable(); -- cgit v1.2.3