Index: lld/wasm/InputFiles.h =================================================================== --- lld/wasm/InputFiles.h +++ lld/wasm/InputFiles.h @@ -118,10 +118,7 @@ uint32_t relocateTableIndex(uint32_t Original) const; uint32_t relocateSymbolIndex(uint32_t Original) const; - Symbol *createDefinedData(const WasmSymbol &Sym, InputSegment *Segment, - uint32_t Offset, uint32_t DataSize); - Symbol *createDefinedFunction(const WasmSymbol &Sym, InputFunction *Function); - Symbol *createDefinedGlobal(const WasmSymbol &Sym, InputGlobal *Global); + Symbol *createDefined(const WasmSymbol &Sym); Symbol *createUndefined(const WasmSymbol &Sym); void initializeSymbols(); Index: lld/wasm/InputFiles.cpp =================================================================== --- lld/wasm/InputFiles.cpp +++ lld/wasm/InputFiles.cpp @@ -224,77 +224,59 @@ // Populate `Symbols` based on the WasmSymbols in the object for (const SymbolRef &Sym : WasmObj->symbols()) { const WasmSymbol &WasmSym = WasmObj->getWasmSymbol(Sym.getRawDataRefImpl()); - bool IsDefined = WasmSym.isDefined(); - - if (IsDefined) { - switch (WasmSym.Info.Kind) { - case WASM_SYMBOL_TYPE_FUNCTION: { - InputFunction *Function = getFunction(WasmSym); - if (isExcludedByComdat(Function)) { - Function->Live = false; - IsDefined = false; - break; - } - Symbols.push_back(createDefinedFunction(WasmSym, Function)); - break; - } - case WASM_SYMBOL_TYPE_DATA: { - InputSegment *Segment = getSegment(WasmSym); - if (isExcludedByComdat(Segment)) { - Segment->Live = false; - IsDefined = false; - break; - } - Symbols.push_back(createDefinedData(WasmSym, Segment, - WasmSym.Info.DataRef.Offset, - WasmSym.Info.DataRef.Size)); - break; - } - case WASM_SYMBOL_TYPE_GLOBAL: - Symbols.push_back(createDefinedGlobal(WasmSym, getGlobal(WasmSym))); - break; - default: - llvm_unreachable("unkown symbol kind"); - break; - } - } - // Either the the symbol itself was undefined, or was excluded via comdat - // in which case this simply insertes the existing symbol into the correct - // slot in the Symbols array. - if (!IsDefined) + if (Symbol *Sym = createDefined(WasmSym)) + Symbols.push_back(Sym); + else Symbols.push_back(createUndefined(WasmSym)); } } -Symbol *ObjFile::createUndefined(const WasmSymbol &Sym) { - return Symtab->addUndefined( - Sym.Info.Name, static_cast(Sym.Info.Kind), Sym.Info.Flags, - this, Sym.FunctionType, Sym.GlobalType); -} +Symbol *ObjFile::createDefined(const WasmSymbol &Sym) { + if (!Sym.isDefined()) + return nullptr; -Symbol *ObjFile::createDefinedFunction(const WasmSymbol &Sym, - InputFunction *Function) { - if (Sym.isBindingLocal()) - return make(Sym.Info.Name, Sym.Info.Flags, this, Function); - return Symtab->addDefinedFunction(Sym.Info.Name, Sym.Info.Flags, this, - Function); -} + switch (Sym.Info.Kind) { + case WASM_SYMBOL_TYPE_FUNCTION: { + InputFunction *Func = getFunction(Sym); + if (isExcludedByComdat(Func)) { + Func->Live = false; + return nullptr; + } + + if (Sym.isBindingLocal()) + return make(Sym.Info.Name, Sym.Info.Flags, this, Func); + return Symtab->addDefinedFunction(Sym.Info.Name, Sym.Info.Flags, this, + Func); + } + case WASM_SYMBOL_TYPE_DATA: { + InputSegment *Seg = getSegment(Sym); + if (isExcludedByComdat(Seg)) { + Seg->Live = false; + return nullptr; + } + + uint32_t Offset = Sym.Info.DataRef.Offset; + uint32_t Size = Sym.Info.DataRef.Size; -Symbol *ObjFile::createDefinedData(const WasmSymbol &Sym, InputSegment *Segment, - uint32_t Offset, uint32_t Size) { - if (Sym.isBindingLocal()) - return make(Sym.Info.Name, Sym.Info.Flags, this, Segment, - Offset, Size); - return Symtab->addDefinedData(Sym.Info.Name, Sym.Info.Flags, this, Segment, - Offset, Size); + if (Sym.isBindingLocal()) + return make(Sym.Info.Name, Sym.Info.Flags, this, Seg, + Offset, Size); + return Symtab->addDefinedData(Sym.Info.Name, Sym.Info.Flags, this, Seg, + Offset, Size); + } + case WASM_SYMBOL_TYPE_GLOBAL: + if (Sym.isBindingLocal()) + return make(Sym.Info.Name, Sym.Info.Flags, this, getGlobal(Sym)); + return Symtab->addDefinedGlobal(Sym.Info.Name, Sym.Info.Flags, this, getGlobal(Sym)); + } + llvm_unreachable("unkown symbol kind"); } -Symbol *ObjFile::createDefinedGlobal(const WasmSymbol &Sym, - InputGlobal *Global) { - if (Sym.isBindingLocal()) - return make(Sym.Info.Name, Sym.Info.Flags, this, Global); - return Symtab->addDefinedGlobal(Sym.Info.Name, Sym.Info.Flags, this, Global); +Symbol *ObjFile::createUndefined(const WasmSymbol &Sym) { + return Symtab->addUndefined( + Sym.Info.Name, static_cast(Sym.Info.Kind), Sym.Info.Flags, + this, Sym.FunctionType, Sym.GlobalType); } void ArchiveFile::parse() {