Index: wasm/InputFiles.h =================================================================== --- wasm/InputFiles.h +++ wasm/InputFiles.h @@ -121,9 +121,9 @@ uint32_t relocateGlobalIndex(uint32_t Original) const; uint32_t relocateTableIndex(uint32_t Original) const; - Symbol *createDefinedGlobal(const WasmSymbol &Sym, InputChunk *Chunk, + Symbol *createDefinedGlobal(const WasmSymbol &Sym, InputSegment *Segment, uint32_t Address); - Symbol *createDefinedFunction(const WasmSymbol &Sym, InputChunk *Chunk); + Symbol *createDefinedFunction(const WasmSymbol &Sym, InputFunction *Function); Symbol *createUndefined(const WasmSymbol &Sym, Symbol::Kind Kind, const WasmSignature *Signature = nullptr); void initializeSymbols(); Index: wasm/InputFiles.cpp =================================================================== --- wasm/InputFiles.cpp +++ wasm/InputFiles.cpp @@ -303,17 +303,17 @@ } Symbol *ObjFile::createDefinedFunction(const WasmSymbol &Sym, - InputChunk *Chunk) { + InputFunction *Function) { if (Sym.isBindingLocal()) - return make(Sym.Name, Sym.Flags, this, Chunk); - return Symtab->addDefined(true, Sym.Name, Sym.Flags, this, Chunk); + return make(Sym.Name, Sym.Flags, this, Function); + return Symtab->addDefined(true, Sym.Name, Sym.Flags, this, Function); } -Symbol *ObjFile::createDefinedGlobal(const WasmSymbol &Sym, InputChunk *Chunk, - uint32_t Address) { +Symbol *ObjFile::createDefinedGlobal(const WasmSymbol &Sym, + InputSegment *Segment, uint32_t Address) { if (Sym.isBindingLocal()) - return make(Sym.Name, Sym.Flags, this, Chunk, Address); - return Symtab->addDefined(false, Sym.Name, Sym.Flags, this, Chunk, Address); + return make(Sym.Name, Sym.Flags, this, Segment, Address); + return Symtab->addDefined(false, Sym.Name, Sym.Flags, this, Segment, Address); } void ArchiveFile::parse() { Index: wasm/SymbolTable.cpp =================================================================== --- wasm/SymbolTable.cpp +++ wasm/SymbolTable.cpp @@ -99,20 +99,21 @@ if (!ExistingFunc || !Config->CheckSignatures) return; + const WasmSignature *OldSig = ExistingFunc->getFunctionType(); + // Skip the signature check if the existing function has no signature (e.g. // if it is an undefined symbol generated by --undefined command line flag). - if (!ExistingFunc->hasFunctionType()) + if (OldSig == nullptr) return; DEBUG(dbgs() << "checkSymbolTypes: " << ExistingFunc->getName() << "\n"); assert(NewSig); - const WasmSignature &OldSig = ExistingFunc->getFunctionType(); - if (*NewSig == OldSig) + if (*NewSig == *OldSig) return; error("function signature mismatch: " + ExistingFunc->getName() + - "\n>>> defined as " + toString(OldSig) + " in " + + "\n>>> defined as " + toString(*OldSig) + " in " + toString(ExistingFunc->getFile()) + "\n>>> defined as " + toString(*NewSig) + " in " + F.getName()); } @@ -188,9 +189,11 @@ if (CheckTypes) checkSymbolTypes(*S, *F, IsFunction, Chunk); if (IsFunction) - replaceSymbol(S, Name, Flags, F, Chunk); + replaceSymbol(S, Name, Flags, F, + cast(Chunk)); else - replaceSymbol(S, Name, Flags, F, Chunk, Address); + replaceSymbol(S, Name, Flags, F, cast(Chunk), + Address); } return S; } Index: wasm/Symbols.h =================================================================== --- wasm/Symbols.h +++ wasm/Symbols.h @@ -22,6 +22,7 @@ class InputFile; class InputChunk; +class InputFunction; #define INVALID_INDEX UINT32_MAX @@ -94,8 +95,7 @@ S->kind() == UndefinedFunctionKind; } - bool hasFunctionType() const { return Chunk || FunctionType; } - const WasmSignature &getFunctionType() const; + const WasmSignature *getFunctionType() const { return FunctionType; } uint32_t getTableIndex() const; @@ -106,28 +106,26 @@ void setTableIndex(uint32_t Index); protected: - void setFunctionType(const WasmSignature *Type); + FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, + InputFunction *Function); FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, - InputChunk *C) - : Symbol(Name, K, Flags, F, C) {} + const WasmSignature* Type) + : Symbol(Name, K, Flags, F, nullptr), FunctionType(Type) {} uint32_t TableIndex = INVALID_INDEX; - // Explict function type, needed for undefined or synthetic functions only. - const WasmSignature *FunctionType = nullptr; + const WasmSignature *FunctionType; }; class DefinedFunction : public FunctionSymbol { public: - DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F = nullptr, - InputChunk *C = nullptr) - : FunctionSymbol(Name, DefinedFunctionKind, Flags, F, C) {} + DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F, + InputFunction *Function) + : FunctionSymbol(Name, DefinedFunctionKind, Flags, F, Function) {} DefinedFunction(StringRef Name, uint32_t Flags, const WasmSignature *Type) - : FunctionSymbol(Name, DefinedFunctionKind, Flags, nullptr, nullptr) { - setFunctionType(Type); - } + : FunctionSymbol(Name, DefinedFunctionKind, Flags, nullptr, Type) {} static bool classof(const Symbol *S) { return S->kind() == DefinedFunctionKind; @@ -138,9 +136,7 @@ public: UndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File = nullptr, const WasmSignature *Type = nullptr) - : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, nullptr) { - setFunctionType(Type); - } + : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type) {} static bool classof(const Symbol *S) { return S->kind() == UndefinedFunctionKind; Index: wasm/Symbols.cpp =================================================================== --- wasm/Symbols.cpp +++ wasm/Symbols.cpp @@ -69,19 +69,9 @@ Flags |= WASM_SYMBOL_VISIBILITY_DEFAULT; } -const WasmSignature &FunctionSymbol::getFunctionType() const { - if (auto *F = dyn_cast_or_null(Chunk)) - return F->Signature; - - assert(FunctionType != nullptr); - return *FunctionType; -} - -void FunctionSymbol::setFunctionType(const WasmSignature *Type) { - assert(FunctionType == nullptr); - assert(!Chunk); - FunctionType = Type; -} +FunctionSymbol::FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, + InputFile *F, InputFunction *Function) + : Symbol(Name, K, Flags, F, Function), FunctionType(&Function->Signature) {} uint32_t FunctionSymbol::getTableIndex() const { if (auto *F = dyn_cast_or_null(Chunk)) Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -169,7 +169,7 @@ Import.Module = "env"; Import.Field = Sym->getName(); Import.Kind = WASM_EXTERNAL_FUNCTION; - Import.SigIndex = lookupType(Sym->getFunctionType()); + Import.SigIndex = lookupType(*Sym->getFunctionType()); writeImport(OS, Import); } @@ -713,7 +713,7 @@ } for (const FunctionSymbol *Sym : ImportedFunctions) - registerType(Sym->getFunctionType()); + registerType(*Sym->getFunctionType()); for (const InputFunction *F : DefinedFunctions) registerType(F->Signature);