diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-06-03 15:48:53 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2016-06-03 15:48:53 -0700 |
commit | c8ec0cd6c053f9e68daf4ba4fdf8137957c1b236 (patch) | |
tree | 559bec6bc2bdc73ea654668b6767a5e0e57ba469 /src/wasm-linker.cpp | |
parent | f6b5c1e5c1c0de26fd078d336782508dd0186820 (diff) | |
download | binaryen-c8ec0cd6c053f9e68daf4ba4fdf8137957c1b236.tar.gz binaryen-c8ec0cd6c053f9e68daf4ba4fdf8137957c1b236.tar.bz2 binaryen-c8ec0cd6c053f9e68daf4ba4fdf8137957c1b236.zip |
Do not generate duplicate import thunks at link time. (#569)
Previously every address-take of an import would cause a new thunk to be
generated. Now check in getImportThunk if the thunk exists already and
just return it if so.
Diffstat (limited to 'src/wasm-linker.cpp')
-rw-r--r-- | src/wasm-linker.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 1aba37b1b..d6c0edb4a 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -145,7 +145,7 @@ void Linker::layout() { if (FunctionType* f = out.getExternType(name)) { // Address of an imported function is taken, but imports do not have addresses in wasm. // Generate a thunk to forward to the call_import. - Function* thunk = generateImportThunk(name, f); + Function* thunk = getImportThunk(name, f); ensureFunctionIndex(thunk->name); *(relocation->data) = functionIndexes[thunk->name] + relocation->addend; } else { @@ -381,12 +381,14 @@ void Linker::makeDynCallThunks() { } } -Function* Linker::generateImportThunk(Name name, const FunctionType* funcType) { +Function* Linker::getImportThunk(Name name, const FunctionType* funcType) { + Name thunkName = std::string("__importThunk_") + name.c_str(); + if (Function* thunk = out.wasm.checkFunction(thunkName)) return thunk; wasm::Builder wasmBuilder(out.wasm); std::vector<NameType> params; Index p = 0; for (const auto& ty : funcType->params) params.emplace_back(std::to_string(p++), ty); - Function *f = wasmBuilder.makeFunction(std::string("__importThunk_") + name.c_str(), std::move(params), funcType->result, {}); + Function *f = wasmBuilder.makeFunction(thunkName, std::move(params), funcType->result, {}); std::vector<Expression*> args; for (Index i = 0; i < funcType->params.size(); ++i) { args.push_back(wasmBuilder.makeGetLocal(i, funcType->params[i])); |