diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-06-02 14:30:30 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2016-06-02 14:30:30 -0700 |
commit | d4dc216888d5028f41e6189e65001694e49a66c2 (patch) | |
tree | 35ac5962bedb07fa732b34b62f7b7c3d68280ce4 /src/wasm-linker.h | |
parent | d595e89003dc3636952de4c561679e3a077e6015 (diff) | |
download | binaryen-d4dc216888d5028f41e6189e65001694e49a66c2.tar.gz binaryen-d4dc216888d5028f41e6189e65001694e49a66c2.tar.bz2 binaryen-d4dc216888d5028f41e6189e65001694e49a66c2.zip |
Generate thunks for address-taken imports (#554)
Under emscripten, C code can take the address of a function implemented
in Javascript (which is exposed via an import in wasm). Because imports
do not have linear memory address in wasm, we need to generate a thunk
to be the target of the indirect call; it call the import directly.
This is facilited by a new .s directive (.functype) which declares the
types of functions which are declared but not defined.
Fixes https://github.com/WebAssembly/binaryen/issues/392
Diffstat (limited to 'src/wasm-linker.h')
-rw-r--r-- | src/wasm-linker.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/wasm-linker.h b/src/wasm-linker.h index 5fe01b393..a0684d02b 100644 --- a/src/wasm-linker.h +++ b/src/wasm-linker.h @@ -119,6 +119,15 @@ class LinkerObject { undefinedFunctionCalls[call->target].push_back(call); } + void addExternType(Name name, FunctionType* ty) { + externTypesMap[name] = ty; + } + FunctionType* getExternType(Name name) { + auto f = externTypesMap.find(name); + if (f == externTypesMap.end()) return nullptr; + return f->second; + } + bool isEmpty() { return wasm.functions.empty(); } @@ -146,6 +155,9 @@ class LinkerObject { using CallList = std::vector<Call*>; std::map<Name, CallList> undefinedFunctionCalls; + // Types of functions which are declared but not defined. + std::unordered_map<cashew::IString, FunctionType*> externTypesMap; + std::map<Name, Address> segments; // name => segment index (in wasm module) std::vector<Name> initializerFunctions; @@ -244,6 +256,8 @@ class Linker { o << "]"; } + void ensureImport(Name target, std::string signature); + // Create thunks for use with emscripten Runtime.dynCall. Creates one for each // signature in the indirect function table. void makeDynCallThunks(); @@ -263,6 +277,8 @@ class Linker { out.wasm.addExport(exp); } + Function* generateImportThunk(Name name, const FunctionType* t); + // The output module (linked executable) LinkerObject out; |