From 777342684f5af51105be710c06591513433ed879 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 6 Aug 2019 17:25:05 -0700 Subject: wasm-emscripten-finalize: Remove reliance on name section (#2285) There were a couple of places where we were relying on internal names and therefore a name section. After this change wasm-emscripten-finalize works correctly on binaries without a name section at all and only relies on the names of imports and exports. --- src/wasm/wasm-emscripten.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/wasm/wasm-emscripten.cpp') diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index c21016baa..caea83302 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -848,18 +848,19 @@ struct EmJsWalker : public PostWalker { EmJsWalker(Module& _wasm) : wasm(_wasm), segmentOffsets(getSegmentOffsets(wasm)) {} - void visitFunction(Function* curr) { - if (curr->imported()) { + void visitExport(Export* curr) { + if (curr->kind != ExternalKind::Function) { return; } if (!curr->name.startsWith(EM_JS_PREFIX.str)) { return; } + auto* func = wasm.getFunction(curr->value); auto funcName = std::string(curr->name.stripPrefix(EM_JS_PREFIX.str)); // An EM_JS has a single const in the body. Typically it is just returned, // but in unoptimized code it might be stored to a local and loaded from // there, and in relocatable code it might get added to __memory_base etc. - FindAll consts(curr->body); + FindAll consts(func->body); if (consts.list.size() != 1) { Fatal() << "Unexpected generated __em_js__ function body: " << curr->name; } -- cgit v1.2.3