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 | |
| 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')
| -rw-r--r-- | lld/wasm/InputFiles.cpp | 5 | ||||
| -rw-r--r-- | lld/wasm/LTO.cpp | 4 | ||||
| -rw-r--r-- | lld/wasm/LTO.h | 1 | ||||
| -rw-r--r-- | lld/wasm/SymbolTable.cpp | 6 | ||||
| -rw-r--r-- | lld/wasm/SymbolTable.h | 4 | ||||
| -rw-r--r-- | lld/wasm/Symbols.h | 8 | ||||
| -rw-r--r-- | lld/wasm/Writer.cpp | 11 | ||||
| -rw-r--r-- | lld/wasm/Writer.h | 2 |
8 files changed, 27 insertions, 14 deletions
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 19018d28028..95aa2684949 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -378,7 +378,8 @@ Symbol *ObjFile::createUndefined(const WasmSymbol &Sym) { switch (Sym.Info.Kind) { case WASM_SYMBOL_TYPE_FUNCTION: - return Symtab->addUndefinedFunction(Name, Flags, this, Sym.Signature); + return Symtab->addUndefinedFunction(Name, Sym.Info.Module, Flags, this, + Sym.Signature); case WASM_SYMBOL_TYPE_DATA: return Symtab->addUndefinedData(Name, Flags, this); case WASM_SYMBOL_TYPE_GLOBAL: @@ -446,7 +447,7 @@ static Symbol *createBitcodeSymbol(const lto::InputFile::Symbol &ObjSym, if (ObjSym.isUndefined()) { if (ObjSym.isExecutable()) - return Symtab->addUndefinedFunction(Name, Flags, &F, nullptr); + return Symtab->addUndefinedFunction(Name, kDefaultModule, Flags, &F, nullptr); return Symtab->addUndefinedData(Name, Flags, &F); } diff --git a/lld/wasm/LTO.cpp b/lld/wasm/LTO.cpp index 584893d75b8..0e76dc214ed 100644 --- a/lld/wasm/LTO.cpp +++ b/lld/wasm/LTO.cpp @@ -80,8 +80,8 @@ BitcodeCompiler::~BitcodeCompiler() = default; static void undefine(Symbol *S) { if (auto F = dyn_cast<DefinedFunction>(S)) - replaceSymbol<UndefinedFunction>(F, F->getName(), 0, F->getFile(), - F->Signature); + replaceSymbol<UndefinedFunction>(F, F->getName(), kDefaultModule, 0, + F->getFile(), F->Signature); else if (isa<DefinedData>(S)) replaceSymbol<UndefinedData>(S, S->getName(), 0, S->getFile()); else diff --git a/lld/wasm/LTO.h b/lld/wasm/LTO.h index 57a27343932..37fea7ad6ee 100644 --- a/lld/wasm/LTO.h +++ b/lld/wasm/LTO.h @@ -22,6 +22,7 @@ #include "lld/Common/LLVM.h" #include "llvm/ADT/SmallString.h" +#include "Writer.h" #include <memory> #include <vector> diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index f490d4c7191..e45dc6bec71 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -315,8 +315,8 @@ Symbol *SymbolTable::addDefinedEvent(StringRef Name, uint32_t Flags, return S; } -Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags, - InputFile *File, +Symbol *SymbolTable::addUndefinedFunction(StringRef Name, StringRef Module, + uint32_t Flags, InputFile *File, const WasmSignature *Sig) { LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name << " [" << (Sig ? toString(*Sig) : "none") << "]\n"); @@ -326,7 +326,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags, std::tie(S, WasInserted) = insert(Name, File); if (WasInserted) - replaceSymbol<UndefinedFunction>(S, Name, Flags, File, Sig); + replaceSymbol<UndefinedFunction>(S, Name, Module, Flags, File, Sig); else if (auto *Lazy = dyn_cast<LazySymbol>(S)) Lazy->fetch(); else diff --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h index b721984e841..f0bdd6cc01c 100644 --- a/lld/wasm/SymbolTable.h +++ b/lld/wasm/SymbolTable.h @@ -58,8 +58,8 @@ public: Symbol *addDefinedEvent(StringRef Name, uint32_t Flags, InputFile *File, InputEvent *E); - Symbol *addUndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File, - const WasmSignature *Signature); + Symbol *addUndefinedFunction(StringRef Name, StringRef Module, uint32_t Flags, + InputFile *File, const WasmSignature *Signature); Symbol *addUndefinedData(StringRef Name, uint32_t Flags, InputFile *File); Symbol *addUndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File, const WasmGlobalType *Type); diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h index 63c023935cb..652d0a9ef6a 100644 --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -155,13 +155,17 @@ public: class UndefinedFunction : public FunctionSymbol { public: - UndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File = nullptr, + UndefinedFunction(StringRef Name, StringRef Module, uint32_t Flags, + InputFile *File = nullptr, const WasmSignature *Type = nullptr) - : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type) {} + : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type), + Module(Module) {} static bool classof(const Symbol *S) { return S->kind() == UndefinedFunctionKind; } + + StringRef Module; }; class SectionSymbol : public Symbol { 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; diff --git a/lld/wasm/Writer.h b/lld/wasm/Writer.h index d83e4cbda62..cf3681ddf35 100644 --- a/lld/wasm/Writer.h +++ b/lld/wasm/Writer.h @@ -14,6 +14,8 @@ namespace wasm { void writeResult(); +extern const char *kDefaultModule; + } // namespace wasm } // namespace lld |

