From 7cc0753118473b5a1c646b826819b294a55c302e Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 1 Feb 2019 02:29:57 +0000 Subject: [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 --- lld/wasm/Writer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lld/wasm/Writer.cpp') 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(Sym)) + Import.Module = F->Module; + else + Import.Module = kDefaultModule; + Import.Field = Sym->getName(); if (auto *FunctionSym = dyn_cast(Sym)) { Import.Kind = WASM_EXTERNAL_FUNCTION; -- cgit v1.2.3