summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2022-01-20 13:59:49 -0800
committerGitHub <noreply@github.com>2022-01-20 21:59:49 +0000
commit4205846f0f7cc795808d8737fd9a0c2c2e2ab41d (patch)
tree386681d3e18b2a90651452ece117f6b3acfbdb6d /src
parenta1b38c796629f8042d1e1accf4708a6a86bfd408 (diff)
downloadbinaryen-4205846f0f7cc795808d8737fd9a0c2c2e2ab41d.tar.gz
binaryen-4205846f0f7cc795808d8737fd9a0c2c2e2ab41d.tar.bz2
binaryen-4205846f0f7cc795808d8737fd9a0c2c2e2ab41d.zip
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 https://github.com/emscripten-core/emscripten/issues/12682 This heuristic still kind of sucks but should always be good enough for llvm output that always puts the stack pointer first.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-emscripten.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 33a92a6c4..ed2f0f430 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -55,15 +55,16 @@ bool isExported(Module& wasm, Name name) {
Global* getStackPointerGlobal(Module& wasm) {
// Assumption: The stack pointer is either imported as __stack_pointer or
- // its the first non-imported and non-exported global.
+ // we just assume it's the first non-imported global.
// TODO(sbc): Find a better way to discover the stack pointer. Perhaps the
// linker could export it by name?
for (auto& g : wasm.globals) {
- if (g->imported()) {
- if (g->base == STACK_POINTER) {
- return g.get();
- }
- } else if (!isExported(wasm, g->name)) {
+ if (g->imported() && g->base == STACK_POINTER) {
+ return g.get();
+ }
+ }
+ for (auto& g : wasm.globals) {
+ if (!g->imported()) {
return g.get();
}
}