diff options
Diffstat (limited to 'src/passes/PostEmscripten.cpp')
-rw-r--r-- | src/passes/PostEmscripten.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index 8efaae8c5..68f0c06e0 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -28,8 +28,11 @@ #include <pass.h> #include <shared-constants.h> #include <wasm-builder.h> +#include <wasm-emscripten.h> #include <wasm.h> +#define DEBUG_TYPE "post-emscripten" + namespace wasm { namespace { @@ -75,6 +78,24 @@ struct OptimizeCalls : public WalkerPass<PostWalker<OptimizeCalls>> { struct PostEmscripten : public Pass { void run(PassRunner* runner, Module* module) override { + // Apply the stack pointer, if it was provided. This is needed here + // because the emscripten JS compiler can add static data allocations that + // come before the stack. + auto stackPtrStr = + runner->options.getArgumentOrDefault("stack-pointer", ""); + if (stackPtrStr != "") { + Global* stackPointer = getStackPointerGlobal(*module); + BYN_TRACE("stack_pointer: " << stackPtrStr << "\n"); + if (stackPointer && !stackPointer->imported()) { + auto stackPtr = std::stoi(stackPtrStr); + auto oldValue = stackPointer->init->cast<Const>()->value; + BYN_TRACE("updating __stack_pointer: " << oldValue.geti32() << " -> " + << stackPtr << "\n"); + stackPointer->init = + Builder(*module).makeConst(Literal(int32_t(stackPtr))); + } + } + // Apply the sbrk ptr, if it was provided. auto sbrkPtrStr = runner->options.getArgumentOrDefault("emscripten-sbrk-ptr", ""); |