diff options
author | Alon Zakai <azakai@google.com> | 2022-01-06 14:05:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-06 14:05:29 -0800 |
commit | 5906a1f120e1485153d1effdc5557e576fd2fc61 (patch) | |
tree | f796699a481004eeffdc20960da52b7f7383456e /src | |
parent | 73897b0884ebbf8555a811fe0263f1f5f05bd756 (diff) | |
download | binaryen-5906a1f120e1485153d1effdc5557e576fd2fc61.tar.gz binaryen-5906a1f120e1485153d1effdc5557e576fd2fc61.tar.bz2 binaryen-5906a1f120e1485153d1effdc5557e576fd2fc61.zip |
[ctor-eval] Remove stack hacks (#4429)
Remove some hackish code for fastcomp's stack handling. The stack pointer arrives
in an imported global there. Upstream does not do this, so this code is completely
unneeded these days (and, frankly, kind of scary as I read it now... it modeled the
stack as separate memory from the heap...).
Remove the tests for this as well. I verified that there was nothing else in those
tests that we need to keep.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 57 |
1 files changed, 2 insertions, 55 deletions
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index a44ea3ceb..f03bbec1d 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -112,18 +112,6 @@ public: Iterator end() { return Iterator(); } }; -// Use a ridiculously large stack size. -static Index STACK_SIZE = 32 * 1024 * 1024; - -// Start the stack at a ridiculously large location, and do so in -// a way that works regardless if the stack goes up or down. -static Index STACK_START = 1024 * 1024 * 1024 + STACK_SIZE; - -// Bound the stack location in both directions, so we have bounds -// that do not depend on the direction it grows. -static Index STACK_LOWER_LIMIT = STACK_START - STACK_SIZE; -static Index STACK_UPPER_LIMIT = STACK_START + STACK_SIZE; - class EvallingModuleInstance : public ModuleInstanceBase<EvallingGlobalManager, EvallingModuleInstance> { public: @@ -136,36 +124,12 @@ public: // global import, which we don't have, and is illegal to use ModuleUtils::iterDefinedGlobals(wasm, [&](Global* global) { if (!global->init->is<Const>()) { - // some constants are ok to use - if (auto* get = global->init->dynCast<GlobalGet>()) { - auto name = get->name; - auto* import = wasm.getGlobal(name); - if (import->module == Name(ENV) && - (import->base == - STACKTOP || // stack constants are special, we handle them - import->base == STACK_MAX)) { - return; // this is fine - } - } // this global is dangerously initialized by an import, so if it is // used, we must fail globals.addDangerous(global->name); } }); } - - std::vector<char> stack; - - // create C stack space for us to use. We do *NOT* care about their contents, - // assuming the stack top was unwound. the memory may have been modified, - // but it should not be read afterwards, doing so would be undefined behavior - void setupEnvironment() { - // prepare scratch memory - stack.resize(2 * STACK_SIZE); - // tell the module to accept writes up to the stack end - auto total = STACK_START + STACK_SIZE; - memorySize = total / Memory::kPageSize; - } }; // Build an artificial `env` module based on a module's imports, so that the @@ -207,11 +171,7 @@ std::unique_ptr<Module> buildEnvModule(Module& wasm) { copied->base = Name(); Builder builder(*env); - if (global->base == STACKTOP || global->base == STACK_MAX) { - copied->init = builder.makeConst(STACK_START); - } else { - copied->init = builder.makeConst(Literal::makeZero(global->type)); - } + copied->init = builder.makeConst(Literal::makeZero(global->type)); env->addExport( builder.makeExport(global->base, copied->name, ExternalKind::Global)); } @@ -405,17 +365,7 @@ private: // TODO: handle unaligned too, see shell-interface template<typename T> T* getMemory(Address address) { - // if memory is on the stack, use the stack - if (address >= STACK_LOWER_LIMIT) { - if (address >= STACK_UPPER_LIMIT) { - throw FailToEvalException("stack usage too high"); - } - Address relative = address - STACK_LOWER_LIMIT; - // in range, all is good, use the stack - return (T*)(&instance->stack[relative]); - } - - // otherwise, this must be in the singleton segment. resize as needed + // this must be in the singleton segment. resize as needed if (wasm->memory.segments.size() == 0) { std::vector<char> temp; Builder builder(*wasm); @@ -452,7 +402,6 @@ void evalCtors(Module& wasm, std::vector<std::string> ctors) { CtorEvalExternalInterface envInterface; auto envInstance = std::make_shared<EvallingModuleInstance>(*envModule, &envInterface); - envInstance->setupEnvironment(); std::map<Name, std::shared_ptr<EvallingModuleInstance>> linkedInstances; linkedInstances["env"] = envInstance; @@ -466,8 +415,6 @@ void evalCtors(Module& wasm, std::vector<std::string> ctors) { // create an instance for evalling EvallingModuleInstance instance(wasm, &interface, linkedInstances); - // set up the stack area and other environment details - instance.setupEnvironment(); // we should not add new globals from here on; as a result, using // an imported global will fail, as it is missing and so looks new instance.globals.seal(); |