Skip to content

Commit 7773426

Browse files
authored
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.
1 parent 36909a3 commit 7773426

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,22 @@ full changeset diff at the end of each section.
1515
Current Trunk
1616
-------------
1717

18+
- wasm-emscripten-finalize: Don't realy on name section being present in the
19+
input. Use the exported names for things instead.
20+
21+
v88
22+
---
23+
1824
- wasm-emscripten-finalize: For -pie binaries that import a mutable stack
1925
pointer we internalize this an import it as immutable.
2026
- The `tail-call` feature including the `return_call` and `return_call_indirect`
2127
instructions is ready to use.
2228

29+
v87
30+
---
31+
32+
- Rename Bysyncify => Asyncify
33+
2334
v86
2435
---
2536

src/tools/wasm-emscripten-finalize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ int main(int argc, const char* argv[]) {
229229
initializerFunctions.push_back(F->name);
230230
}
231231
if (auto* e = wasm.getExportOrNull(WASM_CALL_CTORS)) {
232-
initializerFunctions.push_back(e->value);
232+
initializerFunctions.push_back(e->name);
233233
}
234234
}
235235

src/wasm/wasm-emscripten.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,18 +848,19 @@ struct EmJsWalker : public PostWalker<EmJsWalker> {
848848
EmJsWalker(Module& _wasm)
849849
: wasm(_wasm), segmentOffsets(getSegmentOffsets(wasm)) {}
850850

851-
void visitFunction(Function* curr) {
852-
if (curr->imported()) {
851+
void visitExport(Export* curr) {
852+
if (curr->kind != ExternalKind::Function) {
853853
return;
854854
}
855855
if (!curr->name.startsWith(EM_JS_PREFIX.str)) {
856856
return;
857857
}
858+
auto* func = wasm.getFunction(curr->value);
858859
auto funcName = std::string(curr->name.stripPrefix(EM_JS_PREFIX.str));
859860
// An EM_JS has a single const in the body. Typically it is just returned,
860861
// but in unoptimized code it might be stored to a local and loaded from
861862
// there, and in relocatable code it might get added to __memory_base etc.
862-
FindAll<Const> consts(curr->body);
863+
FindAll<Const> consts(func->body);
863864
if (consts.list.size() != 1) {
864865
Fatal() << "Unexpected generated __em_js__ function body: " << curr->name;
865866
}

0 commit comments

Comments
 (0)