Index: lld/trunk/COFF/Chunks.h =================================================================== --- lld/trunk/COFF/Chunks.h +++ lld/trunk/COFF/Chunks.h @@ -35,7 +35,7 @@ class DefinedRegular; class ObjFile; class OutputSection; -class SymbolBody; +class Symbol; // Mask for section types (code, data, bss, disacardable, etc.) // and permissions (writable, readable or executable). @@ -117,7 +117,7 @@ public: class symbol_iterator : public llvm::iterator_adaptor_base< symbol_iterator, const coff_relocation *, - std::random_access_iterator_tag, SymbolBody *> { + std::random_access_iterator_tag, Symbol *> { friend SectionChunk; ObjFile *File; @@ -128,9 +128,7 @@ public: symbol_iterator() = default; - SymbolBody *operator*() const { - return File->getSymbolBody(I->SymbolTableIndex); - } + Symbol *operator*() const { return File->getSymbol(I->SymbolTableIndex); } }; SectionChunk(ObjFile *File, const coff_section *Header); Index: lld/trunk/COFF/Chunks.cpp =================================================================== --- lld/trunk/COFF/Chunks.cpp +++ lld/trunk/COFF/Chunks.cpp @@ -251,7 +251,7 @@ // Get the output section of the symbol for this relocation. The output // section is needed to compute SECREL and SECTION relocations used in debug // info. - SymbolBody *Body = File->getSymbolBody(Rel.SymbolTableIndex); + Symbol *Body = File->getSymbol(Rel.SymbolTableIndex); Defined *Sym = cast(Body); Chunk *C = Sym->getChunk(); OutputSection *OS = C ? C->getOutputSection() : nullptr; @@ -328,7 +328,7 @@ uint8_t Ty = getBaserelType(Rel); if (Ty == IMAGE_REL_BASED_ABSOLUTE) continue; - SymbolBody *Body = File->getSymbolBody(Rel.SymbolTableIndex); + Symbol *Body = File->getSymbol(Rel.SymbolTableIndex); if (isa(Body)) continue; Res->emplace_back(RVA + Rel.VirtualAddress, Ty); Index: lld/trunk/COFF/Config.h =================================================================== --- lld/trunk/COFF/Config.h +++ lld/trunk/COFF/Config.h @@ -27,7 +27,7 @@ class DefinedAbsolute; class DefinedRelative; class StringChunk; -class SymbolBody; +class Symbol; // Short aliases. static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64; @@ -39,7 +39,7 @@ struct Export { StringRef Name; // N in /export:N or /export:E=N StringRef ExtName; // E in /export:E=N - SymbolBody *Sym = nullptr; + Symbol *Sym = nullptr; uint16_t Ordinal = 0; bool Noname = false; bool Data = false; @@ -79,7 +79,7 @@ llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN; bool Verbose = false; WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN; - SymbolBody *Entry = nullptr; + Symbol *Entry = nullptr; bool NoEntry = false; std::string OutputFile; std::string ImportName; @@ -94,7 +94,7 @@ std::vector Argv; // Symbols in this set are considered as live by the garbage collector. - std::set GCRoot; + std::set GCRoot; std::set NoDefaultLibs; bool NoDefaultLibAll = false; @@ -105,13 +105,13 @@ std::vector Exports; std::set DelayLoads; std::map DLLOrder; - SymbolBody *DelayLoadHelper = nullptr; + Symbol *DelayLoadHelper = nullptr; bool SaveTemps = false; // Used for SafeSEH. - SymbolBody *SEHTable = nullptr; - SymbolBody *SEHCount = nullptr; + Symbol *SEHTable = nullptr; + Symbol *SEHCount = nullptr; // Used for /opt:lldlto=N unsigned LTOOptLevel = 2; Index: lld/trunk/COFF/Driver.h =================================================================== --- lld/trunk/COFF/Driver.h +++ lld/trunk/COFF/Driver.h @@ -96,7 +96,7 @@ std::set VisitedFiles; std::set VisitedLibs; - SymbolBody *addUndefined(StringRef Sym); + Symbol *addUndefined(StringRef Sym); StringRef mangle(StringRef Sym); // Windows specific -- "main" is not the only main function in Windows. Index: lld/trunk/COFF/Driver.cpp =================================================================== --- lld/trunk/COFF/Driver.cpp +++ lld/trunk/COFF/Driver.cpp @@ -353,8 +353,8 @@ } } -SymbolBody *LinkerDriver::addUndefined(StringRef Name) { - SymbolBody *B = Symtab->addUndefined(Name); +Symbol *LinkerDriver::addUndefined(StringRef Name) { + Symbol *B = Symtab->addUndefined(Name); Config->GCRoot.insert(B); return B; } @@ -1181,7 +1181,7 @@ for (auto Pair : Config->AlternateNames) { StringRef From = Pair.first; StringRef To = Pair.second; - SymbolBody *Sym = Symtab->find(From); + Symbol *Sym = Symtab->find(From); if (!Sym) continue; if (auto *U = dyn_cast(Sym)) @@ -1237,7 +1237,7 @@ Args.hasArg(OPT_export_all_symbols))) { AutoExporter Exporter; - Symtab->forEachSymbol([=](SymbolBody *S) { + Symtab->forEachSymbol([=](Symbol *S) { auto *Def = dyn_cast(S); if (!Exporter.shouldExport(Def)) return; @@ -1268,7 +1268,7 @@ StringRef Name = Pair.first; uint32_t Alignment = Pair.second; - SymbolBody *Sym = Symtab->find(Name); + Symbol *Sym = Symtab->find(Name); if (!Sym) { warn("/aligncomm symbol " + Name + " not found"); continue; Index: lld/trunk/COFF/DriverUtils.cpp =================================================================== --- lld/trunk/COFF/DriverUtils.cpp +++ lld/trunk/COFF/DriverUtils.cpp @@ -574,7 +574,7 @@ } for (Export &E : Config->Exports) { - SymbolBody *Sym = E.Sym; + Symbol *Sym = E.Sym; if (!E.ForwardTo.empty() || !Sym) { E.SymbolName = E.Name; } else { Index: lld/trunk/COFF/ICF.cpp =================================================================== --- lld/trunk/COFF/ICF.cpp +++ lld/trunk/COFF/ICF.cpp @@ -119,8 +119,8 @@ R1.VirtualAddress != R2.VirtualAddress) { return false; } - SymbolBody *B1 = A->File->getSymbolBody(R1.SymbolTableIndex); - SymbolBody *B2 = B->File->getSymbolBody(R2.SymbolTableIndex); + Symbol *B1 = A->File->getSymbol(R1.SymbolTableIndex); + Symbol *B2 = B->File->getSymbol(R2.SymbolTableIndex); if (B1 == B2) return true; if (auto *D1 = dyn_cast(B1)) @@ -143,8 +143,8 @@ bool ICF::equalsVariable(const SectionChunk *A, const SectionChunk *B) { // Compare relocations. auto Eq = [&](const coff_relocation &R1, const coff_relocation &R2) { - SymbolBody *B1 = A->File->getSymbolBody(R1.SymbolTableIndex); - SymbolBody *B2 = B->File->getSymbolBody(R2.SymbolTableIndex); + Symbol *B1 = A->File->getSymbol(R1.SymbolTableIndex); + Symbol *B2 = B->File->getSymbol(R2.SymbolTableIndex); if (B1 == B2) return true; if (auto *D1 = dyn_cast(B1)) Index: lld/trunk/COFF/InputFiles.h =================================================================== --- lld/trunk/COFF/InputFiles.h +++ lld/trunk/COFF/InputFiles.h @@ -47,7 +47,7 @@ class DefinedImportThunk; class Lazy; class SectionChunk; -class SymbolBody; +class Symbol; class Undefined; // The root class of input files. @@ -110,11 +110,11 @@ MachineTypes getMachineType() override; std::vector &getChunks() { return Chunks; } std::vector &getDebugChunks() { return DebugChunks; } - std::vector &getSymbols() { return SymbolBodies; } + std::vector &getSymbols() { return SymbolBodies; } - // Returns a SymbolBody object for the SymbolIndex'th symbol in the + // Returns a Symbol object for the SymbolIndex'th symbol in the // underlying object file. - SymbolBody *getSymbolBody(uint32_t SymbolIndex) { + Symbol *getSymbol(uint32_t SymbolIndex) { return SparseSymbolBodies[SymbolIndex]; } @@ -129,7 +129,7 @@ // The list of safe exception handlers listed in .sxdata section. // COFF-specific and x86-only. - std::set SEHandlers; + std::set SEHandlers; // Pointer to the PDB module descriptor builder. Various debug info records // will reference object files by "module index", which is here. Things like @@ -142,8 +142,8 @@ void initializeSymbols(); void initializeSEH(); - SymbolBody *createDefined(COFFSymbolRef Sym, const void *Aux, bool IsFirst); - SymbolBody *createUndefined(COFFSymbolRef Sym); + Symbol *createDefined(COFFSymbolRef Sym, const void *Aux, bool IsFirst); + Symbol *createUndefined(COFFSymbolRef Sym); std::unique_ptr COFFObj; const coff_section *SXData = nullptr; @@ -163,13 +163,13 @@ std::vector SparseChunks; // List of all symbols referenced or defined by this file. - std::vector SymbolBodies; + std::vector SymbolBodies; // This vector contains the same symbols as SymbolBodies, but they - // are indexed such that you can get a SymbolBody by symbol + // are indexed such that you can get a Symbol by symbol // index. Nonexistent indices (which are occupied by auxiliary // symbols in the real symbol table) are filled with null pointers. - std::vector SparseSymbolBodies; + std::vector SparseSymbolBodies; }; // This type represents import library members that contain DLL names @@ -210,7 +210,7 @@ public: explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {} static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; } - std::vector &getSymbols() { return SymbolBodies; } + std::vector &getSymbols() { return SymbolBodies; } MachineTypes getMachineType() override; static std::vector Instances; std::unique_ptr Obj; @@ -218,7 +218,7 @@ private: void parse() override; - std::vector SymbolBodies; + std::vector SymbolBodies; }; } // namespace coff Index: lld/trunk/COFF/InputFiles.cpp =================================================================== --- lld/trunk/COFF/InputFiles.cpp +++ lld/trunk/COFF/InputFiles.cpp @@ -51,7 +51,7 @@ /// If Source is Undefined and has no weak alias set, makes it a weak /// alias to Target. static void checkAndSetWeakAlias(SymbolTable *Symtab, InputFile *F, - SymbolBody *Source, SymbolBody *Target) { + Symbol *Source, Symbol *Target) { if (auto *U = dyn_cast(Source)) { if (U->WeakAlias && U->WeakAlias != Target) Symtab->reportDuplicate(Source, F); @@ -175,7 +175,7 @@ SymbolBodies.reserve(NumSymbols); SparseSymbolBodies.resize(NumSymbols); - SmallVector, 8> WeakAliases; + SmallVector, 8> WeakAliases; int32_t LastSectionNumber = 0; for (uint32_t I = 0; I < NumSymbols; ++I) { @@ -186,7 +186,7 @@ AuxP = check(COFFObj->getSymbol(I + 1)).getRawPtr(); bool IsFirst = (LastSectionNumber != Sym.getSectionNumber()); - SymbolBody *Body = nullptr; + Symbol *Body = nullptr; if (Sym.isUndefined()) { Body = createUndefined(Sym); } else if (Sym.isWeakExternal()) { @@ -206,26 +206,26 @@ } for (auto &KV : WeakAliases) { - SymbolBody *Sym = KV.first; + Symbol *Sym = KV.first; uint32_t Idx = KV.second; checkAndSetWeakAlias(Symtab, this, Sym, SparseSymbolBodies[Idx]); } } -SymbolBody *ObjFile::createUndefined(COFFSymbolRef Sym) { +Symbol *ObjFile::createUndefined(COFFSymbolRef Sym) { StringRef Name; COFFObj->getSymbolName(Sym, Name); return Symtab->addUndefined(Name, this, Sym.isWeakExternal()); } -SymbolBody *ObjFile::createDefined(COFFSymbolRef Sym, const void *AuxP, - bool IsFirst) { +Symbol *ObjFile::createDefined(COFFSymbolRef Sym, const void *AuxP, + bool IsFirst) { StringRef Name; if (Sym.isCommon()) { auto *C = make(Sym); Chunks.push_back(C); COFFObj->getSymbolName(Sym, Name); - SymbolBody *S = + Symbol *S = Symtab->addCommon(this, Name, Sym.getValue(), Sym.getGeneric(), C); return S; } @@ -280,7 +280,7 @@ DefinedRegular *B; if (Sym.isExternal()) { COFFObj->getSymbolName(Sym, Name); - SymbolBody *S = + Symbol *S = Symtab->addRegular(this, Name, SC->isCOMDAT(), Sym.getGeneric(), SC); B = cast(S); } else @@ -368,7 +368,7 @@ MB.getBuffer(), Saver.save(ParentName + MB.getBufferIdentifier())))); for (const lto::InputFile::Symbol &ObjSym : Obj->symbols()) { StringRef SymName = Saver.save(ObjSym.getName()); - SymbolBody *Sym; + Symbol *Sym; if (ObjSym.isUndefined()) { Sym = Symtab->addUndefined(SymName, this, false); } else if (ObjSym.isCommon()) { @@ -377,7 +377,7 @@ // Weak external. Sym = Symtab->addUndefined(SymName, this, true); std::string Fallback = ObjSym.getCOFFWeakExternalFallback(); - SymbolBody *Alias = Symtab->addUndefined(Saver.save(Fallback)); + Symbol *Alias = Symtab->addUndefined(Saver.save(Fallback)); checkAndSetWeakAlias(Symtab, this, Sym, Alias); } else { bool IsCOMDAT = ObjSym.getComdatIndex() != -1; Index: lld/trunk/COFF/LTO.cpp =================================================================== --- lld/trunk/COFF/LTO.cpp +++ lld/trunk/COFF/LTO.cpp @@ -88,17 +88,17 @@ BitcodeCompiler::~BitcodeCompiler() = default; -static void undefine(SymbolBody *S) { replaceBody(S, S->getName()); } +static void undefine(Symbol *S) { replaceBody(S, S->getName()); } void BitcodeCompiler::add(BitcodeFile &F) { lto::InputFile &Obj = *F.Obj; unsigned SymNum = 0; - std::vector SymBodies = F.getSymbols(); + std::vector SymBodies = F.getSymbols(); std::vector Resols(SymBodies.size()); // Provide a resolution to the LTO API for each symbol. for (const lto::InputFile::Symbol &ObjSym : Obj.symbols()) { - SymbolBody *Sym = SymBodies[SymNum]; + Symbol *Sym = SymBodies[SymNum]; lto::SymbolResolution &R = Resols[SymNum]; ++SymNum; Index: lld/trunk/COFF/MapFile.cpp =================================================================== --- lld/trunk/COFF/MapFile.cpp +++ lld/trunk/COFF/MapFile.cpp @@ -49,7 +49,7 @@ static std::vector getSymbols() { std::vector V; for (ObjFile *File : ObjFile::Instances) - for (SymbolBody *B : File->getSymbols()) + for (Symbol *B : File->getSymbols()) if (auto *Sym = dyn_cast(B)) if (Sym && !Sym->getCOFFSymbol().isSectionDefinition()) V.push_back(Sym); Index: lld/trunk/COFF/MarkLive.cpp =================================================================== --- lld/trunk/COFF/MarkLive.cpp +++ lld/trunk/COFF/MarkLive.cpp @@ -37,7 +37,7 @@ Worklist.push_back(C); }; - auto AddSym = [&](SymbolBody *B) { + auto AddSym = [&](Symbol *B) { if (auto *Sym = dyn_cast(B)) Enqueue(Sym->getChunk()); else if (auto *Sym = dyn_cast(B)) @@ -47,7 +47,7 @@ }; // Add GC root chunks. - for (SymbolBody *B : Config->GCRoot) + for (Symbol *B : Config->GCRoot) AddSym(B); while (!Worklist.empty()) { @@ -62,7 +62,7 @@ assert(SC->isLive() && "We mark as live when pushing onto the worklist!"); // Mark all symbols listed in the relocation table for this section. - for (SymbolBody *B : SC->symbols()) + for (Symbol *B : SC->symbols()) AddSym(B); // Mark associative sections if any. Index: lld/trunk/COFF/PDB.cpp =================================================================== --- lld/trunk/COFF/PDB.cpp +++ lld/trunk/COFF/PDB.cpp @@ -727,7 +727,7 @@ // Compute the public and global symbols. auto &GsiBuilder = Builder.getGsiBuilder(); std::vector Publics; - Symtab->forEachSymbol([&Publics](SymbolBody *S) { + Symtab->forEachSymbol([&Publics](Symbol *S) { // Only emit defined, live symbols that have a chunk. auto *Def = dyn_cast(S); if (Def && Def->isLive() && Def->getChunk()) Index: lld/trunk/COFF/SymbolTable.h =================================================================== --- lld/trunk/COFF/SymbolTable.h +++ lld/trunk/COFF/SymbolTable.h @@ -31,7 +31,7 @@ class DefinedRelative; class Lazy; class SectionChunk; -class SymbolBody; +class Symbol; // SymbolTable is a bucket of all known symbols, including defined, // undefined, or lazy symbols (the last one is symbols in archive @@ -58,14 +58,14 @@ std::vector getChunks(); // Returns a symbol for a given name. Returns a nullptr if not found. - SymbolBody *find(StringRef Name); - SymbolBody *findUnderscore(StringRef Name); + Symbol *find(StringRef Name); + Symbol *findUnderscore(StringRef Name); // Occasionally we have to resolve an undefined symbol to its // mangled symbol. This function tries to find a mangled name // for U from the symbol table, and if found, set the symbol as // a weak alias for U. - void mangleMaybe(SymbolBody *B); + void mangleMaybe(Symbol *B); StringRef findMangle(StringRef Name); // Build a set of COFF objects representing the combined contents of @@ -75,25 +75,25 @@ std::vector compileBitcodeFiles(); // Creates an Undefined symbol for a given name. - SymbolBody *addUndefined(StringRef Name); + Symbol *addUndefined(StringRef Name); - SymbolBody *addSynthetic(StringRef N, Chunk *C); - SymbolBody *addAbsolute(StringRef N, uint64_t VA); + Symbol *addSynthetic(StringRef N, Chunk *C); + Symbol *addAbsolute(StringRef N, uint64_t VA); - SymbolBody *addUndefined(StringRef Name, InputFile *F, bool IsWeakAlias); + Symbol *addUndefined(StringRef Name, InputFile *F, bool IsWeakAlias); void addLazy(ArchiveFile *F, const Archive::Symbol Sym); - SymbolBody *addAbsolute(StringRef N, COFFSymbolRef S); - SymbolBody *addRegular(InputFile *F, StringRef N, bool IsCOMDAT, - const llvm::object::coff_symbol_generic *S = nullptr, - SectionChunk *C = nullptr); - SymbolBody *addCommon(InputFile *F, StringRef N, uint64_t Size, - const llvm::object::coff_symbol_generic *S = nullptr, - CommonChunk *C = nullptr); + Symbol *addAbsolute(StringRef N, COFFSymbolRef S); + Symbol *addRegular(InputFile *F, StringRef N, bool IsCOMDAT, + const llvm::object::coff_symbol_generic *S = nullptr, + SectionChunk *C = nullptr); + Symbol *addCommon(InputFile *F, StringRef N, uint64_t Size, + const llvm::object::coff_symbol_generic *S = nullptr, + CommonChunk *C = nullptr); DefinedImportData *addImportData(StringRef N, ImportFile *F); DefinedImportThunk *addImportThunk(StringRef Name, DefinedImportData *S, uint16_t Machine); - void reportDuplicate(SymbolBody *Existing, InputFile *NewFile); + void reportDuplicate(Symbol *Existing, InputFile *NewFile); // A list of chunks which to be added to .rdata. std::vector LocalImportChunks; @@ -105,10 +105,10 @@ } private: - std::pair insert(StringRef Name); + std::pair insert(StringRef Name); StringRef findByPrefix(StringRef Prefix); - llvm::DenseMap Symtab; + llvm::DenseMap Symtab; std::unique_ptr LTO; }; Index: lld/trunk/COFF/SymbolTable.cpp =================================================================== --- lld/trunk/COFF/SymbolTable.cpp +++ lld/trunk/COFF/SymbolTable.cpp @@ -33,7 +33,7 @@ /// Checks if an existing symbol S should be kept or replaced by a new symbol. /// Returns SP_EXISTING when S should be kept, SP_NEW when the new symbol /// should be kept, and SP_CONFLICT if no valid resolution exists. -static SymbolPreference compareDefined(SymbolBody *S, bool WasInserted, +static SymbolPreference compareDefined(Symbol *S, bool WasInserted, bool NewIsCOMDAT) { // If the symbol wasn't previously known, the new symbol wins by default. if (WasInserted || !isa(S)) @@ -92,10 +92,10 @@ } void SymbolTable::reportRemainingUndefines() { - SmallPtrSet Undefs; + SmallPtrSet Undefs; for (auto &I : Symtab) { - SymbolBody *Sym = I.second; + Symbol *Sym = I.second; auto *Undef = dyn_cast(Sym); if (!Undef) continue; @@ -123,7 +123,7 @@ // If we can resolve a symbol by removing __imp_ prefix, do that. // This odd rule is for compatibility with MSVC linker. if (Name.startswith("__imp_")) { - SymbolBody *Imp = find(Name.substr(strlen("__imp_"))); + Symbol *Imp = find(Name.substr(strlen("__imp_"))); if (Imp && isa(Imp)) { auto *D = cast(Imp); replaceBody(Sym, Name, D); @@ -142,29 +142,29 @@ if (Undefs.empty()) return; - for (SymbolBody *B : Config->GCRoot) + for (Symbol *B : Config->GCRoot) if (Undefs.count(B)) errorOrWarn(": undefined symbol: " + B->getName()); for (ObjFile *File : ObjFile::Instances) - for (SymbolBody *Sym : File->getSymbols()) + for (Symbol *Sym : File->getSymbols()) if (Undefs.count(Sym)) errorOrWarn(toString(File) + ": undefined symbol: " + Sym->getName()); } -std::pair SymbolTable::insert(StringRef Name) { - SymbolBody *&Sym = Symtab[CachedHashStringRef(Name)]; +std::pair SymbolTable::insert(StringRef Name) { + Symbol *&Sym = Symtab[CachedHashStringRef(Name)]; if (Sym) return {Sym, false}; - Sym = (SymbolBody *)make(); + Sym = (Symbol *)make(); Sym->IsUsedInRegularObj = false; Sym->PendingArchiveLoad = false; return {Sym, true}; } -SymbolBody *SymbolTable::addUndefined(StringRef Name, InputFile *F, - bool IsWeakAlias) { - SymbolBody *S; +Symbol *SymbolTable::addUndefined(StringRef Name, InputFile *F, + bool IsWeakAlias) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); if (!F || !isa(F)) @@ -184,7 +184,7 @@ void SymbolTable::addLazy(ArchiveFile *F, const Archive::Symbol Sym) { StringRef Name = Sym.getName(); - SymbolBody *S; + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); if (WasInserted) { @@ -198,14 +198,14 @@ F->addMember(&Sym); } -void SymbolTable::reportDuplicate(SymbolBody *Existing, InputFile *NewFile) { +void SymbolTable::reportDuplicate(Symbol *Existing, InputFile *NewFile) { error("duplicate symbol: " + toString(*Existing) + " in " + toString(Existing->getFile()) + " and in " + (NewFile ? toString(NewFile) : "(internal)")); } -SymbolBody *SymbolTable::addAbsolute(StringRef N, COFFSymbolRef Sym) { - SymbolBody *S; +Symbol *SymbolTable::addAbsolute(StringRef N, COFFSymbolRef Sym) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(N); S->IsUsedInRegularObj = true; @@ -216,8 +216,8 @@ return S; } -SymbolBody *SymbolTable::addAbsolute(StringRef N, uint64_t VA) { - SymbolBody *S; +Symbol *SymbolTable::addAbsolute(StringRef N, uint64_t VA) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(N); S->IsUsedInRegularObj = true; @@ -228,8 +228,8 @@ return S; } -SymbolBody *SymbolTable::addSynthetic(StringRef N, Chunk *C) { - SymbolBody *S; +Symbol *SymbolTable::addSynthetic(StringRef N, Chunk *C) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(N); S->IsUsedInRegularObj = true; @@ -240,10 +240,10 @@ return S; } -SymbolBody *SymbolTable::addRegular(InputFile *F, StringRef N, bool IsCOMDAT, - const coff_symbol_generic *Sym, - SectionChunk *C) { - SymbolBody *S; +Symbol *SymbolTable::addRegular(InputFile *F, StringRef N, bool IsCOMDAT, + const coff_symbol_generic *Sym, + SectionChunk *C) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(N); if (!isa(F)) @@ -263,10 +263,9 @@ return S; } -SymbolBody *SymbolTable::addCommon(InputFile *F, StringRef N, uint64_t Size, - const coff_symbol_generic *Sym, - CommonChunk *C) { - SymbolBody *S; +Symbol *SymbolTable::addCommon(InputFile *F, StringRef N, uint64_t Size, + const coff_symbol_generic *Sym, CommonChunk *C) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(N); if (!isa(F)) @@ -280,7 +279,7 @@ } DefinedImportData *SymbolTable::addImportData(StringRef N, ImportFile *F) { - SymbolBody *S; + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(N); S->IsUsedInRegularObj = true; @@ -296,7 +295,7 @@ DefinedImportThunk *SymbolTable::addImportThunk(StringRef Name, DefinedImportData *ID, uint16_t Machine) { - SymbolBody *S; + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); S->IsUsedInRegularObj = true; @@ -318,14 +317,14 @@ return Res; } -SymbolBody *SymbolTable::find(StringRef Name) { +Symbol *SymbolTable::find(StringRef Name) { auto It = Symtab.find(CachedHashStringRef(Name)); if (It == Symtab.end()) return nullptr; return It->second; } -SymbolBody *SymbolTable::findUnderscore(StringRef Name) { +Symbol *SymbolTable::findUnderscore(StringRef Name) { if (Config->Machine == I386) return find(("_" + Name).str()); return find(Name); @@ -341,7 +340,7 @@ } StringRef SymbolTable::findMangle(StringRef Name) { - if (SymbolBody *Sym = find(Name)) + if (Symbol *Sym = find(Name)) if (!isa(Sym)) return Name; if (Config->Machine != I386) @@ -364,7 +363,7 @@ return findByPrefix(("?" + Name.substr(1) + "@@Y").str()); } -void SymbolTable::mangleMaybe(SymbolBody *B) { +void SymbolTable::mangleMaybe(Symbol *B) { auto *U = dyn_cast(B); if (!U || U->WeakAlias) return; @@ -375,7 +374,7 @@ } } -SymbolBody *SymbolTable::addUndefined(StringRef Name) { +Symbol *SymbolTable::addUndefined(StringRef Name) { return addUndefined(Name, nullptr, false); } Index: lld/trunk/COFF/Symbols.h =================================================================== --- lld/trunk/COFF/Symbols.h +++ lld/trunk/COFF/Symbols.h @@ -35,7 +35,7 @@ class SymbolTable; // The base class for real symbol classes. -class SymbolBody { +class Symbol { public: enum Kind { // The order of these is significant. We start with the regular defined @@ -75,7 +75,7 @@ protected: friend SymbolTable; - explicit SymbolBody(Kind K, StringRef N = "") + explicit Symbol(Kind K, StringRef N = "") : SymbolKind(K), IsExternal(true), IsCOMDAT(false), WrittenToSymtab(false), Name(N) {} @@ -104,13 +104,11 @@ // The base class for any defined symbols, including absolute symbols, // etc. -class Defined : public SymbolBody { +class Defined : public Symbol { public: - Defined(Kind K, StringRef N) : SymbolBody(K, N) {} + Defined(Kind K, StringRef N) : Symbol(K, N) {} - static bool classof(const SymbolBody *S) { - return S->kind() <= LastDefinedKind; - } + static bool classof(const Symbol *S) { return S->kind() <= LastDefinedKind; } // Returns the RVA (relative virtual address) of this symbol. The // writer sets and uses RVAs. @@ -126,12 +124,13 @@ // loaded through that. For bitcode files, Sym is nullptr and the name is stored // as a StringRef. class DefinedCOFF : public Defined { - friend SymbolBody; + friend Symbol; + public: DefinedCOFF(Kind K, InputFile *F, StringRef N, const coff_symbol_generic *S) : Defined(K, N), File(F), Sym(S) {} - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() <= LastDefinedCOFFKind; } @@ -157,7 +156,7 @@ this->IsCOMDAT = IsCOMDAT; } - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedRegularKind; } @@ -179,7 +178,7 @@ this->IsExternal = true; } - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedCommonKind; } @@ -204,7 +203,7 @@ DefinedAbsolute(StringRef N, uint64_t V) : Defined(DefinedAbsoluteKind, N), VA(V) {} - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedAbsoluteKind; } @@ -228,7 +227,7 @@ explicit DefinedSynthetic(StringRef Name, Chunk *C) : Defined(DefinedSyntheticKind, Name), C(C) {} - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedSyntheticKind; } @@ -246,12 +245,12 @@ // object file from an archive to replace itself with a defined // symbol. If the resolver finds both Undefined and Lazy for // the same name, it will ask the Lazy to load a file. -class Lazy : public SymbolBody { +class Lazy : public Symbol { public: Lazy(ArchiveFile *F, const Archive::Symbol S) - : SymbolBody(LazyKind, S.getName()), File(F), Sym(S) {} + : Symbol(LazyKind, S.getName()), File(F), Sym(S) {} - static bool classof(const SymbolBody *S) { return S->kind() == LazyKind; } + static bool classof(const Symbol *S) { return S->kind() == LazyKind; } ArchiveFile *File; @@ -263,19 +262,17 @@ }; // Undefined symbols. -class Undefined : public SymbolBody { +class Undefined : public Symbol { public: - explicit Undefined(StringRef N) : SymbolBody(UndefinedKind, N) {} + explicit Undefined(StringRef N) : Symbol(UndefinedKind, N) {} - static bool classof(const SymbolBody *S) { - return S->kind() == UndefinedKind; - } + static bool classof(const Symbol *S) { return S->kind() == UndefinedKind; } // An undefined symbol can have a fallback symbol which gives an // undefined symbol a second chance if it would remain undefined. // If it remains undefined, it'll be replaced with whatever the // Alias pointer points to. - SymbolBody *WeakAlias = nullptr; + Symbol *WeakAlias = nullptr; // If this symbol is external weak, try to resolve it to a defined // symbol by searching the chain of fallback symbols. Returns the symbol if @@ -295,7 +292,7 @@ : Defined(DefinedImportDataKind, N), File(F) { } - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedImportDataKind; } @@ -319,7 +316,7 @@ public: DefinedImportThunk(StringRef Name, DefinedImportData *S, uint16_t Machine); - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedImportThunkKind; } @@ -342,7 +339,7 @@ DefinedLocalImport(StringRef N, Defined *S) : Defined(DefinedLocalImportKind, N), Data(make(S)) {} - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedLocalImportKind; } @@ -399,7 +396,7 @@ llvm_unreachable("unknown symbol kind"); } -// A buffer class that is large enough to hold any SymbolBody-derived +// A buffer class that is large enough to hold any Symbol-derived // object. We allocate memory using this class and instantiate a symbol // using the placement new. union SymbolUnion { @@ -415,17 +412,17 @@ }; template -void replaceBody(SymbolBody *S, ArgT &&... Arg) { +void replaceBody(Symbol *S, ArgT &&... Arg) { static_assert(sizeof(T) <= sizeof(SymbolUnion), "Symbol too small"); static_assert(alignof(T) <= alignof(SymbolUnion), "SymbolUnion not aligned enough"); - assert(static_cast(static_cast(nullptr)) == nullptr && - "Not a SymbolBody"); + assert(static_cast(static_cast(nullptr)) == nullptr && + "Not a Symbol"); new (S) T(std::forward(Arg)...); } } // namespace coff -std::string toString(coff::SymbolBody &B); +std::string toString(coff::Symbol &B); } // namespace lld #endif Index: lld/trunk/COFF/Symbols.cpp =================================================================== --- lld/trunk/COFF/Symbols.cpp +++ lld/trunk/COFF/Symbols.cpp @@ -20,7 +20,7 @@ using namespace llvm::object; // Returns a symbol name for an error message. -std::string lld::toString(coff::SymbolBody &B) { +std::string lld::toString(coff::Symbol &B) { if (Optional S = coff::demangle(B.getName())) return ("\"" + *S + "\" (" + B.getName() + ")").str(); return B.getName(); @@ -29,7 +29,7 @@ namespace lld { namespace coff { -StringRef SymbolBody::getName() { +StringRef Symbol::getName() { // COFF symbol names are read lazily for a performance reason. // Non-external symbol names are never used by the linker except for logging // or debugging. Their internal references are resolved not by name but by @@ -44,7 +44,7 @@ return Name; } -InputFile *SymbolBody::getFile() { +InputFile *Symbol::getFile() { if (auto *Sym = dyn_cast(this)) return Sym->File; if (auto *Sym = dyn_cast(this)) @@ -52,7 +52,7 @@ return nullptr; } -bool SymbolBody::isLive() const { +bool Symbol::isLive() const { if (auto *R = dyn_cast(this)) return R->getChunk()->isLive(); if (auto *Imp = dyn_cast(this)) @@ -91,7 +91,7 @@ Defined *Undefined::getWeakAlias() { // A weak alias may be a weak alias to another symbol, so check recursively. - for (SymbolBody *A = WeakAlias; A; A = cast(A)->WeakAlias) + for (Symbol *A = WeakAlias; A; A = cast(A)->WeakAlias) if (auto *D = dyn_cast(A)) return D; return nullptr; Index: lld/trunk/COFF/Writer.cpp =================================================================== --- lld/trunk/COFF/Writer.cpp +++ lld/trunk/COFF/Writer.cpp @@ -396,7 +396,7 @@ for (ObjFile *File : ObjFile::Instances) { if (!File->SEHCompat) return; - for (SymbolBody *B : File->SEHandlers) { + for (Symbol *B : File->SEHandlers) { // Make sure the handler is still live. Assume all handlers are regular // symbols. auto *D = dyn_cast(B); @@ -532,7 +532,7 @@ Sym.NumberOfAuxSymbols = 0; switch (Def->kind()) { - case SymbolBody::DefinedAbsoluteKind: + case Symbol::DefinedAbsoluteKind: Sym.Value = Def->getRVA(); Sym.SectionNumber = IMAGE_SYM_ABSOLUTE; break; @@ -566,7 +566,7 @@ } for (ObjFile *File : ObjFile::Instances) { - for (SymbolBody *B : File->getSymbols()) { + for (Symbol *B : File->getSymbols()) { auto *D = dyn_cast(B); if (!D || D->WrittenToSymtab) continue; @@ -731,7 +731,7 @@ Dir[BASE_RELOCATION_TABLE].RelativeVirtualAddress = Sec->getRVA(); Dir[BASE_RELOCATION_TABLE].Size = Sec->getVirtualSize(); } - if (SymbolBody *Sym = Symtab->findUnderscore("_tls_used")) { + if (Symbol *Sym = Symtab->findUnderscore("_tls_used")) { if (Defined *B = dyn_cast(Sym)) { Dir[TLS_TABLE].RelativeVirtualAddress = B->getRVA(); Dir[TLS_TABLE].Size = Config->is64() @@ -743,7 +743,7 @@ Dir[DEBUG_DIRECTORY].RelativeVirtualAddress = DebugDirectory->getRVA(); Dir[DEBUG_DIRECTORY].Size = DebugDirectory->getSize(); } - if (SymbolBody *Sym = Symtab->findUnderscore("_load_config_used")) { + if (Symbol *Sym = Symtab->findUnderscore("_load_config_used")) { if (auto *B = dyn_cast(Sym)) { SectionChunk *SC = B->getChunk(); assert(B->getRVA() >= SC->getRVA()); @@ -804,8 +804,8 @@ // Replace the absolute table symbol with a synthetic symbol pointing to the // SEHTable chunk so that we can emit base relocations for it and resolve // section relative relocations. - SymbolBody *T = Symtab->find("___safe_se_handler_table"); - SymbolBody *C = Symtab->find("___safe_se_handler_count"); + Symbol *T = Symtab->find("___safe_se_handler_table"); + Symbol *C = Symtab->find("___safe_se_handler_count"); replaceBody(T, T->getName(), SEHTable); cast(C)->setVA(SEHTable->getSize() / 4); } Index: lld/trunk/ELF/Arch/AArch64.cpp =================================================================== --- lld/trunk/ELF/Arch/AArch64.cpp +++ lld/trunk/ELF/Arch/AArch64.cpp @@ -32,10 +32,10 @@ class AArch64 final : public TargetInfo { public: AArch64(); - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; bool isPicRel(RelType Type) const override; - void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override; + void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; @@ -68,7 +68,7 @@ TcbSize = 16; } -RelExpr AArch64::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr AArch64::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { switch (Type) { case R_AARCH64_TLSDESC_ADR_PAGE21: @@ -139,7 +139,7 @@ return Type == R_AARCH64_ABS32 || Type == R_AARCH64_ABS64; } -void AArch64::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { +void AArch64::writeGotPlt(uint8_t *Buf, const Symbol &) const { write64le(Buf, InX::Plt->getVA()); } Index: lld/trunk/ELF/Arch/AMDGPU.cpp =================================================================== --- lld/trunk/ELF/Arch/AMDGPU.cpp +++ lld/trunk/ELF/Arch/AMDGPU.cpp @@ -27,7 +27,7 @@ AMDGPU(); uint32_t calcEFlags() const override; void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override; - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; }; } // namespace @@ -77,7 +77,7 @@ } } -RelExpr AMDGPU::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr AMDGPU::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { switch (Type) { case R_AMDGPU_ABS32: Index: lld/trunk/ELF/Arch/ARM.cpp =================================================================== --- lld/trunk/ELF/Arch/ARM.cpp +++ lld/trunk/ELF/Arch/ARM.cpp @@ -27,20 +27,20 @@ public: ARM(); uint32_t calcEFlags() const override; - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; bool isPicRel(RelType Type) const override; RelType getDynRel(RelType Type) const override; int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override; - void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override; - void writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const override; + void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; + void writeIgotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; void addPltSymbols(InputSectionBase *IS, uint64_t Off) const override; void addPltHeaderSymbols(InputSectionBase *ISD) const override; bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File, - uint64_t BranchAddr, const SymbolBody &S) const override; + uint64_t BranchAddr, const Symbol &S) const override; bool inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const override; void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override; }; @@ -103,7 +103,7 @@ return EF_ARM_EABI_VER5; } -RelExpr ARM::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr ARM::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { switch (Type) { case R_ARM_THM_JUMP11: @@ -175,11 +175,11 @@ return R_ARM_ABS32; } -void ARM::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { +void ARM::writeGotPlt(uint8_t *Buf, const Symbol &) const { write32le(Buf, InX::Plt->getVA()); } -void ARM::writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const { +void ARM::writeIgotPlt(uint8_t *Buf, const Symbol &S) const { // An ARM entry is the address of the ifunc resolver function. write32le(Buf, S.getVA()); } @@ -228,7 +228,7 @@ } bool ARM::needsThunk(RelExpr Expr, RelType Type, const InputFile *File, - uint64_t BranchAddr, const SymbolBody &S) const { + uint64_t BranchAddr, const Symbol &S) const { // If S is an undefined weak symbol in an executable we don't need a Thunk. // In a DSO calls to undefined symbols, including weak ones get PLT entries // which may need a thunk. Index: lld/trunk/ELF/Arch/AVR.cpp =================================================================== --- lld/trunk/ELF/Arch/AVR.cpp +++ lld/trunk/ELF/Arch/AVR.cpp @@ -43,13 +43,13 @@ namespace { class AVR final : public TargetInfo { public: - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override; }; } // namespace -RelExpr AVR::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr AVR::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { return R_ABS; } Index: lld/trunk/ELF/Arch/Mips.cpp =================================================================== --- lld/trunk/ELF/Arch/Mips.cpp +++ lld/trunk/ELF/Arch/Mips.cpp @@ -29,17 +29,17 @@ public: MIPS(); uint32_t calcEFlags() const override; - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override; bool isPicRel(RelType Type) const override; RelType getDynRel(RelType Type) const override; - void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override; + void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File, - uint64_t BranchAddr, const SymbolBody &S) const override; + uint64_t BranchAddr, const Symbol &S) const override; void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override; bool usesOnlyLowPageBits(RelType Type) const override; }; @@ -75,7 +75,7 @@ } template -RelExpr MIPS::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr MIPS::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { // See comment in the calculateMipsRelChain. if (ELFT::Is64Bits || Config->MipsN32Abi) @@ -192,7 +192,7 @@ } template -void MIPS::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { +void MIPS::writeGotPlt(uint8_t *Buf, const Symbol &) const { write32(Buf, InX::Plt->getVA()); } @@ -331,7 +331,7 @@ template bool MIPS::needsThunk(RelExpr Expr, RelType Type, const InputFile *File, - uint64_t BranchAddr, const SymbolBody &S) const { + uint64_t BranchAddr, const Symbol &S) const { // Any MIPS PIC code function is invoked with its address in register $t9. // So if we have a branch instruction from non-PIC code to the PIC one // we cannot make the jump directly and need to create a small stubs Index: lld/trunk/ELF/Arch/PPC.cpp =================================================================== --- lld/trunk/ELF/Arch/PPC.cpp +++ lld/trunk/ELF/Arch/PPC.cpp @@ -23,12 +23,12 @@ public: PPC() { GotBaseSymOff = 0x8000; } void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override; - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; }; } // namespace -RelExpr PPC::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr PPC::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { switch (Type) { case R_PPC_REL24: Index: lld/trunk/ELF/Arch/PPC64.cpp =================================================================== --- lld/trunk/ELF/Arch/PPC64.cpp +++ lld/trunk/ELF/Arch/PPC64.cpp @@ -39,7 +39,7 @@ class PPC64 final : public TargetInfo { public: PPC64(); - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; @@ -82,7 +82,7 @@ DefaultImageBase = 0x10000000; } -RelExpr PPC64::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr PPC64::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { switch (Type) { case R_PPC64_TOC16: Index: lld/trunk/ELF/Arch/SPARCV9.cpp =================================================================== --- lld/trunk/ELF/Arch/SPARCV9.cpp +++ lld/trunk/ELF/Arch/SPARCV9.cpp @@ -24,7 +24,7 @@ class SPARCV9 final : public TargetInfo { public: SPARCV9(); - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; @@ -46,7 +46,7 @@ DefaultImageBase = 0x100000; } -RelExpr SPARCV9::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr SPARCV9::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { switch (Type) { case R_SPARC_32: Index: lld/trunk/ELF/Arch/X86.cpp =================================================================== --- lld/trunk/ELF/Arch/X86.cpp +++ lld/trunk/ELF/Arch/X86.cpp @@ -24,13 +24,13 @@ class X86 final : public TargetInfo { public: X86(); - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override; void writeGotPltHeader(uint8_t *Buf) const override; RelType getDynRel(RelType Type) const override; - void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override; - void writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const override; + void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; + void writeIgotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; @@ -65,7 +65,7 @@ static bool hasBaseReg(uint8_t ModRM) { return (ModRM & 0xc7) != 0x5; } -RelExpr X86::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr X86::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { switch (Type) { case R_386_8: @@ -156,13 +156,13 @@ write32le(Buf, InX::Dynamic->getVA()); } -void X86::writeGotPlt(uint8_t *Buf, const SymbolBody &S) const { +void X86::writeGotPlt(uint8_t *Buf, const Symbol &S) const { // Entries in .got.plt initially points back to the corresponding // PLT entries with a fixed offset to skip the first instruction. write32le(Buf, S.getPltVA() + 6); } -void X86::writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const { +void X86::writeIgotPlt(uint8_t *Buf, const Symbol &S) const { // An x86 entry is the address of the ifunc resolver function. write32le(Buf, S.getVA()); } Index: lld/trunk/ELF/Arch/X86_64.cpp =================================================================== --- lld/trunk/ELF/Arch/X86_64.cpp +++ lld/trunk/ELF/Arch/X86_64.cpp @@ -26,11 +26,11 @@ template class X86_64 final : public TargetInfo { public: X86_64(); - RelExpr getRelExpr(RelType Type, const SymbolBody &S, + RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const override; bool isPicRel(RelType Type) const override; void writeGotPltHeader(uint8_t *Buf) const override; - void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override; + void writeGotPlt(uint8_t *Buf, const Symbol &S) const override; void writePltHeader(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; @@ -73,7 +73,7 @@ } template -RelExpr X86_64::getRelExpr(RelType Type, const SymbolBody &S, +RelExpr X86_64::getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const { switch (Type) { case R_X86_64_8: @@ -122,7 +122,7 @@ } template -void X86_64::writeGotPlt(uint8_t *Buf, const SymbolBody &S) const { +void X86_64::writeGotPlt(uint8_t *Buf, const Symbol &S) const { // See comments in X86::writeGotPlt. write32le(Buf, S.getPltVA() + 6); } Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -1001,7 +1001,7 @@ for (InputFile *File : Files) if (Optional Archive = getArchiveName(File)) if (All || Libs.count(path::filename(*Archive))) - for (SymbolBody *Sym : File->getSymbols()) + for (Symbol *Sym : File->getSymbols()) if (!Sym->isLocal()) Sym->VersionId = VER_NDX_LOCAL; } Index: lld/trunk/ELF/GdbIndex.cpp =================================================================== --- lld/trunk/ELF/GdbIndex.cpp +++ lld/trunk/ELF/GdbIndex.cpp @@ -68,7 +68,7 @@ uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL); const typename ELFT::Sym &Sym = File->getELFSyms()[SymIndex]; uint32_t SecIndex = File->getSectionIndex(Sym); - SymbolBody &B = File->getRelocTargetSym(Rel); + Symbol &B = File->getRelocTargetSym(Rel); auto &DR = cast(B); uint64_t Val = DR.Value + getAddend(Rel); Index: lld/trunk/ELF/ICF.cpp =================================================================== --- lld/trunk/ELF/ICF.cpp +++ lld/trunk/ELF/ICF.cpp @@ -220,8 +220,8 @@ uint64_t AddA = getAddend(RA[I]); uint64_t AddB = getAddend(RB[I]); - SymbolBody &SA = SecA->template getFile()->getRelocTargetSym(RA[I]); - SymbolBody &SB = SecB->template getFile()->getRelocTargetSym(RB[I]); + Symbol &SA = SecA->template getFile()->getRelocTargetSym(RA[I]); + Symbol &SB = SecB->template getFile()->getRelocTargetSym(RB[I]); if (&SA == &SB) { if (AddA == AddB) continue; @@ -295,8 +295,8 @@ for (size_t I = 0; I < RA.size(); ++I) { // The two sections must be identical. - SymbolBody &SA = SecA->template getFile()->getRelocTargetSym(RA[I]); - SymbolBody &SB = SecB->template getFile()->getRelocTargetSym(RB[I]); + Symbol &SA = SecA->template getFile()->getRelocTargetSym(RA[I]); + Symbol &SB = SecB->template getFile()->getRelocTargetSym(RB[I]); if (&SA == &SB) continue; Index: lld/trunk/ELF/InputFiles.h =================================================================== --- lld/trunk/ELF/InputFiles.h +++ lld/trunk/ELF/InputFiles.h @@ -50,7 +50,7 @@ using llvm::object::Archive; class Lazy; -class SymbolBody; +class Symbol; // If -reproduce option is given, all input files are written // to this tar archive. @@ -85,7 +85,7 @@ // Returns object file symbols. It is a runtime error to call this // function on files of other types. - ArrayRef getSymbols() { + ArrayRef getSymbols() { assert(FileKind == ObjKind || FileKind == BitcodeKind || FileKind == ArchiveKind); return Symbols; @@ -108,7 +108,7 @@ protected: InputFile(Kind K, MemoryBufferRef M); std::vector Sections; - std::vector Symbols; + std::vector Symbols; private: const Kind FileKind; @@ -162,23 +162,22 @@ public: static bool classof(const InputFile *F) { return F->kind() == Base::ObjKind; } - ArrayRef getLocalSymbols(); + ArrayRef getLocalSymbols(); ObjFile(MemoryBufferRef M, StringRef ArchiveName); void parse(llvm::DenseSet &ComdatGroups); InputSectionBase *getSection(uint32_t Index) const; - SymbolBody &getSymbolBody(uint32_t SymbolIndex) const { + Symbol &getSymbol(uint32_t SymbolIndex) const { if (SymbolIndex >= this->Symbols.size()) fatal(toString(this) + ": invalid symbol index"); return *this->Symbols[SymbolIndex]; } - template - SymbolBody &getRelocTargetSym(const RelT &Rel) const { + template Symbol &getRelocTargetSym(const RelT &Rel) const { uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL); - return getSymbolBody(SymIndex); + return getSymbol(SymIndex); } // Returns source line information for a given offset. @@ -207,7 +206,7 @@ StringRef getSectionName(const Elf_Shdr &Sec); bool shouldMerge(const Elf_Shdr &Sec); - SymbolBody *createSymbolBody(const Elf_Sym *Sym); + Symbol *createSymbol(const Elf_Sym *Sym); // .shstrtab contents. StringRef SectionStringTable; Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -227,7 +227,7 @@ this->ArchiveName = ArchiveName; } -template ArrayRef ObjFile::getLocalSymbols() { +template ArrayRef ObjFile::getLocalSymbols() { if (this->Symbols.empty()) return {}; return makeArrayRef(this->Symbols).slice(1, this->FirstNonLocal - 1); @@ -569,7 +569,7 @@ template void ObjFile::initializeSymbols() { this->Symbols.reserve(this->ELFSyms.size()); for (const Elf_Sym &Sym : this->ELFSyms) - this->Symbols.push_back(createSymbolBody(&Sym)); + this->Symbols.push_back(createSymbol(&Sym)); } template @@ -584,8 +584,7 @@ return nullptr; } -template -SymbolBody *ObjFile::createSymbolBody(const Elf_Sym *Sym) { +template Symbol *ObjFile::createSymbol(const Elf_Sym *Sym) { int Binding = Sym->getBinding(); InputSectionBase *Sec = getSection(this->getSectionIndex(*Sym)); @@ -905,9 +904,9 @@ } template -static SymbolBody *createBitcodeSymbol(const std::vector &KeptComdats, - const lto::InputFile::Symbol &ObjSym, - BitcodeFile *F) { +static Symbol *createBitcodeSymbol(const std::vector &KeptComdats, + const lto::InputFile::Symbol &ObjSym, + BitcodeFile *F) { StringRef NameRef = Saver.save(ObjSym.getName()); uint32_t Binding = ObjSym.isWeak() ? STB_WEAK : STB_GLOBAL; Index: lld/trunk/ELF/InputSection.h =================================================================== --- lld/trunk/ELF/InputSection.h +++ lld/trunk/ELF/InputSection.h @@ -25,7 +25,7 @@ namespace elf { class DefinedCommon; -class SymbolBody; +class Symbol; struct SectionPiece; class DefinedRegular; @@ -177,7 +177,8 @@ // Returns a source location string. Used to construct an error message. template std::string getLocation(uint64_t Offset); - template std::string getSrcMsg(const SymbolBody &Sym, uint64_t Offset); + template + std::string getSrcMsg(const Symbol &Sym, uint64_t Offset); std::string getObjMsg(uint64_t Offset); // Each section knows how to relocate itself. These functions apply Index: lld/trunk/ELF/InputSection.cpp =================================================================== --- lld/trunk/ELF/InputSection.cpp +++ lld/trunk/ELF/InputSection.cpp @@ -60,7 +60,7 @@ // Build a map from sections to their priorities. for (InputFile *File : ObjectFiles) { - for (SymbolBody *Body : File->getSymbols()) { + for (Symbol *Body : File->getSymbols()) { auto *D = dyn_cast(Body); if (!D || !D->Section) continue; @@ -250,7 +250,7 @@ SrcFile = toString(File); // Find a function symbol that encloses a given location. - for (SymbolBody *B : File->getSymbols()) + for (Symbol *B : File->getSymbols()) if (auto *D = dyn_cast(B)) if (D->Section == this && D->Type == STT_FUNC) if (D->Value <= Offset && Offset < D->Value + D->Size) @@ -276,8 +276,7 @@ // // Returns an empty string if there's no way to get line info. template -std::string InputSectionBase::getSrcMsg(const SymbolBody &Sym, - uint64_t Offset) { +std::string InputSectionBase::getSrcMsg(const Symbol &Sym, uint64_t Offset) { // Synthetic sections don't have input files. ObjFile *File = getFile(); if (!File) @@ -317,7 +316,7 @@ Archive = (" in archive " + File->ArchiveName).str(); // Find a symbol that encloses a given location. - for (SymbolBody *B : File->getSymbols()) + for (Symbol *B : File->getSymbols()) if (auto *D = dyn_cast(B)) if (D->Section == this && D->Value <= Off && Off < D->Value + D->Size) return Filename + ":(" + toString(*D) + ")" + Archive; @@ -381,7 +380,7 @@ for (const RelTy &Rel : Rels) { RelType Type = Rel.getType(Config->IsMips64EL); - SymbolBody &Body = this->getFile()->getRelocTargetSym(Rel); + Symbol &Body = this->getFile()->getRelocTargetSym(Rel); auto *P = reinterpret_cast(Buf); Buf += sizeof(RelTy); @@ -489,7 +488,7 @@ // The procedure call standard only defines a Read Write Position Independent // RWPI variant so in practice we should expect the static base to be the base // of the RW segment. -static uint64_t getARMStaticBase(const SymbolBody &Body) { +static uint64_t getARMStaticBase(const Symbol &Body) { OutputSection *OS = Body.getOutputSection(); if (!OS || !OS->PtLoad || !OS->PtLoad->FirstSec) fatal("SBREL relocation to " + Body.getName() + " without static base"); @@ -497,7 +496,7 @@ } static uint64_t getRelocTargetVA(RelType Type, int64_t A, uint64_t P, - const SymbolBody &Body, RelExpr Expr) { + const Symbol &Body, RelExpr Expr) { switch (Expr) { case R_INVALID: return 0; @@ -672,7 +671,7 @@ if (!RelTy::IsRela) Addend += Target->getImplicitAddend(BufLoc, Type); - SymbolBody &Sym = this->getFile()->getRelocTargetSym(Rel); + Symbol &Sym = this->getFile()->getRelocTargetSym(Rel); RelExpr Expr = Target->getRelExpr(Type, Sym, BufLoc); if (Expr == R_NONE) continue; @@ -1013,13 +1012,13 @@ template std::string InputSectionBase::getLocation(uint64_t); template std::string InputSectionBase::getLocation(uint64_t); -template std::string InputSectionBase::getSrcMsg(const SymbolBody &, +template std::string InputSectionBase::getSrcMsg(const Symbol &, uint64_t); -template std::string InputSectionBase::getSrcMsg(const SymbolBody &, +template std::string InputSectionBase::getSrcMsg(const Symbol &, uint64_t); -template std::string InputSectionBase::getSrcMsg(const SymbolBody &, +template std::string InputSectionBase::getSrcMsg(const Symbol &, uint64_t); -template std::string InputSectionBase::getSrcMsg(const SymbolBody &, +template std::string InputSectionBase::getSrcMsg(const Symbol &, uint64_t); template void InputSection::writeTo(uint8_t *); Index: lld/trunk/ELF/LTO.cpp =================================================================== --- lld/trunk/ELF/LTO.cpp +++ lld/trunk/ELF/LTO.cpp @@ -108,7 +108,7 @@ } BitcodeCompiler::BitcodeCompiler() : LTOObj(createLTO()) { - for (SymbolBody *Sym : Symtab->getSymbols()) { + for (Symbol *Sym : Symtab->getSymbols()) { StringRef Name = Sym->getName(); for (StringRef Prefix : {"__start_", "__stop_"}) if (Name.startswith(Prefix)) @@ -118,7 +118,7 @@ BitcodeCompiler::~BitcodeCompiler() = default; -static void undefine(SymbolBody *S) { +static void undefine(Symbol *S) { replaceBody(S, nullptr, S->getName(), /*IsLocal=*/false, STV_DEFAULT, S->Type); } @@ -126,7 +126,7 @@ void BitcodeCompiler::add(BitcodeFile &F) { lto::InputFile &Obj = *F.Obj; unsigned SymNum = 0; - std::vector Syms = F.getSymbols(); + std::vector Syms = F.getSymbols(); std::vector Resols(Syms.size()); DenseSet ScriptSymbols; @@ -136,7 +136,7 @@ // Provide a resolution to the LTO API for each symbol. for (const lto::InputFile::Symbol &ObjSym : Obj.symbols()) { - SymbolBody *Sym = Syms[SymNum]; + Symbol *Sym = Syms[SymNum]; lto::SymbolResolution &R = Resols[SymNum]; ++SymNum; Index: lld/trunk/ELF/LinkerScript.h =================================================================== --- lld/trunk/ELF/LinkerScript.h +++ lld/trunk/ELF/LinkerScript.h @@ -30,7 +30,7 @@ namespace elf { class DefinedRegular; -class SymbolBody; +class Symbol; class InputSectionBase; class InputSection; class OutputSection; Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -122,12 +122,12 @@ // If a symbol was in PROVIDE(), we need to define it only when // it is a referenced undefined symbol. - SymbolBody *B = Symtab->find(Cmd->Name); + Symbol *B = Symtab->find(Cmd->Name); if (Cmd->Provide && (!B || B->isDefined())) return; // Define a symbol. - SymbolBody *Sym; + Symbol *Sym; uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT; std::tie(Sym, std::ignore) = Symtab->insert(Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false, Index: lld/trunk/ELF/MapFile.cpp =================================================================== --- lld/trunk/ELF/MapFile.cpp +++ lld/trunk/ELF/MapFile.cpp @@ -50,7 +50,7 @@ static std::vector getSymbols() { std::vector V; for (InputFile *File : ObjectFiles) - for (SymbolBody *B : File->getSymbols()) + for (Symbol *B : File->getSymbols()) if (auto *DR = dyn_cast(B)) if (DR->getFile() == File && !DR->isSection() && DR->Section && DR->Section->Live) Index: lld/trunk/ELF/MarkLive.cpp =================================================================== --- lld/trunk/ELF/MarkLive.cpp +++ lld/trunk/ELF/MarkLive.cpp @@ -62,7 +62,7 @@ template static void resolveReloc(InputSectionBase &Sec, RelT &Rel, std::function Fn) { - SymbolBody &B = Sec.getFile()->getRelocTargetSym(Rel); + Symbol &B = Sec.getFile()->getRelocTargetSym(Rel); if (auto *D = dyn_cast(&B)) { if (!D->Section) @@ -211,7 +211,7 @@ Q.push_back(S); }; - auto MarkSymbol = [&](SymbolBody *Sym) { + auto MarkSymbol = [&](Symbol *Sym) { if (auto *D = dyn_cast_or_null(Sym)) if (auto *IS = cast_or_null(D->Section)) Enqueue(IS, D->Value); @@ -228,7 +228,7 @@ // Preserve externally-visible symbols if the symbols defined by this // file can interrupt other ELF file's symbols at runtime. - for (SymbolBody *S : Symtab->getSymbols()) + for (Symbol *S : Symtab->getSymbols()) if (S->includeInDynsym()) MarkSymbol(S); Index: lld/trunk/ELF/OutputSections.h =================================================================== --- lld/trunk/ELF/OutputSections.h +++ lld/trunk/ELF/OutputSections.h @@ -23,7 +23,7 @@ namespace elf { struct PhdrEntry; -class SymbolBody; +class Symbol; struct EhSectionPiece; class EhInputSection; class InputSection; Index: lld/trunk/ELF/OutputSections.cpp =================================================================== --- lld/trunk/ELF/OutputSections.cpp +++ lld/trunk/ELF/OutputSections.cpp @@ -425,7 +425,7 @@ // sh_info then contain index of an entry in symbol table section which // provides signature of the section group. ObjFile *Obj = Sections[0]->getFile(); - ArrayRef Symbols = Obj->getSymbols(); + ArrayRef Symbols = Obj->getSymbols(); OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info]); } Index: lld/trunk/ELF/Relocations.h =================================================================== --- lld/trunk/ELF/Relocations.h +++ lld/trunk/ELF/Relocations.h @@ -17,7 +17,7 @@ namespace lld { namespace elf { -class SymbolBody; +class Symbol; class InputSection; class InputSectionBase; class OutputSection; @@ -118,7 +118,7 @@ RelType Type; uint64_t Offset; int64_t Addend; - SymbolBody *Sym; + Symbol *Sym; }; template void scanRelocations(InputSectionBase &); @@ -152,8 +152,7 @@ ArrayRef OutputSections, std::function Fn); - std::pair getThunk(SymbolBody &Body, RelType Type, - uint64_t Src); + std::pair getThunk(Symbol &Body, RelType Type, uint64_t Src); ThunkSection *addThunkSection(OutputSection *OS, InputSectionDescription *, uint64_t Off); @@ -161,11 +160,11 @@ bool normalizeExistingThunk(Relocation &Rel, uint64_t Src); // Record all the available Thunks for a Symbol - llvm::DenseMap> ThunkedSymbols; + llvm::DenseMap> ThunkedSymbols; // Find a Thunk from the Thunks symbol definition, we can use this to find // the Thunk from a relocation to the Thunks symbol definition. - llvm::DenseMap Thunks; + llvm::DenseMap Thunks; // Track InputSections that have an inline ThunkSection placed in front // an inline ThunkSection may have control fall through to the section below Index: lld/trunk/ELF/Relocations.cpp =================================================================== --- lld/trunk/ELF/Relocations.cpp +++ lld/trunk/ELF/Relocations.cpp @@ -70,7 +70,7 @@ // >>> referenced by bar.c:12 (/home/alice/src/bar.c:12) // >>> /home/alice/src/bar.o:(.text+0x1) template -static std::string getLocation(InputSectionBase &S, const SymbolBody &Sym, +static std::string getLocation(InputSectionBase &S, const Symbol &Sym, uint64_t Off) { std::string Msg = "\n>>> defined in " + toString(Sym.getFile()) + "\n>>> referenced by "; @@ -108,7 +108,7 @@ // Mips has a custom MipsGotSection that handles the writing of GOT entries // without dynamic relocations. template -static unsigned handleMipsTlsRelocation(RelType Type, SymbolBody &Body, +static unsigned handleMipsTlsRelocation(RelType Type, Symbol &Body, InputSectionBase &C, uint64_t Offset, int64_t Addend, RelExpr Expr) { if (Expr == R_MIPS_TLSLD) { @@ -150,7 +150,7 @@ // GOT[e0] Module Index (Used to find pointer to TLS block at run-time) // GOT[e1] Offset of symbol in TLS block template -static unsigned handleARMTlsRelocation(RelType Type, SymbolBody &Body, +static unsigned handleARMTlsRelocation(RelType Type, Symbol &Body, InputSectionBase &C, uint64_t Offset, int64_t Addend, RelExpr Expr) { // The Dynamic TLS Module Index Relocation for a symbol defined in an @@ -159,8 +159,7 @@ bool NeedDynId = Body.IsPreemptible || Config->Shared; bool NeedDynOff = Body.IsPreemptible; - auto AddTlsReloc = [&](uint64_t Off, RelType Type, SymbolBody *Dest, - bool Dyn) { + auto AddTlsReloc = [&](uint64_t Off, RelType Type, Symbol *Dest, bool Dyn) { if (Dyn) In::RelaDyn->addReloc({Type, InX::Got, Off, false, Dest, 0}); else @@ -197,7 +196,7 @@ // Returns the number of relocations processed. template static unsigned -handleTlsRelocation(RelType Type, SymbolBody &Body, InputSectionBase &C, +handleTlsRelocation(RelType Type, Symbol &Body, InputSectionBase &C, typename ELFT::uint Offset, int64_t Addend, RelExpr Expr) { if (!(C.Flags & SHF_ALLOC)) return 0; @@ -326,7 +325,7 @@ // True if non-preemptable symbol always has the same value regardless of where // the DSO is loaded. -static bool isAbsolute(const SymbolBody &Body) { +static bool isAbsolute(const Symbol &Body) { if (Body.isUndefWeak()) return true; if (const auto *DR = dyn_cast(&Body)) @@ -334,7 +333,7 @@ return false; } -static bool isAbsoluteValue(const SymbolBody &Body) { +static bool isAbsoluteValue(const Symbol &Body) { return isAbsolute(Body) || Body.isTls(); } @@ -370,8 +369,8 @@ // dynamic relocation so that the relocation will be fixed at load-time. template static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, - const SymbolBody &Body, - InputSectionBase &S, uint64_t RelOff) { + const Symbol &Body, InputSectionBase &S, + uint64_t RelOff) { // These expressions always compute a constant if (isRelExprOneOfValue) continue; StringRef Name = check(S.getName(File->getStringTable())); - SymbolBody *Sym = Symtab->find(Name); + Symbol *Sym = Symtab->find(Name); if (auto *Alias = dyn_cast_or_null(Sym)) Ret.push_back(Alias); } @@ -558,7 +557,7 @@ } template -static RelExpr adjustExpr(SymbolBody &Body, RelExpr Expr, RelType Type, +static RelExpr adjustExpr(Symbol &Body, RelExpr Expr, RelType Type, InputSectionBase &S, uint64_t RelOff) { // We can create any dynamic relocation if a section is simply writable. if (S.Flags & SHF_WRITE) @@ -712,7 +711,7 @@ // Report an undefined symbol if necessary. // Returns true if this function printed out an error message. template -static bool maybeReportUndefined(SymbolBody &Sym, InputSectionBase &Sec, +static bool maybeReportUndefined(Symbol &Sym, InputSectionBase &Sec, uint64_t Offset) { if (Config->UnresolvedSymbols == UnresolvedPolicy::IgnoreAll) return false; @@ -806,15 +805,14 @@ template static void addPltEntry(PltSection *Plt, GotPltSection *GotPlt, - RelocationSection *Rel, RelType Type, - SymbolBody &Sym, bool UseSymVA) { + RelocationSection *Rel, RelType Type, Symbol &Sym, + bool UseSymVA) { Plt->addEntry(Sym); GotPlt->addEntry(Sym); Rel->addReloc({Type, GotPlt, Sym.getGotPltOffset(), UseSymVA, &Sym, 0}); } -template -static void addGotEntry(SymbolBody &Sym, bool Preemptible) { +template static void addGotEntry(Symbol &Sym, bool Preemptible) { InX::Got->addEntry(Sym); RelExpr Expr = Sym.isTls() ? R_TLS : R_ABS; @@ -873,7 +871,7 @@ for (auto I = Rels.begin(), End = Rels.end(); I != End; ++I) { const RelTy &Rel = *I; - SymbolBody &Body = Sec.getFile()->getRelocTargetSym(Rel); + Symbol &Body = Sec.getFile()->getRelocTargetSym(Rel); RelType Type = Rel.getType(Config->IsMips64EL); // Deal with MIPS oddity. @@ -1281,7 +1279,7 @@ return TS; } -std::pair ThunkCreator::getThunk(SymbolBody &Body, RelType Type, +std::pair ThunkCreator::getThunk(Symbol &Body, RelType Type, uint64_t Src) { auto Res = ThunkedSymbols.insert({&Body, std::vector()}); if (!Res.second) { Index: lld/trunk/ELF/SymbolTable.h =================================================================== --- lld/trunk/ELF/SymbolTable.h +++ lld/trunk/ELF/SymbolTable.h @@ -39,22 +39,22 @@ template void addSymbolWrap(StringRef Name); void applySymbolRenames(); - ArrayRef getSymbols() const { return SymVector; } + ArrayRef getSymbols() const { return SymVector; } template DefinedRegular *addAbsolute(StringRef Name, uint8_t Visibility = llvm::ELF::STV_HIDDEN, uint8_t Binding = llvm::ELF::STB_GLOBAL); - template SymbolBody *addUndefined(StringRef Name); + template Symbol *addUndefined(StringRef Name); template - SymbolBody *addUndefined(StringRef Name, bool IsLocal, uint8_t Binding, - uint8_t StOther, uint8_t Type, - bool CanOmitFromDynSym, InputFile *File); + Symbol *addUndefined(StringRef Name, bool IsLocal, uint8_t Binding, + uint8_t StOther, uint8_t Type, bool CanOmitFromDynSym, + InputFile *File); template - SymbolBody *addRegular(StringRef Name, uint8_t StOther, uint8_t Type, - uint64_t Value, uint64_t Size, uint8_t Binding, - SectionBase *Section, InputFile *File); + Symbol *addRegular(StringRef Name, uint8_t StOther, uint8_t Type, + uint64_t Value, uint64_t Size, uint8_t Binding, + SectionBase *Section, InputFile *File); template void addShared(StringRef Name, SharedFile *F, @@ -62,40 +62,39 @@ const typename ELFT::Verdef *Verdef); template - SymbolBody *addLazyArchive(StringRef Name, ArchiveFile *F, - const llvm::object::Archive::Symbol S); + Symbol *addLazyArchive(StringRef Name, ArchiveFile *F, + const llvm::object::Archive::Symbol S); template void addLazyObject(StringRef Name, LazyObjFile &Obj); - SymbolBody *addBitcode(StringRef Name, uint8_t Binding, uint8_t StOther, - uint8_t Type, bool CanOmitFromDynSym, - BitcodeFile *File); - - SymbolBody *addCommon(StringRef Name, uint64_t Size, uint32_t Alignment, - uint8_t Binding, uint8_t StOther, uint8_t Type, - InputFile *File); - - std::pair insert(StringRef Name); - std::pair insert(StringRef Name, uint8_t Type, - uint8_t Visibility, - bool CanOmitFromDynSym, InputFile *File); + Symbol *addBitcode(StringRef Name, uint8_t Binding, uint8_t StOther, + uint8_t Type, bool CanOmitFromDynSym, BitcodeFile *File); + + Symbol *addCommon(StringRef Name, uint64_t Size, uint32_t Alignment, + uint8_t Binding, uint8_t StOther, uint8_t Type, + InputFile *File); + + std::pair insert(StringRef Name); + std::pair insert(StringRef Name, uint8_t Type, + uint8_t Visibility, bool CanOmitFromDynSym, + InputFile *File); template void fetchIfLazy(StringRef Name); template void scanShlibUndefined(); void scanVersionScript(); - SymbolBody *find(StringRef Name); + Symbol *find(StringRef Name); void trace(StringRef Name); void handleDynamicList(); private: - std::vector findByVersion(SymbolVersion Ver); - std::vector findAllByVersion(SymbolVersion Ver); - void defsym(SymbolBody *Dst, SymbolBody *Src); + std::vector findByVersion(SymbolVersion Ver); + std::vector findAllByVersion(SymbolVersion Ver); + void defsym(Symbol *Dst, Symbol *Src); - llvm::StringMap> &getDemangledSyms(); + llvm::StringMap> &getDemangledSyms(); void handleAnonymousVersion(); void assignExactVersion(SymbolVersion Ver, uint16_t VersionId, StringRef VersionName); @@ -115,7 +114,7 @@ // FIXME: Experiment with passing in a custom hashing or sorting the symbols // once symbol resolution is finished. llvm::DenseMap Symtab; - std::vector SymVector; + std::vector SymVector; // Comdat groups define "link once" sections. If two comdat groups have the // same name, only one of them is linked, and the other is ignored. This set @@ -129,11 +128,11 @@ // This mapping is 1:N because two symbols with different versions // can have the same name. We use this map to handle "extern C++ {}" // directive in version scripts. - llvm::Optional>> DemangledSyms; + llvm::Optional>> DemangledSyms; struct SymbolRenaming { - SymbolBody *Dst; - SymbolBody *Src; + Symbol *Dst; + Symbol *Src; uint8_t Binding; }; @@ -141,7 +140,7 @@ std::vector Defsyms; // For -wrap. - std::vector> WrapSymbols; + std::vector> WrapSymbols; // For LTO. std::unique_ptr LTO; Index: lld/trunk/ELF/SymbolTable.cpp =================================================================== --- lld/trunk/ELF/SymbolTable.cpp +++ lld/trunk/ELF/SymbolTable.cpp @@ -136,8 +136,8 @@ template DefinedRegular *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility, uint8_t Binding) { - SymbolBody *Sym = addRegular(Name, Visibility, STT_NOTYPE, 0, 0, - Binding, nullptr, nullptr); + Symbol *Sym = addRegular(Name, Visibility, STT_NOTYPE, 0, 0, Binding, + nullptr, nullptr); return cast(Sym); } @@ -150,11 +150,11 @@ // Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM. // Used to implement --wrap. template void SymbolTable::addSymbolWrap(StringRef Name) { - SymbolBody *Sym = find(Name); + Symbol *Sym = find(Name); if (!Sym) return; - SymbolBody *Real = addUndefined(Saver.save("__real_" + Name)); - SymbolBody *Wrap = addUndefined(Saver.save("__wrap_" + Name)); + Symbol *Real = addUndefined(Saver.save("__real_" + Name)); + Symbol *Wrap = addUndefined(Saver.save("__wrap_" + Name)); defsym(Real, Sym); defsym(Sym, Wrap); @@ -165,7 +165,7 @@ // Creates alias for symbol. Used to implement --defsym=ALIAS=SYM. template void SymbolTable::addSymbolAlias(StringRef Alias, StringRef Name) { - SymbolBody *B = find(Name); + Symbol *B = find(Name); if (!B) { error("-defsym: undefined symbol: " + Name); return; @@ -204,15 +204,15 @@ // __real_foo into it. for (unsigned I = 0, N = WrapSymbols.size(); I < N; ++I) { // We now have two copies of __wrap_foo. Drop one. - SymbolBody *Wrap = WrapSymbols[I].first; + Symbol *Wrap = WrapSymbols[I].first; Wrap->IsUsedInRegularObj = false; - auto *Real = (SymbolBody *)&Origs[I]; + auto *Real = (Symbol *)&Origs[I]; // If __real_foo was undefined, we don't want it in the symbol table. if (!Real->isInCurrentOutput()) continue; - auto *NewSym = (SymbolBody *)make(); + auto *NewSym = (Symbol *)make(); memcpy(NewSym, Real, sizeof(SymbolUnion)); SymVector.push_back(NewSym); } @@ -227,7 +227,7 @@ } // Find an existing symbol or create and insert a new one. -std::pair SymbolTable::insert(StringRef Name) { +std::pair SymbolTable::insert(StringRef Name) { // @@ means the symbol is the default version. In that // case @@ will be used to resolve references to . // @@ -248,9 +248,9 @@ V = SymIndex((int)SymVector.size(), true); } - SymbolBody *Sym; + Symbol *Sym; if (IsNew) { - Sym = (SymbolBody *)make(); + Sym = (Symbol *)make(); Sym->InVersionScript = false; Sym->Binding = STB_WEAK; Sym->Visibility = STV_DEFAULT; @@ -268,11 +268,11 @@ // Find an existing symbol or create and insert a new one, then apply the given // attributes. -std::pair SymbolTable::insert(StringRef Name, uint8_t Type, - uint8_t Visibility, - bool CanOmitFromDynSym, - InputFile *File) { - SymbolBody *S; +std::pair SymbolTable::insert(StringRef Name, uint8_t Type, + uint8_t Visibility, + bool CanOmitFromDynSym, + InputFile *File) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); @@ -285,7 +285,7 @@ if (!File || File->kind() == InputFile::ObjKind) S->IsUsedInRegularObj = true; - if (!WasInserted && S->Type != SymbolBody::UnknownType && + if (!WasInserted && S->Type != Symbol::UnknownType && ((Type == STT_TLS) != S->isTls())) { error("TLS attribute mismatch: " + toString(*S) + "\n>>> defined in " + toString(S->File) + "\n>>> defined in " + toString(File)); @@ -294,7 +294,7 @@ return {S, WasInserted}; } -template SymbolBody *SymbolTable::addUndefined(StringRef Name) { +template Symbol *SymbolTable::addUndefined(StringRef Name) { return addUndefined(Name, /*IsLocal=*/false, STB_GLOBAL, STV_DEFAULT, /*Type*/ 0, /*CanOmitFromDynSym*/ false, /*File*/ nullptr); @@ -303,11 +303,10 @@ static uint8_t getVisibility(uint8_t StOther) { return StOther & 3; } template -SymbolBody *SymbolTable::addUndefined(StringRef Name, bool IsLocal, - uint8_t Binding, uint8_t StOther, - uint8_t Type, bool CanOmitFromDynSym, - InputFile *File) { - SymbolBody *S; +Symbol *SymbolTable::addUndefined(StringRef Name, bool IsLocal, uint8_t Binding, + uint8_t StOther, uint8_t Type, + bool CanOmitFromDynSym, InputFile *File) { + Symbol *S; bool WasInserted; uint8_t Visibility = getVisibility(StOther); std::tie(S, WasInserted) = @@ -342,7 +341,7 @@ // FIXME: If users can transition to using // .symver foo,foo@@@VER // we can delete this hack. -static int compareVersion(SymbolBody *S, StringRef Name) { +static int compareVersion(Symbol *S, StringRef Name) { bool A = Name.contains("@@"); bool B = S->getName().contains("@@"); if (A && !B) @@ -355,7 +354,7 @@ // We have a new defined symbol with the specified binding. Return 1 if the new // symbol should win, -1 if the new symbol should lose, or 0 if both symbols are // strong defined symbols. -static int compareDefined(SymbolBody *S, bool WasInserted, uint8_t Binding, +static int compareDefined(Symbol *S, bool WasInserted, uint8_t Binding, StringRef Name) { if (WasInserted) return 1; @@ -373,9 +372,9 @@ // We have a new non-common defined symbol with the specified binding. Return 1 // if the new symbol should win, -1 if the new symbol should lose, or 0 if there // is a conflict. If the new symbol wins, also update the binding. -static int compareDefinedNonCommon(SymbolBody *S, bool WasInserted, - uint8_t Binding, bool IsAbsolute, - uint64_t Value, StringRef Name) { +static int compareDefinedNonCommon(Symbol *S, bool WasInserted, uint8_t Binding, + bool IsAbsolute, uint64_t Value, + StringRef Name) { if (int Cmp = compareDefined(S, WasInserted, Binding, Name)) { if (Cmp > 0) S->Binding = Binding; @@ -395,11 +394,10 @@ return 0; } -SymbolBody *SymbolTable::addCommon(StringRef N, uint64_t Size, - uint32_t Alignment, uint8_t Binding, - uint8_t StOther, uint8_t Type, - InputFile *File) { - SymbolBody *S; +Symbol *SymbolTable::addCommon(StringRef N, uint64_t Size, uint32_t Alignment, + uint8_t Binding, uint8_t StOther, uint8_t Type, + InputFile *File) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(N, Type, getVisibility(StOther), /*CanOmitFromDynSym*/ false, File); @@ -433,14 +431,14 @@ error(Msg); } -static void reportDuplicate(SymbolBody *Sym, InputFile *NewFile) { +static void reportDuplicate(Symbol *Sym, InputFile *NewFile) { warnOrError("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " + toString(Sym->getFile()) + "\n>>> defined in " + toString(NewFile)); } template -static void reportDuplicate(SymbolBody *Sym, InputSectionBase *ErrSec, +static void reportDuplicate(Symbol *Sym, InputSectionBase *ErrSec, typename ELFT::uint ErrOffset) { DefinedRegular *D = dyn_cast(Sym); if (!D || !D->Section || !ErrSec) { @@ -472,11 +470,10 @@ } template -SymbolBody *SymbolTable::addRegular(StringRef Name, uint8_t StOther, - uint8_t Type, uint64_t Value, uint64_t Size, - uint8_t Binding, SectionBase *Section, - InputFile *File) { - SymbolBody *S; +Symbol *SymbolTable::addRegular(StringRef Name, uint8_t StOther, uint8_t Type, + uint64_t Value, uint64_t Size, uint8_t Binding, + SectionBase *Section, InputFile *File) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name, Type, getVisibility(StOther), /*CanOmitFromDynSym*/ false, File); @@ -498,7 +495,7 @@ // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT // as the visibility, which will leave the visibility in the symbol table // unchanged. - SymbolBody *S; + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT, /*CanOmitFromDynSym*/ true, File); @@ -517,10 +514,10 @@ } } -SymbolBody *SymbolTable::addBitcode(StringRef Name, uint8_t Binding, - uint8_t StOther, uint8_t Type, - bool CanOmitFromDynSym, BitcodeFile *F) { - SymbolBody *S; +Symbol *SymbolTable::addBitcode(StringRef Name, uint8_t Binding, + uint8_t StOther, uint8_t Type, + bool CanOmitFromDynSym, BitcodeFile *F) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name, Type, getVisibility(StOther), CanOmitFromDynSym, F); @@ -534,7 +531,7 @@ return S; } -SymbolBody *SymbolTable::find(StringRef Name) { +Symbol *SymbolTable::find(StringRef Name) { auto It = Symtab.find(CachedHashStringRef(Name)); if (It == Symtab.end()) return nullptr; @@ -544,7 +541,7 @@ return SymVector[V.Idx]; } -void SymbolTable::defsym(SymbolBody *Dst, SymbolBody *Src) { +void SymbolTable::defsym(Symbol *Dst, Symbol *Src) { // We want to tell LTO not to inline Dst symbol because LTO doesn't // know the final symbol contents after renaming. Dst->CanInline = false; @@ -556,13 +553,13 @@ } template -SymbolBody *SymbolTable::addLazyArchive(StringRef Name, ArchiveFile *F, - const object::Archive::Symbol Sym) { - SymbolBody *S; +Symbol *SymbolTable::addLazyArchive(StringRef Name, ArchiveFile *F, + const object::Archive::Symbol Sym) { + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); if (WasInserted) { - replaceBody(S, F, Sym, SymbolBody::UnknownType); + replaceBody(S, F, Sym, Symbol::UnknownType); return S; } if (!S->isUndefined()) @@ -582,11 +579,11 @@ template void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) { - SymbolBody *S; + Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); if (WasInserted) { - replaceBody(S, &Obj, Name, SymbolBody::UnknownType); + replaceBody(S, &Obj, Name, Symbol::UnknownType); return; } if (!S->isUndefined()) @@ -601,7 +598,7 @@ // If we already saw this symbol, force loading its file. template void SymbolTable::fetchIfLazy(StringRef Name) { - if (SymbolBody *B = find(Name)) { + if (Symbol *B = find(Name)) { // Mark the symbol not to be eliminated by LTO // even if it is a bitcode symbol. B->IsUsedInRegularObj = true; @@ -621,7 +618,7 @@ template void SymbolTable::scanShlibUndefined() { for (InputFile *F : SharedFiles) { for (StringRef U : cast>(F)->getUndefinedSymbols()) { - SymbolBody *Sym = find(U); + Symbol *Sym = find(U); if (!Sym || !Sym->isDefined()) continue; Sym->ExportDynamic = true; @@ -648,10 +645,10 @@ // other than trying to match a pattern against all demangled symbols. // So, if "extern C++" feature is used, we need to demangle all known // symbols. -StringMap> &SymbolTable::getDemangledSyms() { +StringMap> &SymbolTable::getDemangledSyms() { if (!DemangledSyms) { DemangledSyms.emplace(); - for (SymbolBody *Sym : SymVector) { + for (Symbol *Sym : SymVector) { if (!Sym->isInCurrentOutput()) continue; if (Optional S = demangle(Sym->getName())) @@ -663,17 +660,17 @@ return *DemangledSyms; } -std::vector SymbolTable::findByVersion(SymbolVersion Ver) { +std::vector SymbolTable::findByVersion(SymbolVersion Ver) { if (Ver.IsExternCpp) return getDemangledSyms().lookup(Ver.Name); - if (SymbolBody *B = find(Ver.Name)) + if (Symbol *B = find(Ver.Name)) if (B->isInCurrentOutput()) return {B}; return {}; } -std::vector SymbolTable::findAllByVersion(SymbolVersion Ver) { - std::vector Res; +std::vector SymbolTable::findAllByVersion(SymbolVersion Ver) { + std::vector Res; StringMatcher M(Ver.Name); if (Ver.IsExternCpp) { @@ -683,7 +680,7 @@ return Res; } - for (SymbolBody *Sym : SymVector) + for (Symbol *Sym : SymVector) if (Sym->isInCurrentOutput() && M.match(Sym->getName())) Res.push_back(Sym); return Res; @@ -706,13 +703,13 @@ // Handles -dynamic-list. void SymbolTable::handleDynamicList() { for (SymbolVersion &Ver : Config->DynamicList) { - std::vector Syms; + std::vector Syms; if (Ver.HasWildcard) Syms = findByVersion(Ver); else Syms = findAllByVersion(Ver); - for (SymbolBody *B : Syms) { + for (Symbol *B : Syms) { if (!Config->Shared) B->ExportDynamic = true; else if (B->includeInDynsym()) @@ -729,7 +726,7 @@ return; // Get a list of symbols which we need to assign the version to. - std::vector Syms = findByVersion(Ver); + std::vector Syms = findByVersion(Ver); if (Syms.empty()) { if (Config->NoUndefinedVersion) error("version script assignment of '" + VersionName + "' to symbol '" + @@ -738,7 +735,7 @@ } // Assign the version. - for (SymbolBody *Sym : Syms) { + for (Symbol *Sym : Syms) { // Skip symbols containing version info because symbol versions // specified by symbol names take precedence over version scripts. // See parseSymbolVersion(). @@ -759,7 +756,7 @@ // Exact matching takes precendence over fuzzy matching, // so we set a version to a symbol only if no version has been assigned // to the symbol. This behavior is compatible with GNU. - for (SymbolBody *B : findAllByVersion(Ver)) + for (Symbol *B : findAllByVersion(Ver)) if (B->VersionId == Config->DefaultSymbolVersion) B->VersionId = VersionId; } @@ -792,7 +789,7 @@ // Symbol themselves might know their versions because symbols // can contain versions in the form of @. // Let them parse and update their names to exclude version suffix. - for (SymbolBody *Sym : SymVector) + for (Symbol *Sym : SymVector) Sym->parseSymbolVersion(); } @@ -801,27 +798,23 @@ template void SymbolTable::addSymbolWrap(StringRef); template void SymbolTable::addSymbolWrap(StringRef); -template SymbolBody *SymbolTable::addUndefined(StringRef); -template SymbolBody *SymbolTable::addUndefined(StringRef); -template SymbolBody *SymbolTable::addUndefined(StringRef); -template SymbolBody *SymbolTable::addUndefined(StringRef); - -template SymbolBody *SymbolTable::addUndefined(StringRef, bool, - uint8_t, uint8_t, - uint8_t, bool, - InputFile *); -template SymbolBody *SymbolTable::addUndefined(StringRef, bool, - uint8_t, uint8_t, - uint8_t, bool, - InputFile *); -template SymbolBody *SymbolTable::addUndefined(StringRef, bool, - uint8_t, uint8_t, - uint8_t, bool, - InputFile *); -template SymbolBody *SymbolTable::addUndefined(StringRef, bool, - uint8_t, uint8_t, - uint8_t, bool, - InputFile *); +template Symbol *SymbolTable::addUndefined(StringRef); +template Symbol *SymbolTable::addUndefined(StringRef); +template Symbol *SymbolTable::addUndefined(StringRef); +template Symbol *SymbolTable::addUndefined(StringRef); + +template Symbol *SymbolTable::addUndefined(StringRef, bool, uint8_t, + uint8_t, uint8_t, bool, + InputFile *); +template Symbol *SymbolTable::addUndefined(StringRef, bool, uint8_t, + uint8_t, uint8_t, bool, + InputFile *); +template Symbol *SymbolTable::addUndefined(StringRef, bool, uint8_t, + uint8_t, uint8_t, bool, + InputFile *); +template Symbol *SymbolTable::addUndefined(StringRef, bool, uint8_t, + uint8_t, uint8_t, bool, + InputFile *); template void SymbolTable::addSymbolAlias(StringRef, StringRef); template void SymbolTable::addSymbolAlias(StringRef, StringRef); @@ -833,18 +826,18 @@ template void SymbolTable::addCombinedLTOObject(); template void SymbolTable::addCombinedLTOObject(); -template SymbolBody * -SymbolTable::addRegular(StringRef, uint8_t, uint8_t, uint64_t, - uint64_t, uint8_t, SectionBase *, InputFile *); -template SymbolBody * -SymbolTable::addRegular(StringRef, uint8_t, uint8_t, uint64_t, - uint64_t, uint8_t, SectionBase *, InputFile *); -template SymbolBody * -SymbolTable::addRegular(StringRef, uint8_t, uint8_t, uint64_t, - uint64_t, uint8_t, SectionBase *, InputFile *); -template SymbolBody * -SymbolTable::addRegular(StringRef, uint8_t, uint8_t, uint64_t, - uint64_t, uint8_t, SectionBase *, InputFile *); +template Symbol *SymbolTable::addRegular(StringRef, uint8_t, uint8_t, + uint64_t, uint64_t, uint8_t, + SectionBase *, InputFile *); +template Symbol *SymbolTable::addRegular(StringRef, uint8_t, uint8_t, + uint64_t, uint64_t, uint8_t, + SectionBase *, InputFile *); +template Symbol *SymbolTable::addRegular(StringRef, uint8_t, uint8_t, + uint64_t, uint64_t, uint8_t, + SectionBase *, InputFile *); +template Symbol *SymbolTable::addRegular(StringRef, uint8_t, uint8_t, + uint64_t, uint64_t, uint8_t, + SectionBase *, InputFile *); template DefinedRegular *SymbolTable::addAbsolute(StringRef, uint8_t, uint8_t); @@ -855,16 +848,16 @@ template DefinedRegular *SymbolTable::addAbsolute(StringRef, uint8_t, uint8_t); -template SymbolBody * +template Symbol * SymbolTable::addLazyArchive(StringRef, ArchiveFile *, const object::Archive::Symbol); -template SymbolBody * +template Symbol * SymbolTable::addLazyArchive(StringRef, ArchiveFile *, const object::Archive::Symbol); -template SymbolBody * +template Symbol * SymbolTable::addLazyArchive(StringRef, ArchiveFile *, const object::Archive::Symbol); -template SymbolBody * +template Symbol * SymbolTable::addLazyArchive(StringRef, ArchiveFile *, const object::Archive::Symbol); Index: lld/trunk/ELF/Symbols.h =================================================================== --- lld/trunk/ELF/Symbols.h +++ lld/trunk/ELF/Symbols.h @@ -35,7 +35,7 @@ template class SharedFile; // The base class for real symbol classes. -class SymbolBody { +class Symbol { public: enum Kind { DefinedFirst, @@ -48,7 +48,7 @@ LazyObjectKind, }; - SymbolBody(Kind K) : SymbolKind(K) {} + Symbol(Kind K) : SymbolKind(K) {} Kind kind() const { return static_cast(SymbolKind); } // Symbol binding. This is not overwritten by replaceSymbol to track @@ -117,7 +117,7 @@ StringRef getName() const { return Name; } uint8_t getVisibility() const { return StOther & 0x3; } void parseSymbolVersion(); - void copyFrom(SymbolBody *Other); + void copyFrom(Symbol *Other); bool isInGot() const { return GotIndex != -1U; } bool isInPlt() const { return PltIndex != -1U; } @@ -139,8 +139,7 @@ uint32_t GlobalDynIndex = -1; protected: - SymbolBody(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther, - uint8_t Type) + Symbol(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type) : SymbolKind(K), IsLocal(IsLocal), NeedsPltAddr(false), IsInGlobalMipsGot(false), Is32BitMipsGot(false), IsInIplt(false), IsInIgot(false), IsPreemptible(false), Type(Type), StOther(StOther), @@ -192,12 +191,12 @@ }; // The base class for any defined symbols. -class Defined : public SymbolBody { +class Defined : public Symbol { public: Defined(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type) - : SymbolBody(K, Name, IsLocal, StOther, Type) {} + : Symbol(K, Name, IsLocal, StOther, Type) {} - static bool classof(const SymbolBody *S) { return S->isDefined(); } + static bool classof(const Symbol *S) { return S->isDefined(); } }; class DefinedCommon : public Defined { @@ -207,7 +206,7 @@ : Defined(DefinedCommonKind, Name, /*IsLocal=*/false, StOther, Type), Alignment(Alignment), Size(Size) {} - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedCommonKind; } @@ -231,7 +230,7 @@ // Return true if the symbol is a PIC function. template bool isMipsPIC() const; - static bool classof(const SymbolBody *S) { + static bool classof(const Symbol *S) { return S->kind() == DefinedRegularKind; } @@ -240,19 +239,17 @@ SectionBase *Section; }; -class Undefined : public SymbolBody { +class Undefined : public Symbol { public: Undefined(StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type) - : SymbolBody(UndefinedKind, Name, IsLocal, StOther, Type) {} + : Symbol(UndefinedKind, Name, IsLocal, StOther, Type) {} - static bool classof(const SymbolBody *S) { - return S->kind() == UndefinedKind; - } + static bool classof(const Symbol *S) { return S->kind() == UndefinedKind; } }; class SharedSymbol : public Defined { public: - static bool classof(const SymbolBody *S) { return S->kind() == SharedKind; } + static bool classof(const Symbol *S) { return S->kind() == SharedKind; } SharedSymbol(StringRef Name, uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size, uint32_t Alignment, const void *Verdef) @@ -279,7 +276,7 @@ } template SharedFile *getFile() const { - return cast>(SymbolBody::getFile()); + return cast>(Symbol::getFile()); } template uint32_t getAlignment() const; @@ -304,9 +301,9 @@ // and the lazy. We represent that with a lazy symbol with a weak binding. This // means that code looking for undefined symbols normally also has to take lazy // symbols into consideration. -class Lazy : public SymbolBody { +class Lazy : public Symbol { public: - static bool classof(const SymbolBody *S) { return S->isLazy(); } + static bool classof(const Symbol *S) { return S->isLazy(); } // Returns an object file for this symbol, or a nullptr if the file // was already returned. @@ -314,7 +311,7 @@ protected: Lazy(Kind K, StringRef Name, uint8_t Type) - : SymbolBody(K, Name, /*IsLocal=*/false, llvm::ELF::STV_DEFAULT, Type) {} + : Symbol(K, Name, /*IsLocal=*/false, llvm::ELF::STV_DEFAULT, Type) {} }; // This class represents a symbol defined in an archive file. It is @@ -326,9 +323,7 @@ LazyArchive(const llvm::object::Archive::Symbol S, uint8_t Type) : Lazy(LazyArchiveKind, S.getName(), Type), Sym(S) {} - static bool classof(const SymbolBody *S) { - return S->kind() == LazyArchiveKind; - } + static bool classof(const Symbol *S) { return S->kind() == LazyArchiveKind; } ArchiveFile *getFile(); InputFile *fetch(); @@ -343,9 +338,7 @@ public: LazyObject(StringRef Name, uint8_t Type) : Lazy(LazyObjectKind, Name, Type) {} - static bool classof(const SymbolBody *S) { - return S->kind() == LazyObjectKind; - } + static bool classof(const Symbol *S) { return S->kind() == LazyObjectKind; } LazyObjFile *getFile(); InputFile *fetch(); @@ -380,7 +373,7 @@ static DefinedRegular *MipsLocalGp; }; -// A buffer class that is large enough to hold any SymbolBody-derived +// A buffer class that is large enough to hold any Symbol-derived // object. We allocate memory using this class and instantiate a symbol // using the placement new. union SymbolUnion { @@ -392,17 +385,17 @@ alignas(LazyObject) char F[sizeof(LazyObject)]; }; -void printTraceSymbol(SymbolBody *Sym); +void printTraceSymbol(Symbol *Sym); template -void replaceBody(SymbolBody *S, InputFile *File, ArgT &&... Arg) { +void replaceBody(Symbol *S, InputFile *File, ArgT &&... Arg) { static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small"); static_assert(alignof(T) <= alignof(SymbolUnion), "SymbolUnion not aligned enough"); - assert(static_cast(static_cast(nullptr)) == nullptr && - "Not a SymbolBody"); + assert(static_cast(static_cast(nullptr)) == nullptr && + "Not a Symbol"); - SymbolBody Sym = *S; + Symbol Sym = *S; new (S) T(std::forward(Arg)...); S->File = File; @@ -423,7 +416,7 @@ } } // namespace elf -std::string toString(const elf::SymbolBody &B); +std::string toString(const elf::Symbol &B); } // namespace lld #endif Index: lld/trunk/ELF/Symbols.cpp =================================================================== --- lld/trunk/ELF/Symbols.cpp +++ lld/trunk/ELF/Symbols.cpp @@ -40,9 +40,9 @@ DefinedRegular *ElfSym::MipsGpDisp; DefinedRegular *ElfSym::MipsLocalGp; -static uint64_t getSymVA(const SymbolBody &Body, int64_t &Addend) { +static uint64_t getSymVA(const Symbol &Body, int64_t &Addend) { switch (Body.kind()) { - case SymbolBody::DefinedRegularKind: { + case Symbol::DefinedRegularKind: { auto &D = cast(Body); SectionBase *IS = D.Section; if (auto *ISB = dyn_cast_or_null(IS)) @@ -99,9 +99,9 @@ } return VA; } - case SymbolBody::DefinedCommonKind: + case Symbol::DefinedCommonKind: llvm_unreachable("common are converted to bss"); - case SymbolBody::SharedKind: { + case Symbol::SharedKind: { auto &SS = cast(Body); if (SS.CopyRelSec) return SS.CopyRelSec->getParent()->Addr + SS.CopyRelSec->OutSecOff; @@ -109,10 +109,10 @@ return Body.getPltVA(); return 0; } - case SymbolBody::UndefinedKind: + case Symbol::UndefinedKind: return 0; - case SymbolBody::LazyArchiveKind: - case SymbolBody::LazyObjectKind: + case Symbol::LazyArchiveKind: + case Symbol::LazyObjectKind: assert(Body.IsUsedInRegularObj && "lazy symbol reached writer"); return 0; } @@ -120,17 +120,17 @@ } // Returns true if this is a weak undefined symbol. -bool SymbolBody::isUndefWeak() const { +bool Symbol::isUndefWeak() const { // See comment on Lazy in Symbols.h for the details. return !isLocal() && isWeak() && (isUndefined() || isLazy()); } -InputFile *SymbolBody::getFile() const { +InputFile *Symbol::getFile() const { if (isLocal()) { const SectionBase *Sec = cast(this)->Section; // Local absolute symbols actually have a file, but that is not currently // used. We could support that by having a mostly redundant InputFile in - // SymbolBody, or having a special absolute section if needed. + // Symbol, or having a special absolute section if needed. return Sec ? cast(Sec)->File : nullptr; } return File; @@ -139,8 +139,8 @@ // Overwrites all attributes with Other's so that this symbol becomes // an alias to Other. This is useful for handling some options such as // --wrap. -void SymbolBody::copyFrom(SymbolBody *Other) { - SymbolBody Sym = *this; +void Symbol::copyFrom(Symbol *Other) { + Symbol Sym = *this; memcpy(this, Other, sizeof(SymbolUnion)); Binding = Sym.Binding; @@ -153,37 +153,35 @@ InVersionScript = Sym.InVersionScript; } -uint64_t SymbolBody::getVA(int64_t Addend) const { +uint64_t Symbol::getVA(int64_t Addend) const { uint64_t OutVA = getSymVA(*this, Addend); return OutVA + Addend; } -uint64_t SymbolBody::getGotVA() const { - return InX::Got->getVA() + getGotOffset(); -} +uint64_t Symbol::getGotVA() const { return InX::Got->getVA() + getGotOffset(); } -uint64_t SymbolBody::getGotOffset() const { +uint64_t Symbol::getGotOffset() const { return GotIndex * Target->GotEntrySize; } -uint64_t SymbolBody::getGotPltVA() const { +uint64_t Symbol::getGotPltVA() const { if (this->IsInIgot) return InX::IgotPlt->getVA() + getGotPltOffset(); return InX::GotPlt->getVA() + getGotPltOffset(); } -uint64_t SymbolBody::getGotPltOffset() const { +uint64_t Symbol::getGotPltOffset() const { return GotPltIndex * Target->GotPltEntrySize; } -uint64_t SymbolBody::getPltVA() const { +uint64_t Symbol::getPltVA() const { if (this->IsInIplt) return InX::Iplt->getVA() + PltIndex * Target->PltEntrySize; return InX::Plt->getVA() + Target->PltHeaderSize + PltIndex * Target->PltEntrySize; } -uint64_t SymbolBody::getSize() const { +uint64_t Symbol::getSize() const { if (const auto *C = dyn_cast(this)) return C->Size; if (const auto *DR = dyn_cast(this)) @@ -193,7 +191,7 @@ return 0; } -OutputSection *SymbolBody::getOutputSection() const { +OutputSection *Symbol::getOutputSection() const { if (auto *S = dyn_cast(this)) { if (S->Section) return S->Section->getOutputSection(); @@ -217,7 +215,7 @@ // If a symbol name contains '@', the characters after that is // a symbol version name. This function parses that. -void SymbolBody::parseSymbolVersion() { +void Symbol::parseSymbolVersion() { StringRef S = getName(); size_t Pos = S.find('@'); if (Pos == 0 || Pos == StringRef::npos) @@ -277,7 +275,7 @@ } ArchiveFile *LazyArchive::getFile() { - return cast(SymbolBody::getFile()); + return cast(Symbol::getFile()); } InputFile *LazyArchive::fetch() { @@ -291,12 +289,12 @@ } LazyObjFile *LazyObject::getFile() { - return cast(SymbolBody::getFile()); + return cast(Symbol::getFile()); } InputFile *LazyObject::fetch() { return getFile()->fetch(); } -uint8_t SymbolBody::computeBinding() const { +uint8_t Symbol::computeBinding() const { if (Config->Relocatable) return Binding; if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) @@ -308,7 +306,7 @@ return Binding; } -bool SymbolBody::includeInDynsym() const { +bool Symbol::includeInDynsym() const { if (!Config->HasDynSymTab) return false; if (computeBinding() == STB_LOCAL) @@ -319,7 +317,7 @@ } // Print out a log message for --trace-symbol. -void elf::printTraceSymbol(SymbolBody *Sym) { +void elf::printTraceSymbol(Symbol *Sym) { std::string S; if (Sym->isUndefined()) S = ": reference to "; @@ -336,7 +334,7 @@ } // Returns a symbol for an error message. -std::string lld::toString(const SymbolBody &B) { +std::string lld::toString(const Symbol &B) { if (Config->Demangle) if (Optional S = demangle(B.getName())) return *S; Index: lld/trunk/ELF/SyntheticSections.h =================================================================== --- lld/trunk/ELF/SyntheticSections.h +++ lld/trunk/ELF/SyntheticSections.h @@ -99,8 +99,7 @@ std::vector CieRecords; // CIE records are uniquified by their contents and personality functions. - llvm::DenseMap, SymbolBody *>, CieRecord *> - CieMap; + llvm::DenseMap, Symbol *>, CieRecord *> CieMap; }; class GotSection : public SyntheticSection { @@ -111,11 +110,11 @@ bool empty() const override; void writeTo(uint8_t *Buf) override; - void addEntry(SymbolBody &Sym); - bool addDynTlsEntry(SymbolBody &Sym); + void addEntry(Symbol &Sym); + bool addDynTlsEntry(Symbol &Sym); bool addTlsIndex(); - uint64_t getGlobalDynAddr(const SymbolBody &B) const; - uint64_t getGlobalDynOffset(const SymbolBody &B) const; + uint64_t getGlobalDynAddr(const Symbol &B) const; + uint64_t getGlobalDynOffset(const Symbol &B) const; uint64_t getTlsIndexVA() { return this->getVA() + TlsIndexOff; } uint32_t getTlsIndexOff() const { return TlsIndexOff; } @@ -172,18 +171,18 @@ bool updateAllocSize() override; void finalizeContents() override; bool empty() const override; - void addEntry(SymbolBody &Sym, int64_t Addend, RelExpr Expr); - bool addDynTlsEntry(SymbolBody &Sym); + void addEntry(Symbol &Sym, int64_t Addend, RelExpr Expr); + bool addDynTlsEntry(Symbol &Sym); bool addTlsIndex(); - uint64_t getPageEntryOffset(const SymbolBody &B, int64_t Addend) const; - uint64_t getBodyEntryOffset(const SymbolBody &B, int64_t Addend) const; - uint64_t getGlobalDynOffset(const SymbolBody &B) const; + uint64_t getPageEntryOffset(const Symbol &B, int64_t Addend) const; + uint64_t getBodyEntryOffset(const Symbol &B, int64_t Addend) const; + uint64_t getGlobalDynOffset(const Symbol &B) const; // Returns the symbol which corresponds to the first entry of the global part // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic // table properties. // Returns nullptr if the global part is empty. - const SymbolBody *getFirstGlobalEntry() const; + const Symbol *getFirstGlobalEntry() const; // Returns the number of entries in the local part of GOT including // the number of reserved entries. @@ -243,7 +242,7 @@ // to the first index of "Page" entries allocated for this section. llvm::SmallMapVector PageIndexMap; - typedef std::pair GotEntry; + typedef std::pair GotEntry; typedef std::vector GotEntries; // Map from Symbol-Addend pair to the GOT index. llvm::DenseMap EntryIndexMap; @@ -256,7 +255,7 @@ GotEntries GlobalEntries; // TLS entries. - std::vector TlsEntries; + std::vector TlsEntries; uint32_t TlsIndexOff = -1; uint64_t Size = 0; @@ -265,13 +264,13 @@ class GotPltSection final : public SyntheticSection { public: GotPltSection(); - void addEntry(SymbolBody &Sym); + void addEntry(Symbol &Sym); size_t getSize() const override; void writeTo(uint8_t *Buf) override; bool empty() const override { return Entries.empty(); } private: - std::vector Entries; + std::vector Entries; }; // The IgotPltSection is a Got associated with the PltSection for GNU Ifunc @@ -281,13 +280,13 @@ class IgotPltSection final : public SyntheticSection { public: IgotPltSection(); - void addEntry(SymbolBody &Sym); + void addEntry(Symbol &Sym); size_t getSize() const override; void writeTo(uint8_t *Buf) override; bool empty() const override { return Entries.empty(); } private: - std::vector Entries; + std::vector Entries; }; class StringTableSection final : public SyntheticSection { @@ -310,8 +309,7 @@ class DynamicReloc { public: DynamicReloc(uint32_t Type, const InputSectionBase *InputSec, - uint64_t OffsetInSec, bool UseSymVA, SymbolBody *Sym, - int64_t Addend) + uint64_t OffsetInSec, bool UseSymVA, Symbol *Sym, int64_t Addend) : Type(Type), Sym(Sym), InputSec(InputSec), OffsetInSec(OffsetInSec), UseSymVA(UseSymVA), Addend(Addend) {} @@ -323,7 +321,7 @@ uint32_t Type; private: - SymbolBody *Sym; + Symbol *Sym; const InputSectionBase *InputSec = nullptr; uint64_t OffsetInSec; bool UseSymVA; @@ -347,7 +345,7 @@ OutputSection *OutSec; InputSection *InSec; uint64_t Val; - const SymbolBody *Sym; + const Symbol *Sym; }; enum KindT { SecAddr, SecSize, SymAddr, PlainInt, InSecAddr } Kind; Entry(int32_t Tag, OutputSection *OutSec, KindT Kind = SecAddr) @@ -355,8 +353,7 @@ Entry(int32_t Tag, InputSection *Sec) : Tag(Tag), InSec(Sec), Kind(InSecAddr) {} Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {} - Entry(int32_t Tag, const SymbolBody *Sym) - : Tag(Tag), Sym(Sym), Kind(SymAddr) {} + Entry(int32_t Tag, const Symbol *Sym) : Tag(Tag), Sym(Sym), Kind(SymAddr) {} }; // finalizeContents() fills this vector with the section contents. @@ -423,7 +420,7 @@ }; struct SymbolTableEntry { - SymbolBody *Symbol; + Symbol *Symbol; size_t StrTabOffset; }; @@ -433,9 +430,9 @@ void finalizeContents() override; void postThunkContents() override; size_t getSize() const override { return getNumSymbols() * Entsize; } - void addSymbol(SymbolBody *Body); + void addSymbol(Symbol *Body); unsigned getNumSymbols() const { return Symbols.size() + 1; } - size_t getSymbolIndex(SymbolBody *Body); + size_t getSymbolIndex(Symbol *Body); ArrayRef getSymbols() const { return Symbols; } protected: @@ -445,7 +442,7 @@ StringTableSection &StrTabSec; llvm::once_flag OnceFlag; - llvm::DenseMap SymbolIndexMap; + llvm::DenseMap SymbolIndexMap; llvm::DenseMap SectionIndexMap; }; @@ -478,7 +475,7 @@ void writeHashTable(uint8_t *Buf); struct Entry { - SymbolBody *Body; + Symbol *Body; size_t StrTabOffset; uint32_t Hash; }; @@ -512,11 +509,11 @@ bool empty() const override { return Entries.empty(); } void addSymbols(); - template void addEntry(SymbolBody &Sym); + template void addEntry(Symbol &Sym); private: unsigned getPltRelocOff() const; - std::vector> Entries; + std::vector> Entries; // Iplt always has HeaderSize of 0, the Plt HeaderSize is always non-zero size_t HeaderSize; }; @@ -830,8 +827,8 @@ void decompressSections(); void mergeSections(); -SymbolBody *addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value, - uint64_t Size, InputSectionBase *Section); +Symbol *addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value, + uint64_t Size, InputSectionBase *Section); // Linker generated sections which can be used as inputs. struct InX { Index: lld/trunk/ELF/SyntheticSections.cpp =================================================================== --- lld/trunk/ELF/SyntheticSections.cpp +++ lld/trunk/ELF/SyntheticSections.cpp @@ -66,7 +66,7 @@ // Create a .bss section for each common symbol and replace the common symbol // with a DefinedRegular symbol. template void elf::createCommonSections() { - for (SymbolBody *S : Symtab->getSymbols()) { + for (Symbol *S : Symtab->getSymbols()) { auto *Sym = dyn_cast(S); if (!Sym) @@ -296,8 +296,8 @@ return Sec; } -SymbolBody *elf::addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value, - uint64_t Size, InputSectionBase *Section) { +Symbol *elf::addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value, + uint64_t Size, InputSectionBase *Section) { auto *S = make(Name, /*IsLocal*/ true, STV_DEFAULT, Type, Value, Size, Section); if (InX::SymTab) @@ -413,7 +413,7 @@ if (read32(Cie.data().data() + 4, Config->Endianness) != 0) fatal(toString(Sec) + ": CIE expected at beginning of .eh_frame"); - SymbolBody *Personality = nullptr; + Symbol *Personality = nullptr; unsigned FirstRelI = Cie.FirstRelocation; if (FirstRelI != (unsigned)-1) Personality = @@ -447,7 +447,7 @@ return false; const RelTy &Rel = Rels[FirstRelI]; - SymbolBody &B = Sec->template getFile()->getRelocTargetSym(Rel); + Symbol &B = Sec->template getFile()->getRelocTargetSym(Rel); // FDEs for garbage-collected or merged-by-ICF sections are dead. if (auto *D = dyn_cast(&B)) @@ -620,12 +620,12 @@ : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, Target->GotEntrySize, ".got") {} -void GotSection::addEntry(SymbolBody &Sym) { +void GotSection::addEntry(Symbol &Sym) { Sym.GotIndex = NumEntries; ++NumEntries; } -bool GotSection::addDynTlsEntry(SymbolBody &Sym) { +bool GotSection::addDynTlsEntry(Symbol &Sym) { if (Sym.GlobalDynIndex != -1U) return false; Sym.GlobalDynIndex = NumEntries; @@ -644,11 +644,11 @@ return true; } -uint64_t GotSection::getGlobalDynAddr(const SymbolBody &B) const { +uint64_t GotSection::getGlobalDynAddr(const Symbol &B) const { return this->getVA() + B.GlobalDynIndex * Config->Wordsize; } -uint64_t GotSection::getGlobalDynOffset(const SymbolBody &B) const { +uint64_t GotSection::getGlobalDynOffset(const Symbol &B) const { return B.GlobalDynIndex * Config->Wordsize; } @@ -672,7 +672,7 @@ : SyntheticSection(SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL, SHT_PROGBITS, 16, ".got") {} -void MipsGotSection::addEntry(SymbolBody &Sym, int64_t Addend, RelExpr Expr) { +void MipsGotSection::addEntry(Symbol &Sym, int64_t Addend, RelExpr Expr) { // For "true" local symbols which can be referenced from the same module // only compiler creates two instructions for address loading: // @@ -714,7 +714,7 @@ TlsEntries.push_back(&Sym); return; } - auto AddEntry = [&](SymbolBody &S, uint64_t A, GotEntries &Items) { + auto AddEntry = [&](Symbol &S, uint64_t A, GotEntries &Items) { if (S.isInGot() && !A) return; size_t NewIndex = Items.size(); @@ -739,7 +739,7 @@ } } -bool MipsGotSection::addDynTlsEntry(SymbolBody &Sym) { +bool MipsGotSection::addDynTlsEntry(Symbol &Sym) { if (Sym.GlobalDynIndex != -1U) return false; Sym.GlobalDynIndex = TlsEntries.size(); @@ -768,7 +768,7 @@ return (Size + 0xfffe) / 0xffff + 1; } -uint64_t MipsGotSection::getPageEntryOffset(const SymbolBody &B, +uint64_t MipsGotSection::getPageEntryOffset(const Symbol &B, int64_t Addend) const { const OutputSection *OutSec = B.getOutputSection(); uint64_t SecAddr = getMipsPageAddr(OutSec->Addr); @@ -778,7 +778,7 @@ return (HeaderEntriesNum + Index) * Config->Wordsize; } -uint64_t MipsGotSection::getBodyEntryOffset(const SymbolBody &B, +uint64_t MipsGotSection::getBodyEntryOffset(const Symbol &B, int64_t Addend) const { // Calculate offset of the GOT entries block: TLS, global, local. uint64_t Index = HeaderEntriesNum + PageEntriesNum; @@ -803,11 +803,11 @@ return (getLocalEntriesNum() + GlobalEntries.size()) * Config->Wordsize; } -uint64_t MipsGotSection::getGlobalDynOffset(const SymbolBody &B) const { +uint64_t MipsGotSection::getGlobalDynOffset(const Symbol &B) const { return B.GlobalDynIndex * Config->Wordsize; } -const SymbolBody *MipsGotSection::getFirstGlobalEntry() const { +const Symbol *MipsGotSection::getFirstGlobalEntry() const { return GlobalEntries.empty() ? nullptr : GlobalEntries.front().first; } @@ -873,7 +873,7 @@ auto AddEntry = [&](const GotEntry &SA) { uint8_t *Entry = Buf; Buf += Config->Wordsize; - const SymbolBody *Body = SA.first; + const Symbol *Body = SA.first; uint64_t VA = Body->getVA(SA.second); writeUint(Entry, VA); }; @@ -887,7 +887,7 @@ // https://www.linux-mips.org/wiki/NPTL if (TlsIndexOff != -1U && !Config->Pic) writeUint(Buf + TlsIndexOff, 1); - for (const SymbolBody *B : TlsEntries) { + for (const Symbol *B : TlsEntries) { if (!B || B->IsPreemptible) continue; uint64_t VA = B->getVA(); @@ -908,7 +908,7 @@ : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, Target->GotPltEntrySize, ".got.plt") {} -void GotPltSection::addEntry(SymbolBody &Sym) { +void GotPltSection::addEntry(Symbol &Sym) { Sym.GotPltIndex = Target->GotPltHeaderEntriesNum + Entries.size(); Entries.push_back(&Sym); } @@ -921,7 +921,7 @@ void GotPltSection::writeTo(uint8_t *Buf) { Target->writeGotPltHeader(Buf); Buf += Target->GotPltHeaderEntriesNum * Target->GotPltEntrySize; - for (const SymbolBody *B : Entries) { + for (const Symbol *B : Entries) { Target->writeGotPlt(Buf, *B); Buf += Config->Wordsize; } @@ -934,7 +934,7 @@ Target->GotPltEntrySize, Config->EMachine == EM_ARM ? ".got" : ".got.plt") {} -void IgotPltSection::addEntry(SymbolBody &Sym) { +void IgotPltSection::addEntry(Symbol &Sym) { Sym.IsInIgot = true; Sym.GotPltIndex = Entries.size(); Entries.push_back(&Sym); @@ -945,7 +945,7 @@ } void IgotPltSection::writeTo(uint8_t *Buf) { - for (const SymbolBody *B : Entries) { + for (const Symbol *B : Entries) { Target->writeIgotPlt(Buf, *B); Buf += Config->Wordsize; } @@ -1123,10 +1123,10 @@ add({DT_FINI_ARRAYSZ, Out::FiniArray, Entry::SecSize}); } - if (SymbolBody *B = Symtab->find(Config->Init)) + if (Symbol *B = Symtab->find(Config->Init)) if (B->isInCurrentOutput()) add({DT_INIT, B}); - if (SymbolBody *B = Symtab->find(Config->Fini)) + if (Symbol *B = Symtab->find(Config->Fini)) if (B->isInCurrentOutput()) add({DT_FINI, B}); @@ -1148,7 +1148,7 @@ add({DT_MIPS_BASE_ADDRESS, Target->getImageBase()}); add({DT_MIPS_SYMTABNO, InX::DynSymTab->getNumSymbols()}); add({DT_MIPS_LOCAL_GOTNO, InX::MipsGot->getLocalEntriesNum()}); - if (const SymbolBody *B = InX::MipsGot->getFirstGlobalEntry()) + if (const Symbol *B = InX::MipsGot->getFirstGlobalEntry()) add({DT_MIPS_GOTSYM, B->DynsymIndex}); else add({DT_MIPS_GOTSYM, InX::DynSymTab->getNumSymbols()}); @@ -1539,7 +1539,7 @@ getParent()->Info = NumLocals + 1; } -void SymbolTableBaseSection::addSymbol(SymbolBody *B) { +void SymbolTableBaseSection::addSymbol(Symbol *B) { // Adding a local symbol to a .dynsym is a bug. assert(this->Type != SHT_DYNSYM || !B->isLocal()); @@ -1547,7 +1547,7 @@ Symbols.push_back({B, StrTabSec.addString(B->getName(), HashIt)}); } -size_t SymbolTableBaseSection::getSymbolIndex(SymbolBody *Body) { +size_t SymbolTableBaseSection::getSymbolIndex(Symbol *Body) { // Initializes symbol lookup tables lazily. This is used only // for -r or -emit-relocs. llvm::call_once(OnceFlag, [&] { @@ -1583,7 +1583,7 @@ auto *ESym = reinterpret_cast(Buf); for (SymbolTableEntry &Ent : Symbols) { - SymbolBody *Body = Ent.Symbol; + Symbol *Body = Ent.Symbol; // Set st_info and st_other. ESym->st_other = 0; @@ -1635,7 +1635,7 @@ auto *ESym = reinterpret_cast(Buf); for (SymbolTableEntry &Ent : Symbols) { - SymbolBody *Body = Ent.Symbol; + Symbol *Body = Ent.Symbol; if (Body->isInPlt() && Body->NeedsPltAddr) ESym->st_other |= STO_MIPS_PLT; @@ -1799,7 +1799,7 @@ return; for (SymbolTableEntry &Ent : llvm::make_range(Mid, V.end())) { - SymbolBody *B = Ent.Symbol; + Symbol *B = Ent.Symbol; Symbols.push_back({B, Ent.StrTabOffset, hashGnu(B->getName())}); } @@ -1841,7 +1841,7 @@ uint32_t *Chains = P + NumSymbols; for (const SymbolTableEntry &S : InX::DynSymTab->getSymbols()) { - SymbolBody *Body = S.Symbol; + Symbol *Body = S.Symbol; StringRef Name = Body->getName(); unsigned I = Body->DynsymIndex; uint32_t Hash = hashSysV(Name) % NumSymbols; @@ -1869,7 +1869,7 @@ unsigned PltOff = getPltRelocOff(); for (auto &I : Entries) { - const SymbolBody *B = I.first; + const Symbol *B = I.first; unsigned RelOff = I.second + PltOff; uint64_t Got = B->getGotPltVA(); uint64_t Plt = this->getVA() + Off; @@ -1878,7 +1878,7 @@ } } -template void PltSection::addEntry(SymbolBody &Sym) { +template void PltSection::addEntry(Symbol &Sym) { Sym.PltIndex = Entries.size(); RelocationSection *PltRelocSection = In::RelaPlt; if (HeaderSize == 0) { @@ -2638,10 +2638,10 @@ template void EhFrameSection::addSection(InputSectionBase *); template void EhFrameSection::addSection(InputSectionBase *); -template void PltSection::addEntry(SymbolBody &Sym); -template void PltSection::addEntry(SymbolBody &Sym); -template void PltSection::addEntry(SymbolBody &Sym); -template void PltSection::addEntry(SymbolBody &Sym); +template void PltSection::addEntry(Symbol &Sym); +template void PltSection::addEntry(Symbol &Sym); +template void PltSection::addEntry(Symbol &Sym); +template void PltSection::addEntry(Symbol &Sym); template void elf::createCommonSections(); template void elf::createCommonSections(); Index: lld/trunk/ELF/Target.h =================================================================== --- lld/trunk/ELF/Target.h +++ lld/trunk/ELF/Target.h @@ -19,7 +19,7 @@ namespace elf { class InputFile; -class SymbolBody; +class Symbol; class TargetInfo { public: @@ -27,8 +27,8 @@ virtual bool isPicRel(RelType Type) const { return true; } virtual RelType getDynRel(RelType Type) const { return Type; } virtual void writeGotPltHeader(uint8_t *Buf) const {} - virtual void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const {}; - virtual void writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const; + virtual void writeGotPlt(uint8_t *Buf, const Symbol &S) const {}; + virtual void writeIgotPlt(uint8_t *Buf, const Symbol &S) const; virtual int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const; // If lazy binding is supported, the first entry of the PLT has code @@ -53,11 +53,11 @@ // targeting S. virtual bool needsThunk(RelExpr Expr, RelType RelocType, const InputFile *File, uint64_t BranchAddr, - const SymbolBody &S) const; + const Symbol &S) const; // Return true if we can reach Dst from Src with Relocation RelocType virtual bool inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const; - virtual RelExpr getRelExpr(RelType Type, const SymbolBody &S, + virtual RelExpr getRelExpr(RelType Type, const Symbol &S, const uint8_t *Loc) const = 0; virtual void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const = 0; Index: lld/trunk/ELF/Target.cpp =================================================================== --- lld/trunk/ELF/Target.cpp +++ lld/trunk/ELF/Target.cpp @@ -124,7 +124,7 @@ bool TargetInfo::usesOnlyLowPageBits(RelType Type) const { return false; } bool TargetInfo::needsThunk(RelExpr Expr, RelType Type, const InputFile *File, - uint64_t BranchAddr, const SymbolBody &S) const { + uint64_t BranchAddr, const Symbol &S) const { return false; } @@ -132,7 +132,7 @@ return true; } -void TargetInfo::writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const { +void TargetInfo::writeIgotPlt(uint8_t *Buf, const Symbol &S) const { writeGotPlt(Buf, S); } Index: lld/trunk/ELF/Thunks.h =================================================================== --- lld/trunk/ELF/Thunks.h +++ lld/trunk/ELF/Thunks.h @@ -14,7 +14,7 @@ namespace lld { namespace elf { -class SymbolBody; +class Symbol; class ThunkSection; // Class to describe an instance of a Thunk. // A Thunk is a code-sequence inserted by the linker in between a caller and @@ -27,7 +27,7 @@ // Thunks are assigned to synthetic ThunkSections class Thunk { public: - Thunk(SymbolBody &Destination); + Thunk(Symbol &Destination); virtual ~Thunk(); virtual uint32_t size() const { return 0; } @@ -47,15 +47,15 @@ // The alignment requirement for this Thunk, defaults to the size of the // typical code section alignment. - SymbolBody &Destination; - SymbolBody *ThunkSym; + Symbol &Destination; + Symbol *ThunkSym; uint64_t Offset = 0; uint32_t Alignment = 4; }; // For a Relocation to symbol S create a Thunk to be added to a synthetic // ThunkSection. At present there are implementations for ARM and Mips Thunks. -Thunk *addThunk(RelType Type, SymbolBody &S); +Thunk *addThunk(RelType Type, Symbol &S); } // namespace elf } // namespace lld Index: lld/trunk/ELF/Thunks.cpp =================================================================== --- lld/trunk/ELF/Thunks.cpp +++ lld/trunk/ELF/Thunks.cpp @@ -52,7 +52,7 @@ // Source State, TargetState, Target Requirement, ABS or PI, Range class ARMV7ABSLongThunk final : public Thunk { public: - ARMV7ABSLongThunk(SymbolBody &Dest) : Thunk(Dest) {} + ARMV7ABSLongThunk(Symbol &Dest) : Thunk(Dest) {} uint32_t size() const override { return 12; } void writeTo(uint8_t *Buf, ThunkSection &IS) const override; @@ -62,7 +62,7 @@ class ARMV7PILongThunk final : public Thunk { public: - ARMV7PILongThunk(SymbolBody &Dest) : Thunk(Dest) {} + ARMV7PILongThunk(Symbol &Dest) : Thunk(Dest) {} uint32_t size() const override { return 16; } void writeTo(uint8_t *Buf, ThunkSection &IS) const override; @@ -72,7 +72,7 @@ class ThumbV7ABSLongThunk final : public Thunk { public: - ThumbV7ABSLongThunk(SymbolBody &Dest) : Thunk(Dest) { Alignment = 2; } + ThumbV7ABSLongThunk(Symbol &Dest) : Thunk(Dest) { Alignment = 2; } uint32_t size() const override { return 10; } void writeTo(uint8_t *Buf, ThunkSection &IS) const override; @@ -82,7 +82,7 @@ class ThumbV7PILongThunk final : public Thunk { public: - ThumbV7PILongThunk(SymbolBody &Dest) : Thunk(Dest) { Alignment = 2; } + ThumbV7PILongThunk(Symbol &Dest) : Thunk(Dest) { Alignment = 2; } uint32_t size() const override { return 12; } void writeTo(uint8_t *Buf, ThunkSection &IS) const override; @@ -93,7 +93,7 @@ // MIPS LA25 thunk class MipsThunk final : public Thunk { public: - MipsThunk(SymbolBody &Dest) : Thunk(Dest) {} + MipsThunk(Symbol &Dest) : Thunk(Dest) {} uint32_t size() const override { return 16; } void writeTo(uint8_t *Buf, ThunkSection &IS) const override; @@ -104,7 +104,7 @@ // microMIPS R2-R5 LA25 thunk class MicroMipsThunk final : public Thunk { public: - MicroMipsThunk(SymbolBody &Dest) : Thunk(Dest) {} + MicroMipsThunk(Symbol &Dest) : Thunk(Dest) {} uint32_t size() const override { return 14; } void writeTo(uint8_t *Buf, ThunkSection &IS) const override; @@ -115,7 +115,7 @@ // microMIPS R6 LA25 thunk class MicroMipsR6Thunk final : public Thunk { public: - MicroMipsR6Thunk(SymbolBody &Dest) : Thunk(Dest) {} + MicroMipsR6Thunk(Symbol &Dest) : Thunk(Dest) {} uint32_t size() const override { return 12; } void writeTo(uint8_t *Buf, ThunkSection &IS) const override; @@ -126,7 +126,7 @@ } // end anonymous namespace // ARM Target Thunks -static uint64_t getARMThunkDestVA(const SymbolBody &S) { +static uint64_t getARMThunkDestVA(const Symbol &S) { uint64_t V = S.isInPlt() ? S.getPltVA() : S.getVA(); return SignExtend64<32>(V); } @@ -305,12 +305,12 @@ return dyn_cast(DR->Section); } -Thunk::Thunk(SymbolBody &D) : Destination(D), Offset(0) {} +Thunk::Thunk(Symbol &D) : Destination(D), Offset(0) {} Thunk::~Thunk() = default; // Creates a thunk for Thumb-ARM interworking. -static Thunk *addThunkArm(RelType Reloc, SymbolBody &S) { +static Thunk *addThunkArm(RelType Reloc, Symbol &S) { // ARM relocations need ARM to Thumb interworking Thunks. // Thumb relocations need Thumb to ARM relocations. // Use position independent Thunks if we require position independent code. @@ -332,7 +332,7 @@ fatal("unrecognized relocation type"); } -static Thunk *addThunkMips(RelType Type, SymbolBody &S) { +static Thunk *addThunkMips(RelType Type, Symbol &S) { if ((S.StOther & STO_MIPS_MICROMIPS) && isMipsR6()) return make(S); if (S.StOther & STO_MIPS_MICROMIPS) @@ -340,7 +340,7 @@ return make(S); } -Thunk *addThunk(RelType Type, SymbolBody &S) { +Thunk *addThunk(RelType Type, Symbol &S) { if (Config->EMachine == EM_ARM) return addThunkArm(Type, S); else if (Config->EMachine == EM_MIPS) Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -399,7 +399,7 @@ } static bool shouldKeepInSymtab(SectionBase *Sec, StringRef SymName, - const SymbolBody &B) { + const Symbol &B) { if (B.isFile() || B.isSection()) return false; @@ -424,7 +424,7 @@ return !Sec || !(Sec->Flags & SHF_MERGE); } -static bool includeInSymtab(const SymbolBody &B) { +static bool includeInSymtab(const Symbol &B) { if (!B.isLocal() && !B.IsUsedInRegularObj) return false; @@ -454,7 +454,7 @@ return; for (InputFile *File : ObjectFiles) { ObjFile *F = cast>(File); - for (SymbolBody *B : F->getLocalSymbols()) { + for (Symbol *B : F->getLocalSymbols()) { if (!B->isLocal()) fatal(toString(F) + ": broken object: getLocalSymbols returns a non-local symbol"); @@ -740,12 +740,12 @@ static DefinedRegular * addOptionalRegular(StringRef Name, SectionBase *Sec, uint64_t Val, uint8_t StOther = STV_HIDDEN, uint8_t Binding = STB_GLOBAL) { - SymbolBody *S = Symtab->find(Name); + Symbol *S = Symtab->find(Name); if (!S || S->isInCurrentOutput()) return nullptr; - SymbolBody *Sym = Symtab->addRegular(Name, StOther, STT_NOTYPE, Val, - /*Size=*/0, Binding, Sec, - /*File=*/nullptr); + Symbol *Sym = Symtab->addRegular(Name, StOther, STT_NOTYPE, Val, + /*Size=*/0, Binding, Sec, + /*File=*/nullptr); return cast(Sym); } @@ -1182,7 +1182,7 @@ // Returns true if a symbol can be replaced at load-time by a symbol // with the same name defined in other ELF executable or DSO. -static bool computeIsPreemptible(const SymbolBody &B) { +static bool computeIsPreemptible(const Symbol &B) { assert(!B.isLocal()); // Only symbols that appear in dynsym can be preempted. if (!B.includeInDynsym()) @@ -1245,7 +1245,7 @@ applySynthetic({InX::EhFrame}, [](SyntheticSection *SS) { SS->finalizeContents(); }); - for (SymbolBody *S : Symtab->getSymbols()) + for (Symbol *S : Symtab->getSymbols()) S->IsPreemptible |= computeIsPreemptible(*S); // Scan relocations. This must be done after every symbol is declared so that @@ -1260,7 +1260,7 @@ // Now that we have defined all possible global symbols including linker- // synthesized ones. Visit all symbols to give the finishing touches. - for (SymbolBody *Sym : Symtab->getSymbols()) { + for (Symbol *Sym : Symtab->getSymbols()) { if (!includeInSymtab(*Sym)) continue; if (InX::SymTab) @@ -1715,7 +1715,7 @@ // 6. the address 0. template uint64_t Writer::getEntryAddr() { // Case 1, 2 or 3 - if (SymbolBody *B = Symtab->find(Config->Entry)) + if (Symbol *B = Symtab->find(Config->Entry)) return B->getVA(); // Case 4