diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -172,6 +172,9 @@ bool isStub : 1; uint32_t flags; + + llvm::Optional importName; + llvm::Optional importModule; }; class FunctionSymbol : public Symbol { @@ -222,15 +225,15 @@ const WasmSignature *type = nullptr, bool isCalledDirectly = true) : FunctionSymbol(name, UndefinedFunctionKind, flags, file, type), - importName(importName), importModule(importModule), - isCalledDirectly(isCalledDirectly) {} + isCalledDirectly(isCalledDirectly) { + this->importName = importName; + this->importModule = importModule; + } static bool classof(const Symbol *s) { return s->kind() == UndefinedFunctionKind; } - llvm::Optional importName; - llvm::Optional importModule; DefinedFunction *stubFunction = nullptr; bool isCalledDirectly; }; @@ -354,15 +357,14 @@ llvm::Optional importModule, uint32_t flags, InputFile *file = nullptr, const WasmGlobalType *type = nullptr) - : GlobalSymbol(name, UndefinedGlobalKind, flags, file, type), - importName(importName), importModule(importModule) {} + : GlobalSymbol(name, UndefinedGlobalKind, flags, file, type) { + this->importName = importName; + this->importModule = importModule; + } static bool classof(const Symbol *s) { return s->kind() == UndefinedGlobalKind; } - - llvm::Optional importName; - llvm::Optional importModule; }; class TableSymbol : public Symbol { @@ -403,15 +405,14 @@ UndefinedTable(StringRef name, llvm::Optional importName, llvm::Optional importModule, uint32_t flags, InputFile *file, const WasmTableType *type) - : TableSymbol(name, UndefinedTableKind, flags, file, type), - importName(importName), importModule(importModule) {} + : TableSymbol(name, UndefinedTableKind, flags, file, type) { + this->importName = importName; + this->importModule = importModule; + } static bool classof(const Symbol *s) { return s->kind() == UndefinedTableKind; } - - llvm::Optional importName; - llvm::Optional importModule; }; // A tag is a general format to distinguish typed entities. Each tag has an diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp --- a/lld/wasm/SyntheticSections.cpp +++ b/lld/wasm/SyntheticSections.cpp @@ -145,15 +145,9 @@ for (const Symbol *sym : importedSymbols) { WasmImport import; - if (auto *f = dyn_cast(sym)) { - import.Field = f->importName ? *f->importName : sym->getName(); - import.Module = f->importModule ? *f->importModule : defaultModule; - } else if (auto *g = dyn_cast(sym)) { - import.Field = g->importName ? *g->importName : sym->getName(); - import.Module = g->importModule ? *g->importModule : defaultModule; - } else if (auto *t = dyn_cast(sym)) { - import.Field = t->importName ? *t->importName : sym->getName(); - import.Module = t->importModule ? *t->importModule : defaultModule; + if (sym->isUndefined()) { + import.Field = sym->importName.getValueOr(sym->getName()); + import.Module = sym->importModule.getValueOr(defaultModule); } else { import.Field = sym->getName(); import.Module = defaultModule; diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -562,12 +562,8 @@ return true; if (config->allowUndefinedSymbols.count(sym->getName()) != 0) return true; - if (auto *g = dyn_cast(sym)) - return g->importName.hasValue(); - if (auto *f = dyn_cast(sym)) - return f->importName.hasValue(); - if (auto *t = dyn_cast(sym)) - return t->importName.hasValue(); + if (sym->isUndefined()) + return sym->importName.hasValue(); return false; } diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -53,7 +53,7 @@ if (auto BinOp = dyn_cast(Expr)) { auto SectionLHS = getFixupSection(BinOp->getLHS()); auto SectionRHS = getFixupSection(BinOp->getRHS()); - return SectionLHS == SectionRHS ? nullptr : SectionLHS; + return SectionLHS == SectionRHS ? SectionLHS : nullptr; } if (auto UnOp = dyn_cast(Expr))