Skip to content

Commit 4205846

Browse files
authored
Update heuristic for finding __stack_pointer to allow exports. NFC (#4467)
There is no reason the `__stack_pointer` global can't be exported from the module, and in fact I'm experimenting with a non-relocatable main module that requires this. See emscripten-core/emscripten#12682 This heuristic still kind of sucks but should always be good enough for llvm output that always puts the stack pointer first.
1 parent a1b38c7 commit 4205846

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/wasm/wasm-emscripten.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ bool isExported(Module& wasm, Name name) {
5555

5656
Global* getStackPointerGlobal(Module& wasm) {
5757
// Assumption: The stack pointer is either imported as __stack_pointer or
58-
// its the first non-imported and non-exported global.
58+
// we just assume it's the first non-imported global.
5959
// TODO(sbc): Find a better way to discover the stack pointer. Perhaps the
6060
// linker could export it by name?
6161
for (auto& g : wasm.globals) {
62-
if (g->imported()) {
63-
if (g->base == STACK_POINTER) {
64-
return g.get();
65-
}
66-
} else if (!isExported(wasm, g->name)) {
62+
if (g->imported() && g->base == STACK_POINTER) {
63+
return g.get();
64+
}
65+
}
66+
for (auto& g : wasm.globals) {
67+
if (!g->imported()) {
6768
return g.get();
6869
}
6970
}

0 commit comments

Comments
 (0)