diff options
| author | Sam Clegg <sbc@chromium.org> | 2019-02-01 02:29:57 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2019-02-01 02:29:57 +0000 |
| commit | 7cc0753118473b5a1c646b826819b294a55c302e (patch) | |
| tree | 5cd1280d804cc17bb7f2edf5171d3368c33a5075 /lld/wasm/Writer.cpp | |
| parent | 13680223b9d80bb01e17372f0907cf215e424cce (diff) | |
| download | bcm5719-llvm-7cc0753118473b5a1c646b826819b294a55c302e.tar.gz bcm5719-llvm-7cc0753118473b5a1c646b826819b294a55c302e.zip | |
[WebAssembly] Support imports from custom module names
Fixes: https://bugs.llvm.org/show_bug.cgi?id=37168
This is only a first pass at supporting these custom import
modules. In the long run we most likely want to treat these
kinds of symbols very differently. For example, it should not
be possible to resolve such as symbol at static link type.
Differential Revision: https://reviews.llvm.org/D45796
llvm-svn: 352828
Diffstat (limited to 'lld/wasm/Writer.cpp')
| -rw-r--r-- | lld/wasm/Writer.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index d8986c83738..a1b40971ea0 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -41,6 +41,7 @@ using namespace lld::wasm; static constexpr int kStackAlignment = 16; static constexpr const char *kFunctionTableName = "__indirect_function_table"; +const char *lld::wasm::kDefaultModule = "env"; namespace { @@ -156,7 +157,7 @@ void Writer::createImportSection() { if (Config->ImportMemory) { WasmImport Import; - Import.Module = "env"; + Import.Module = kDefaultModule; Import.Field = "memory"; Import.Kind = WASM_EXTERNAL_MEMORY; Import.Memory.Flags = 0; @@ -173,7 +174,7 @@ void Writer::createImportSection() { if (Config->ImportTable) { uint32_t TableSize = TableBase + IndirectFunctions.size(); WasmImport Import; - Import.Module = "env"; + Import.Module = kDefaultModule; Import.Field = kFunctionTableName; Import.Kind = WASM_EXTERNAL_TABLE; Import.Table.ElemType = WASM_TYPE_FUNCREF; @@ -183,7 +184,11 @@ void Writer::createImportSection() { for (const Symbol *Sym : ImportedSymbols) { WasmImport Import; - Import.Module = "env"; + if (auto *F = dyn_cast<UndefinedFunction>(Sym)) + Import.Module = F->Module; + else + Import.Module = kDefaultModule; + Import.Field = Sym->getName(); if (auto *FunctionSym = dyn_cast<FunctionSymbol>(Sym)) { Import.Kind = WASM_EXTERNAL_FUNCTION; |

