summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2019-03-13 14:19:40 -0700
committerGitHub <noreply@github.com>2019-03-13 14:19:40 -0700
commite18ab2a0cd8b36144578d37585e8a67af618ecd1 (patch)
tree146f3993523f912e3cfac286584a685681a5ce51 /src
parent0c429ea85f309353c68ea887303ccd1f3935b15e (diff)
downloadbinaryen-e18ab2a0cd8b36144578d37585e8a67af618ecd1.tar.gz
binaryen-e18ab2a0cd8b36144578d37585e8a67af618ecd1.tar.bz2
binaryen-e18ab2a0cd8b36144578d37585e8a67af618ecd1.zip
Add some checking in EmscriptenGlueGenerator::generateStackInitialization (#1944)
We expect the stack pointer to be of a certain type. This fixes a segfault we are seeing when passed a binary which doesn't quite meet our expectations.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-emscripten.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index a21c45476..ea24b945d 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -47,10 +47,15 @@ void addExportedFunction(Module& wasm, Function* function) {
}
Global* EmscriptenGlueGenerator::getStackPointerGlobal() {
- // Assumption: first global is __stack_pointer
- // TODO(sbc): Once mutable globals are a thing we shouldn't need this
- // at all since we can simply export __stack_pointer.
- return wasm.globals[0].get();
+ // Assumption: The first non-imported global is global is __stack_pointer
+ // 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()) {
+ return g.get();
+ }
+ }
+ Fatal() << "stack pointer global not found";
}
Expression* EmscriptenGlueGenerator::generateLoadStackPointer() {
@@ -157,6 +162,9 @@ Function* EmscriptenGlueGenerator::generateMemoryGrowthFunction() {
void EmscriptenGlueGenerator::generateStackInitialization(Address addr) {
auto* stackPointer = getStackPointerGlobal();
+ assert(!stackPointer->imported());
+ if (!stackPointer->init || !stackPointer->init->is<Const>())
+ Fatal() << "stack pointer global is not assignable";
stackPointer->init->cast<Const>()->value = Literal(int32_t(addr));
}