Rename SymbolBody -> Symbol

Now that we have only SymbolBody as the symbol class. So, "SymbolBody"
is a bit strange name now. This is a mechanical change generated by

  perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF)

nd clang-format-diff.

Differential Revision: https://reviews.llvm.org/D39459

llvm-svn: 317370
This commit is contained in:
Rui Ueyama 2017-11-03 21:21:47 +00:00
parent e6b53dad42
commit f52496e1e0
55 changed files with 535 additions and 566 deletions

View File

@ -251,7 +251,7 @@ void SectionChunk::writeTo(uint8_t *Buf) const {
// 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<Defined>(Body);
Chunk *C = Sym->getChunk();
OutputSection *OS = C ? C->getOutputSection() : nullptr;
@ -328,7 +328,7 @@ void SectionChunk::getBaserels(std::vector<Baserel> *Res) {
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<DefinedAbsolute>(Body))
continue;
Res->emplace_back(RVA + Rel.VirtualAddress, Ty);

View File

@ -35,7 +35,7 @@ class DefinedImportData;
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 @@ class SectionChunk final : public Chunk {
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:
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);

View File

@ -27,7 +27,7 @@ using llvm::StringRef;
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 @@ static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
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 @@ struct Configuration {
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 @@ struct Configuration {
std::vector<llvm::StringRef> Argv;
// Symbols in this set are considered as live by the garbage collector.
std::set<SymbolBody *> GCRoot;
std::set<Symbol *> GCRoot;
std::set<StringRef> NoDefaultLibs;
bool NoDefaultLibAll = false;
@ -105,13 +105,13 @@ struct Configuration {
std::vector<Export> Exports;
std::set<std::string> DelayLoads;
std::map<std::string, int> 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;

View File

@ -353,8 +353,8 @@ void LinkerDriver::addLibSearchPaths() {
}
}
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 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
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<Undefined>(Sym))
@ -1237,7 +1237,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
Args.hasArg(OPT_export_all_symbols))) {
AutoExporter Exporter;
Symtab->forEachSymbol([=](SymbolBody *S) {
Symtab->forEachSymbol([=](Symbol *S) {
auto *Def = dyn_cast<Defined>(S);
if (!Exporter.shouldExport(Def))
return;
@ -1268,7 +1268,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
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;

View File

@ -96,7 +96,7 @@ private:
std::set<std::string> VisitedFiles;
std::set<std::string> VisitedLibs;
SymbolBody *addUndefined(StringRef Sym);
Symbol *addUndefined(StringRef Sym);
StringRef mangle(StringRef Sym);
// Windows specific -- "main" is not the only main function in Windows.

View File

@ -574,7 +574,7 @@ void fixupExports() {
}
for (Export &E : Config->Exports) {
SymbolBody *Sym = E.Sym;
Symbol *Sym = E.Sym;
if (!E.ForwardTo.empty() || !Sym) {
E.SymbolName = E.Name;
} else {

View File

@ -119,8 +119,8 @@ bool ICF::equalsConstant(const SectionChunk *A, const SectionChunk *B) {
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<DefinedRegular>(B1))
@ -143,8 +143,8 @@ bool ICF::equalsConstant(const SectionChunk *A, const SectionChunk *B) {
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<DefinedRegular>(B1))

View File

@ -51,7 +51,7 @@ std::vector<BitcodeFile *> BitcodeFile::Instances;
/// 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<Undefined>(Source)) {
if (U->WeakAlias && U->WeakAlias != Target)
Symtab->reportDuplicate(Source, F);
@ -175,7 +175,7 @@ void ObjFile::initializeSymbols() {
SymbolBodies.reserve(NumSymbols);
SparseSymbolBodies.resize(NumSymbols);
SmallVector<std::pair<SymbolBody *, uint32_t>, 8> WeakAliases;
SmallVector<std::pair<Symbol *, uint32_t>, 8> WeakAliases;
int32_t LastSectionNumber = 0;
for (uint32_t I = 0; I < NumSymbols; ++I) {
@ -186,7 +186,7 @@ void ObjFile::initializeSymbols() {
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 @@ void ObjFile::initializeSymbols() {
}
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<CommonChunk>(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 @@ SymbolBody *ObjFile::createDefined(COFFSymbolRef Sym, const void *AuxP,
DefinedRegular *B;
if (Sym.isExternal()) {
COFFObj->getSymbolName(Sym, Name);
SymbolBody *S =
Symbol *S =
Symtab->addRegular(this, Name, SC->isCOMDAT(), Sym.getGeneric(), SC);
B = cast<DefinedRegular>(S);
} else
@ -368,7 +368,7 @@ void BitcodeFile::parse() {
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 @@ void BitcodeFile::parse() {
// 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;

View File

@ -47,7 +47,7 @@ class DefinedImportData;
class DefinedImportThunk;
class Lazy;
class SectionChunk;
class SymbolBody;
class Symbol;
class Undefined;
// The root class of input files.
@ -110,11 +110,11 @@ public:
MachineTypes getMachineType() override;
std::vector<Chunk *> &getChunks() { return Chunks; }
std::vector<SectionChunk *> &getDebugChunks() { return DebugChunks; }
std::vector<SymbolBody *> &getSymbols() { return SymbolBodies; }
std::vector<Symbol *> &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 @@ public:
// The list of safe exception handlers listed in .sxdata section.
// COFF-specific and x86-only.
std::set<SymbolBody *> SEHandlers;
std::set<Symbol *> 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 @@ private:
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<COFFObjectFile> COFFObj;
const coff_section *SXData = nullptr;
@ -163,13 +163,13 @@ private:
std::vector<Chunk *> SparseChunks;
// List of all symbols referenced or defined by this file.
std::vector<SymbolBody *> SymbolBodies;
std::vector<Symbol *> 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<SymbolBody *> SparseSymbolBodies;
std::vector<Symbol *> SparseSymbolBodies;
};
// This type represents import library members that contain DLL names
@ -210,7 +210,7 @@ class BitcodeFile : public InputFile {
public:
explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}
static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
std::vector<SymbolBody *> &getSymbols() { return SymbolBodies; }
std::vector<Symbol *> &getSymbols() { return SymbolBodies; }
MachineTypes getMachineType() override;
static std::vector<BitcodeFile *> Instances;
std::unique_ptr<llvm::lto::InputFile> Obj;
@ -218,7 +218,7 @@ public:
private:
void parse() override;
std::vector<SymbolBody *> SymbolBodies;
std::vector<Symbol *> SymbolBodies;
};
} // namespace coff

View File

@ -88,17 +88,17 @@ BitcodeCompiler::BitcodeCompiler() : LTOObj(createLTO()) {}
BitcodeCompiler::~BitcodeCompiler() = default;
static void undefine(SymbolBody *S) { replaceBody<Undefined>(S, S->getName()); }
static void undefine(Symbol *S) { replaceBody<Undefined>(S, S->getName()); }
void BitcodeCompiler::add(BitcodeFile &F) {
lto::InputFile &Obj = *F.Obj;
unsigned SymNum = 0;
std::vector<SymbolBody *> SymBodies = F.getSymbols();
std::vector<Symbol *> SymBodies = F.getSymbols();
std::vector<lto::SymbolResolution> 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;

View File

@ -49,7 +49,7 @@ static std::string indent(int Depth) { return std::string(Depth * 8, ' '); }
static std::vector<DefinedRegular *> getSymbols() {
std::vector<DefinedRegular *> V;
for (ObjFile *File : ObjFile::Instances)
for (SymbolBody *B : File->getSymbols())
for (Symbol *B : File->getSymbols())
if (auto *Sym = dyn_cast<DefinedRegular>(B))
if (Sym && !Sym->getCOFFSymbol().isSectionDefinition())
V.push_back(Sym);

View File

@ -37,7 +37,7 @@ void markLive(const std::vector<Chunk *> &Chunks) {
Worklist.push_back(C);
};
auto AddSym = [&](SymbolBody *B) {
auto AddSym = [&](Symbol *B) {
if (auto *Sym = dyn_cast<DefinedRegular>(B))
Enqueue(Sym->getChunk());
else if (auto *Sym = dyn_cast<DefinedImportData>(B))
@ -47,7 +47,7 @@ void markLive(const std::vector<Chunk *> &Chunks) {
};
// Add GC root chunks.
for (SymbolBody *B : Config->GCRoot)
for (Symbol *B : Config->GCRoot)
AddSym(B);
while (!Worklist.empty()) {
@ -62,7 +62,7 @@ void markLive(const std::vector<Chunk *> &Chunks) {
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.

View File

@ -727,7 +727,7 @@ void PDBLinker::addObjectsToPDB() {
// Compute the public and global symbols.
auto &GsiBuilder = Builder.getGsiBuilder();
std::vector<PublicSym32> Publics;
Symtab->forEachSymbol([&Publics](SymbolBody *S) {
Symtab->forEachSymbol([&Publics](Symbol *S) {
// Only emit defined, live symbols that have a chunk.
auto *Def = dyn_cast<Defined>(S);
if (Def && Def->isLive() && Def->getChunk())

View File

@ -33,7 +33,7 @@ enum SymbolPreference {
/// 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<Defined>(S))
@ -92,10 +92,10 @@ static void errorOrWarn(const Twine &S) {
}
void SymbolTable::reportRemainingUndefines() {
SmallPtrSet<SymbolBody *, 8> Undefs;
SmallPtrSet<Symbol *, 8> Undefs;
for (auto &I : Symtab) {
SymbolBody *Sym = I.second;
Symbol *Sym = I.second;
auto *Undef = dyn_cast<Undefined>(Sym);
if (!Undef)
continue;
@ -123,7 +123,7 @@ void SymbolTable::reportRemainingUndefines() {
// 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<Defined>(Imp)) {
auto *D = cast<Defined>(Imp);
replaceBody<DefinedLocalImport>(Sym, Name, D);
@ -142,29 +142,29 @@ void SymbolTable::reportRemainingUndefines() {
if (Undefs.empty())
return;
for (SymbolBody *B : Config->GCRoot)
for (Symbol *B : Config->GCRoot)
if (Undefs.count(B))
errorOrWarn("<root>: 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<SymbolBody *, bool> SymbolTable::insert(StringRef Name) {
SymbolBody *&Sym = Symtab[CachedHashStringRef(Name)];
std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
Symbol *&Sym = Symtab[CachedHashStringRef(Name)];
if (Sym)
return {Sym, false};
Sym = (SymbolBody *)make<SymbolUnion>();
Sym = (Symbol *)make<SymbolUnion>();
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<BitcodeFile>(F))
@ -184,7 +184,7 @@ SymbolBody *SymbolTable::addUndefined(StringRef Name, InputFile *F,
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 @@ void SymbolTable::addLazy(ArchiveFile *F, const Archive::Symbol Sym) {
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 @@ SymbolBody *SymbolTable::addAbsolute(StringRef N, COFFSymbolRef Sym) {
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 @@ SymbolBody *SymbolTable::addAbsolute(StringRef N, uint64_t VA) {
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 @@ SymbolBody *SymbolTable::addSynthetic(StringRef N, Chunk *C) {
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<BitcodeFile>(F))
@ -263,10 +263,9 @@ SymbolBody *SymbolTable::addRegular(InputFile *F, StringRef N, bool IsCOMDAT,
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<BitcodeFile>(F))
@ -280,7 +279,7 @@ SymbolBody *SymbolTable::addCommon(InputFile *F, StringRef N, uint64_t Size,
}
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 @@ DefinedImportData *SymbolTable::addImportData(StringRef N, ImportFile *F) {
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 @@ std::vector<Chunk *> SymbolTable::getChunks() {
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::findByPrefix(StringRef Prefix) {
}
StringRef SymbolTable::findMangle(StringRef Name) {
if (SymbolBody *Sym = find(Name))
if (Symbol *Sym = find(Name))
if (!isa<Undefined>(Sym))
return Name;
if (Config->Machine != I386)
@ -364,7 +363,7 @@ StringRef SymbolTable::findMangle(StringRef Name) {
return findByPrefix(("?" + Name.substr(1) + "@@Y").str());
}
void SymbolTable::mangleMaybe(SymbolBody *B) {
void SymbolTable::mangleMaybe(Symbol *B) {
auto *U = dyn_cast<Undefined>(B);
if (!U || U->WeakAlias)
return;
@ -375,7 +374,7 @@ void SymbolTable::mangleMaybe(SymbolBody *B) {
}
}
SymbolBody *SymbolTable::addUndefined(StringRef Name) {
Symbol *SymbolTable::addUndefined(StringRef Name) {
return addUndefined(Name, nullptr, false);
}

View File

@ -31,7 +31,7 @@ class DefinedAbsolute;
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 @@ public:
std::vector<Chunk *> 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 @@ public:
std::vector<StringRef> 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<Chunk *> LocalImportChunks;
@ -105,10 +105,10 @@ public:
}
private:
std::pair<SymbolBody *, bool> insert(StringRef Name);
std::pair<Symbol *, bool> insert(StringRef Name);
StringRef findByPrefix(StringRef Prefix);
llvm::DenseMap<llvm::CachedHashStringRef, SymbolBody *> Symtab;
llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> Symtab;
std::unique_ptr<BitcodeCompiler> LTO;
};

View File

@ -20,7 +20,7 @@ using namespace llvm;
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<std::string> S = coff::demangle(B.getName()))
return ("\"" + *S + "\" (" + B.getName() + ")").str();
return B.getName();
@ -29,7 +29,7 @@ std::string lld::toString(coff::SymbolBody &B) {
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 @@ StringRef SymbolBody::getName() {
return Name;
}
InputFile *SymbolBody::getFile() {
InputFile *Symbol::getFile() {
if (auto *Sym = dyn_cast<DefinedCOFF>(this))
return Sym->File;
if (auto *Sym = dyn_cast<Lazy>(this))
@ -52,7 +52,7 @@ InputFile *SymbolBody::getFile() {
return nullptr;
}
bool SymbolBody::isLive() const {
bool Symbol::isLive() const {
if (auto *R = dyn_cast<DefinedRegular>(this))
return R->getChunk()->isLive();
if (auto *Imp = dyn_cast<DefinedImportData>(this))
@ -91,7 +91,7 @@ DefinedImportThunk::DefinedImportThunk(StringRef Name, DefinedImportData *S,
Defined *Undefined::getWeakAlias() {
// A weak alias may be a weak alias to another symbol, so check recursively.
for (SymbolBody *A = WeakAlias; A; A = cast<Undefined>(A)->WeakAlias)
for (Symbol *A = WeakAlias; A; A = cast<Undefined>(A)->WeakAlias)
if (auto *D = dyn_cast<Defined>(A))
return D;
return nullptr;

View File

@ -35,7 +35,7 @@ class ObjFile;
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 @@ public:
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 @@ protected:
// 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 @@ public:
// 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 @@ public:
this->IsCOMDAT = IsCOMDAT;
}
static bool classof(const SymbolBody *S) {
static bool classof(const Symbol *S) {
return S->kind() == DefinedRegularKind;
}
@ -179,7 +178,7 @@ public:
this->IsExternal = true;
}
static bool classof(const SymbolBody *S) {
static bool classof(const Symbol *S) {
return S->kind() == DefinedCommonKind;
}
@ -204,7 +203,7 @@ public:
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 @@ public:
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 @@ private:
// 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 @@ private:
};
// 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 @@ public:
: 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 @@ class DefinedImportThunk : public Defined {
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 @@ public:
DefinedLocalImport(StringRef N, Defined *S)
: Defined(DefinedLocalImportKind, N), Data(make<LocalImportChunk>(S)) {}
static bool classof(const SymbolBody *S) {
static bool classof(const Symbol *S) {
return S->kind() == DefinedLocalImportKind;
}
@ -399,7 +396,7 @@ inline Chunk *Defined::getChunk() {
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 @@ union SymbolUnion {
};
template <typename T, typename... ArgT>
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<SymbolBody *>(static_cast<T *>(nullptr)) == nullptr &&
"Not a SymbolBody");
assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
"Not a Symbol");
new (S) T(std::forward<ArgT>(Arg)...);
}
} // namespace coff
std::string toString(coff::SymbolBody &B);
std::string toString(coff::Symbol &B);
} // namespace lld
#endif

View File

@ -396,7 +396,7 @@ void Writer::createMiscChunks() {
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<DefinedRegular>(B);
@ -532,7 +532,7 @@ Optional<coff_symbol16> Writer::createSymbol(Defined *Def) {
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 @@ void Writer::createSymbolAndStringTable() {
}
for (ObjFile *File : ObjFile::Instances) {
for (SymbolBody *B : File->getSymbols()) {
for (Symbol *B : File->getSymbols()) {
auto *D = dyn_cast<Defined>(B);
if (!D || D->WrittenToSymtab)
continue;
@ -731,7 +731,7 @@ template <typename PEHeaderTy> void Writer::writeHeader() {
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<Defined>(Sym)) {
Dir[TLS_TABLE].RelativeVirtualAddress = B->getRVA();
Dir[TLS_TABLE].Size = Config->is64()
@ -743,7 +743,7 @@ template <typename PEHeaderTy> void Writer::writeHeader() {
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<DefinedRegular>(Sym)) {
SectionChunk *SC = B->getChunk();
assert(B->getRVA() >= SC->getRVA());
@ -804,8 +804,8 @@ void Writer::fixSafeSEHSymbols() {
// 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<DefinedSynthetic>(T, T->getName(), SEHTable);
cast<DefinedAbsolute>(C)->setVA(SEHTable->getSize() / 4);
}

View File

@ -32,10 +32,10 @@ namespace {
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 @@ AArch64::AArch64() {
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 @@ bool AArch64::isPicRel(RelType Type) const {
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());
}

View File

@ -27,7 +27,7 @@ public:
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 @@ void AMDGPU::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
}
}
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:

View File

@ -27,20 +27,20 @@ class ARM final : public TargetInfo {
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 @@ uint32_t ARM::calcEFlags() const {
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 @@ RelType ARM::getDynRel(RelType Type) const {
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 @@ void ARM::addPltSymbols(InputSectionBase *ISD, uint64_t Off) const {
}
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.

View File

@ -43,13 +43,13 @@ using namespace lld::elf;
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;
}

View File

@ -29,17 +29,17 @@ template <class ELFT> class MIPS final : public TargetInfo {
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 <class ELFT> uint32_t MIPS<ELFT>::calcEFlags() const {
}
template <class ELFT>
RelExpr MIPS<ELFT>::getRelExpr(RelType Type, const SymbolBody &S,
RelExpr MIPS<ELFT>::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 <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType Type) const {
}
template <class ELFT>
void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const SymbolBody &) const {
void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {
write32<ELFT::TargetEndianness>(Buf, InX::Plt->getVA());
}
@ -331,7 +331,7 @@ void MIPS<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,
template <class ELFT>
bool MIPS<ELFT>::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

View File

@ -23,12 +23,12 @@ class PPC final : public TargetInfo {
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:

View File

@ -39,7 +39,7 @@ namespace {
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 @@ PPC64::PPC64() {
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:

View File

@ -24,7 +24,7 @@ namespace {
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 @@ SPARCV9::SPARCV9() {
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:

View File

@ -24,13 +24,13 @@ namespace {
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 @@ X86::X86() {
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 @@ void X86::writeGotPltHeader(uint8_t *Buf) const {
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());
}

View File

@ -26,11 +26,11 @@ namespace {
template <class ELFT> 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 <class ELFT> X86_64<ELFT>::X86_64() {
}
template <class ELFT>
RelExpr X86_64<ELFT>::getRelExpr(RelType Type, const SymbolBody &S,
RelExpr X86_64<ELFT>::getRelExpr(RelType Type, const Symbol &S,
const uint8_t *Loc) const {
switch (Type) {
case R_X86_64_8:
@ -122,7 +122,7 @@ template <class ELFT> void X86_64<ELFT>::writeGotPltHeader(uint8_t *Buf) const {
}
template <class ELFT>
void X86_64<ELFT>::writeGotPlt(uint8_t *Buf, const SymbolBody &S) const {
void X86_64<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &S) const {
// See comments in X86::writeGotPlt.
write32le(Buf, S.getPltVA() + 6);
}

View File

@ -1001,7 +1001,7 @@ static void excludeLibs(opt::InputArgList &Args, ArrayRef<InputFile *> Files) {
for (InputFile *File : Files)
if (Optional<StringRef> 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;
}

View File

@ -68,7 +68,7 @@ LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
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<DefinedRegular>(B);
uint64_t Val = DR.Value + getAddend<ELFT>(Rel);

View File

@ -220,8 +220,8 @@ bool ICF<ELFT>::constantEq(const InputSection *SecA, ArrayRef<RelTy> RA,
uint64_t AddA = getAddend<ELFT>(RA[I]);
uint64_t AddB = getAddend<ELFT>(RB[I]);
SymbolBody &SA = SecA->template getFile<ELFT>()->getRelocTargetSym(RA[I]);
SymbolBody &SB = SecB->template getFile<ELFT>()->getRelocTargetSym(RB[I]);
Symbol &SA = SecA->template getFile<ELFT>()->getRelocTargetSym(RA[I]);
Symbol &SB = SecB->template getFile<ELFT>()->getRelocTargetSym(RB[I]);
if (&SA == &SB) {
if (AddA == AddB)
continue;
@ -295,8 +295,8 @@ bool ICF<ELFT>::variableEq(const InputSection *SecA, ArrayRef<RelTy> RA,
for (size_t I = 0; I < RA.size(); ++I) {
// The two sections must be identical.
SymbolBody &SA = SecA->template getFile<ELFT>()->getRelocTargetSym(RA[I]);
SymbolBody &SB = SecB->template getFile<ELFT>()->getRelocTargetSym(RB[I]);
Symbol &SA = SecA->template getFile<ELFT>()->getRelocTargetSym(RA[I]);
Symbol &SB = SecB->template getFile<ELFT>()->getRelocTargetSym(RB[I]);
if (&SA == &SB)
continue;

View File

@ -227,7 +227,7 @@ ObjFile<ELFT>::ObjFile(MemoryBufferRef M, StringRef ArchiveName)
this->ArchiveName = ArchiveName;
}
template <class ELFT> ArrayRef<SymbolBody *> ObjFile<ELFT>::getLocalSymbols() {
template <class ELFT> ArrayRef<Symbol *> ObjFile<ELFT>::getLocalSymbols() {
if (this->Symbols.empty())
return {};
return makeArrayRef(this->Symbols).slice(1, this->FirstNonLocal - 1);
@ -569,7 +569,7 @@ StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &Sec) {
template <class ELFT> void ObjFile<ELFT>::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 <class ELFT>
@ -584,8 +584,7 @@ InputSectionBase *ObjFile<ELFT>::getSection(uint32_t Index) const {
return nullptr;
}
template <class ELFT>
SymbolBody *ObjFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
template <class ELFT> Symbol *ObjFile<ELFT>::createSymbol(const Elf_Sym *Sym) {
int Binding = Sym->getBinding();
InputSectionBase *Sec = getSection(this->getSectionIndex(*Sym));
@ -905,9 +904,9 @@ static uint8_t mapVisibility(GlobalValue::VisibilityTypes GvVisibility) {
}
template <class ELFT>
static SymbolBody *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
const lto::InputFile::Symbol &ObjSym,
BitcodeFile *F) {
static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
const lto::InputFile::Symbol &ObjSym,
BitcodeFile *F) {
StringRef NameRef = Saver.save(ObjSym.getName());
uint32_t Binding = ObjSym.isWeak() ? STB_WEAK : STB_GLOBAL;

View File

@ -50,7 +50,7 @@ namespace elf {
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 @@ public:
// Returns object file symbols. It is a runtime error to call this
// function on files of other types.
ArrayRef<SymbolBody *> getSymbols() {
ArrayRef<Symbol *> getSymbols() {
assert(FileKind == ObjKind || FileKind == BitcodeKind ||
FileKind == ArchiveKind);
return Symbols;
@ -108,7 +108,7 @@ public:
protected:
InputFile(Kind K, MemoryBufferRef M);
std::vector<InputSectionBase *> Sections;
std::vector<SymbolBody *> Symbols;
std::vector<Symbol *> Symbols;
private:
const Kind FileKind;
@ -162,23 +162,22 @@ template <class ELFT> class ObjFile : public ELFFileBase<ELFT> {
public:
static bool classof(const InputFile *F) { return F->kind() == Base::ObjKind; }
ArrayRef<SymbolBody *> getLocalSymbols();
ArrayRef<Symbol *> getLocalSymbols();
ObjFile(MemoryBufferRef M, StringRef ArchiveName);
void parse(llvm::DenseSet<llvm::CachedHashStringRef> &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 <typename RelT>
SymbolBody &getRelocTargetSym(const RelT &Rel) const {
template <typename RelT> 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 @@ private:
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;

View File

@ -60,7 +60,7 @@ DenseMap<SectionBase *, int> elf::buildSectionOrder() {
// 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<DefinedRegular>(Body);
if (!D || !D->Section)
continue;
@ -250,7 +250,7 @@ std::string InputSectionBase::getLocation(uint64_t Offset) {
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<DefinedRegular>(B))
if (D->Section == this && D->Type == STT_FUNC)
if (D->Value <= Offset && Offset < D->Value + D->Size)
@ -276,8 +276,7 @@ static std::string createFileLineMsg(StringRef Path, unsigned Line) {
//
// Returns an empty string if there's no way to get line info.
template <class ELFT>
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<ELFT> *File = getFile<ELFT>();
if (!File)
@ -317,7 +316,7 @@ std::string InputSectionBase::getObjMsg(uint64_t Off) {
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<DefinedRegular>(B))
if (D->Section == this && D->Value <= Off && Off < D->Value + D->Size)
return Filename + ":(" + toString(*D) + ")" + Archive;
@ -381,7 +380,7 @@ void InputSection::copyRelocations(uint8_t *Buf, ArrayRef<RelTy> Rels) {
for (const RelTy &Rel : Rels) {
RelType Type = Rel.getType(Config->IsMips64EL);
SymbolBody &Body = this->getFile<ELFT>()->getRelocTargetSym(Rel);
Symbol &Body = this->getFile<ELFT>()->getRelocTargetSym(Rel);
auto *P = reinterpret_cast<typename ELFT::Rela *>(Buf);
Buf += sizeof(RelTy);
@ -489,7 +488,7 @@ static uint64_t getAArch64UndefinedRelativeWeakVA(uint64_t Type, uint64_t A,
// 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 getARMStaticBase(const SymbolBody &Body) {
}
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 @@ void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {
if (!RelTy::IsRela)
Addend += Target->getImplicitAddend(BufLoc, Type);
SymbolBody &Sym = this->getFile<ELFT>()->getRelocTargetSym(Rel);
Symbol &Sym = this->getFile<ELFT>()->getRelocTargetSym(Rel);
RelExpr Expr = Target->getRelExpr(Type, Sym, BufLoc);
if (Expr == R_NONE)
continue;
@ -1013,13 +1012,13 @@ template std::string InputSectionBase::getLocation<ELF32BE>(uint64_t);
template std::string InputSectionBase::getLocation<ELF64LE>(uint64_t);
template std::string InputSectionBase::getLocation<ELF64BE>(uint64_t);
template std::string InputSectionBase::getSrcMsg<ELF32LE>(const SymbolBody &,
template std::string InputSectionBase::getSrcMsg<ELF32LE>(const Symbol &,
uint64_t);
template std::string InputSectionBase::getSrcMsg<ELF32BE>(const SymbolBody &,
template std::string InputSectionBase::getSrcMsg<ELF32BE>(const Symbol &,
uint64_t);
template std::string InputSectionBase::getSrcMsg<ELF64LE>(const SymbolBody &,
template std::string InputSectionBase::getSrcMsg<ELF64LE>(const Symbol &,
uint64_t);
template std::string InputSectionBase::getSrcMsg<ELF64BE>(const SymbolBody &,
template std::string InputSectionBase::getSrcMsg<ELF64BE>(const Symbol &,
uint64_t);
template void InputSection::writeTo<ELF32LE>(uint8_t *);

View File

@ -25,7 +25,7 @@ namespace lld {
namespace elf {
class DefinedCommon;
class SymbolBody;
class Symbol;
struct SectionPiece;
class DefinedRegular;
@ -177,7 +177,8 @@ public:
// Returns a source location string. Used to construct an error message.
template <class ELFT> std::string getLocation(uint64_t Offset);
template <class ELFT> std::string getSrcMsg(const SymbolBody &Sym, uint64_t Offset);
template <class ELFT>
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

View File

@ -108,7 +108,7 @@ static std::unique_ptr<lto::LTO> createLTO() {
}
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() : LTOObj(createLTO()) {
BitcodeCompiler::~BitcodeCompiler() = default;
static void undefine(SymbolBody *S) {
static void undefine(Symbol *S) {
replaceBody<Undefined>(S, nullptr, S->getName(), /*IsLocal=*/false,
STV_DEFAULT, S->Type);
}
@ -126,7 +126,7 @@ static void undefine(SymbolBody *S) {
void BitcodeCompiler::add(BitcodeFile &F) {
lto::InputFile &Obj = *F.Obj;
unsigned SymNum = 0;
std::vector<SymbolBody *> Syms = F.getSymbols();
std::vector<Symbol *> Syms = F.getSymbols();
std::vector<lto::SymbolResolution> Resols(Syms.size());
DenseSet<StringRef> ScriptSymbols;
@ -136,7 +136,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
// 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;

View File

@ -122,12 +122,12 @@ void LinkerScript::addSymbol(SymbolAssignment *Cmd) {
// 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,

View File

@ -30,7 +30,7 @@ namespace lld {
namespace elf {
class DefinedRegular;
class SymbolBody;
class Symbol;
class InputSectionBase;
class InputSection;
class OutputSection;

View File

@ -50,7 +50,7 @@ static std::string indent(int Depth) { return std::string(Depth * 8, ' '); }
static std::vector<Defined *> getSymbols() {
std::vector<Defined *> V;
for (InputFile *File : ObjectFiles)
for (SymbolBody *B : File->getSymbols())
for (Symbol *B : File->getSymbols())
if (auto *DR = dyn_cast<DefinedRegular>(B))
if (DR->getFile() == File && !DR->isSection() && DR->Section &&
DR->Section->Live)

View File

@ -62,7 +62,7 @@ static DenseMap<StringRef, std::vector<InputSectionBase *>> CNamedSections;
template <class ELFT, class RelT>
static void resolveReloc(InputSectionBase &Sec, RelT &Rel,
std::function<void(InputSectionBase *, uint64_t)> Fn) {
SymbolBody &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
Symbol &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
if (auto *D = dyn_cast<DefinedRegular>(&B)) {
if (!D->Section)
@ -211,7 +211,7 @@ template <class ELFT> static void doGcSections() {
Q.push_back(S);
};
auto MarkSymbol = [&](SymbolBody *Sym) {
auto MarkSymbol = [&](Symbol *Sym) {
if (auto *D = dyn_cast_or_null<DefinedRegular>(Sym))
if (auto *IS = cast_or_null<InputSectionBase>(D->Section))
Enqueue(IS, D->Value);
@ -228,7 +228,7 @@ template <class ELFT> static void doGcSections() {
// 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);

View File

@ -425,7 +425,7 @@ static void finalizeShtGroup(OutputSection *OS,
// sh_info then contain index of an entry in symbol table section which
// provides signature of the section group.
ObjFile<ELFT> *Obj = Sections[0]->getFile<ELFT>();
ArrayRef<SymbolBody *> Symbols = Obj->getSymbols();
ArrayRef<Symbol *> Symbols = Obj->getSymbols();
OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info]);
}

View File

@ -23,7 +23,7 @@ namespace lld {
namespace elf {
struct PhdrEntry;
class SymbolBody;
class Symbol;
struct EhSectionPiece;
class EhInputSection;
class InputSection;

View File

@ -70,7 +70,7 @@ using namespace lld::elf;
// >>> referenced by bar.c:12 (/home/alice/src/bar.c:12)
// >>> /home/alice/src/bar.o:(.text+0x1)
template <class ELFT>
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 @@ static bool isMipsGprel(RelType Type) {
// Mips has a custom MipsGotSection that handles the writing of GOT entries
// without dynamic relocations.
template <class ELFT>
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 @@ static unsigned handleMipsTlsRelocation(RelType Type, SymbolBody &Body,
// GOT[e0] Module Index (Used to find pointer to TLS block at run-time)
// GOT[e1] Offset of symbol in TLS block
template <class ELFT>
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 @@ static unsigned handleARMTlsRelocation(RelType Type, SymbolBody &Body,
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<ELFT>::RelaDyn->addReloc({Type, InX::Got, Off, false, Dest, 0});
else
@ -197,7 +196,7 @@ static unsigned handleARMTlsRelocation(RelType Type, SymbolBody &Body,
// Returns the number of relocations processed.
template <class ELFT>
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 @@ static RelType getMipsPairType(RelType Type, bool IsLocal) {
// 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<DefinedRegular>(&Body))
@ -334,7 +333,7 @@ static bool isAbsolute(const SymbolBody &Body) {
return false;
}
static bool isAbsoluteValue(const SymbolBody &Body) {
static bool isAbsoluteValue(const Symbol &Body) {
return isAbsolute(Body) || Body.isTls();
}
@ -370,8 +369,8 @@ static bool isRelExpr(RelExpr Expr) {
// dynamic relocation so that the relocation will be fixed at load-time.
template <class ELFT>
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 (isRelExprOneOf<R_SIZE, R_GOT_FROM_END, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE,
R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_MIPS_GOT_GP_PC,
@ -473,7 +472,7 @@ static std::vector<SharedSymbol *> getSymbolsAt(SharedSymbol *SS) {
S.st_value != SS->Value)
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<SharedSymbol>(Sym))
Ret.push_back(Alias);
}
@ -558,7 +557,7 @@ static void errorOrWarn(const Twine &Msg) {
}
template <class ELFT>
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 @@ static int64_t computeAddend(const RelTy &Rel, const RelTy *End,
// Report an undefined symbol if necessary.
// Returns true if this function printed out an error message.
template <class ELFT>
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 @@ private:
template <class ELFT, class GotPltSection>
static void addPltEntry(PltSection *Plt, GotPltSection *GotPlt,
RelocationSection<ELFT> *Rel, RelType Type,
SymbolBody &Sym, bool UseSymVA) {
RelocationSection<ELFT> *Rel, RelType Type, Symbol &Sym,
bool UseSymVA) {
Plt->addEntry<ELFT>(Sym);
GotPlt->addEntry(Sym);
Rel->addReloc({Type, GotPlt, Sym.getGotPltOffset(), UseSymVA, &Sym, 0});
}
template <class ELFT>
static void addGotEntry(SymbolBody &Sym, bool Preemptible) {
template <class ELFT> static void addGotEntry(Symbol &Sym, bool Preemptible) {
InX::Got->addEntry(Sym);
RelExpr Expr = Sym.isTls() ? R_TLS : R_ABS;
@ -873,7 +871,7 @@ static void scanRelocs(InputSectionBase &Sec, ArrayRef<RelTy> Rels) {
for (auto I = Rels.begin(), End = Rels.end(); I != End; ++I) {
const RelTy &Rel = *I;
SymbolBody &Body = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
Symbol &Body = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
RelType Type = Rel.getType(Config->IsMips64EL);
// Deal with MIPS oddity.
@ -1281,7 +1279,7 @@ ThunkSection *ThunkCreator::addThunkSection(OutputSection *OS,
return TS;
}
std::pair<Thunk *, bool> ThunkCreator::getThunk(SymbolBody &Body, RelType Type,
std::pair<Thunk *, bool> ThunkCreator::getThunk(Symbol &Body, RelType Type,
uint64_t Src) {
auto Res = ThunkedSymbols.insert({&Body, std::vector<Thunk *>()});
if (!Res.second) {

View File

@ -17,7 +17,7 @@
namespace lld {
namespace elf {
class SymbolBody;
class Symbol;
class InputSection;
class InputSectionBase;
class OutputSection;
@ -118,7 +118,7 @@ struct Relocation {
RelType Type;
uint64_t Offset;
int64_t Addend;
SymbolBody *Sym;
Symbol *Sym;
};
template <class ELFT> void scanRelocations(InputSectionBase &);
@ -152,8 +152,7 @@ private:
ArrayRef<OutputSection *> OutputSections,
std::function<void(OutputSection *, InputSectionDescription *)> Fn);
std::pair<Thunk *, bool> getThunk(SymbolBody &Body, RelType Type,
uint64_t Src);
std::pair<Thunk *, bool> getThunk(Symbol &Body, RelType Type, uint64_t Src);
ThunkSection *addThunkSection(OutputSection *OS, InputSectionDescription *,
uint64_t Off);
@ -161,11 +160,11 @@ private:
bool normalizeExistingThunk(Relocation &Rel, uint64_t Src);
// Record all the available Thunks for a Symbol
llvm::DenseMap<SymbolBody *, std::vector<Thunk *>> ThunkedSymbols;
llvm::DenseMap<Symbol *, std::vector<Thunk *>> 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<SymbolBody *, Thunk *> Thunks;
llvm::DenseMap<Symbol *, Thunk *> Thunks;
// Track InputSections that have an inline ThunkSection placed in front
// an inline ThunkSection may have control fall through to the section below

View File

@ -136,8 +136,8 @@ template <class ELFT> void SymbolTable::addCombinedLTOObject() {
template <class ELFT>
DefinedRegular *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
uint8_t Binding) {
SymbolBody *Sym = addRegular<ELFT>(Name, Visibility, STT_NOTYPE, 0, 0,
Binding, nullptr, nullptr);
Symbol *Sym = addRegular<ELFT>(Name, Visibility, STT_NOTYPE, 0, 0, Binding,
nullptr, nullptr);
return cast<DefinedRegular>(Sym);
}
@ -150,11 +150,11 @@ void SymbolTable::trace(StringRef Name) {
// Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM.
// Used to implement --wrap.
template <class ELFT> void SymbolTable::addSymbolWrap(StringRef Name) {
SymbolBody *Sym = find(Name);
Symbol *Sym = find(Name);
if (!Sym)
return;
SymbolBody *Real = addUndefined<ELFT>(Saver.save("__real_" + Name));
SymbolBody *Wrap = addUndefined<ELFT>(Saver.save("__wrap_" + Name));
Symbol *Real = addUndefined<ELFT>(Saver.save("__real_" + Name));
Symbol *Wrap = addUndefined<ELFT>(Saver.save("__wrap_" + Name));
defsym(Real, Sym);
defsym(Sym, Wrap);
@ -165,7 +165,7 @@ template <class ELFT> void SymbolTable::addSymbolWrap(StringRef Name) {
// Creates alias for symbol. Used to implement --defsym=ALIAS=SYM.
template <class ELFT>
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 @@ void SymbolTable::applySymbolRenames() {
// __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<SymbolUnion>();
auto *NewSym = (Symbol *)make<SymbolUnion>();
memcpy(NewSym, Real, sizeof(SymbolUnion));
SymVector.push_back(NewSym);
}
@ -227,7 +227,7 @@ static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
}
// Find an existing symbol or create and insert a new one.
std::pair<SymbolBody *, bool> SymbolTable::insert(StringRef Name) {
std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
// <name>@@<version> means the symbol is the default version. In that
// case <name>@@<version> will be used to resolve references to <name>.
//
@ -248,9 +248,9 @@ std::pair<SymbolBody *, bool> SymbolTable::insert(StringRef Name) {
V = SymIndex((int)SymVector.size(), true);
}
SymbolBody *Sym;
Symbol *Sym;
if (IsNew) {
Sym = (SymbolBody *)make<SymbolUnion>();
Sym = (Symbol *)make<SymbolUnion>();
Sym->InVersionScript = false;
Sym->Binding = STB_WEAK;
Sym->Visibility = STV_DEFAULT;
@ -268,11 +268,11 @@ std::pair<SymbolBody *, bool> SymbolTable::insert(StringRef Name) {
// Find an existing symbol or create and insert a new one, then apply the given
// attributes.
std::pair<SymbolBody *, bool> SymbolTable::insert(StringRef Name, uint8_t Type,
uint8_t Visibility,
bool CanOmitFromDynSym,
InputFile *File) {
SymbolBody *S;
std::pair<Symbol *, bool> 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 @@ std::pair<SymbolBody *, bool> SymbolTable::insert(StringRef Name, uint8_t Type,
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 @@ std::pair<SymbolBody *, bool> SymbolTable::insert(StringRef Name, uint8_t Type,
return {S, WasInserted};
}
template <class ELFT> SymbolBody *SymbolTable::addUndefined(StringRef Name) {
template <class ELFT> Symbol *SymbolTable::addUndefined(StringRef Name) {
return addUndefined<ELFT>(Name, /*IsLocal=*/false, STB_GLOBAL, STV_DEFAULT,
/*Type*/ 0,
/*CanOmitFromDynSym*/ false, /*File*/ nullptr);
@ -303,11 +303,10 @@ template <class ELFT> SymbolBody *SymbolTable::addUndefined(StringRef Name) {
static uint8_t getVisibility(uint8_t StOther) { return StOther & 3; }
template <class ELFT>
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 @@ SymbolBody *SymbolTable::addUndefined(StringRef Name, bool IsLocal,
// 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 @@ static int compareVersion(SymbolBody *S, StringRef Name) {
// 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 @@ static int compareDefined(SymbolBody *S, bool WasInserted, uint8_t Binding,
// 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 @@ static int compareDefinedNonCommon(SymbolBody *S, bool WasInserted,
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 @@ static void warnOrError(const Twine &Msg) {
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 <class ELFT>
static void reportDuplicate(SymbolBody *Sym, InputSectionBase *ErrSec,
static void reportDuplicate(Symbol *Sym, InputSectionBase *ErrSec,
typename ELFT::uint ErrOffset) {
DefinedRegular *D = dyn_cast<DefinedRegular>(Sym);
if (!D || !D->Section || !ErrSec) {
@ -472,11 +470,10 @@ static void reportDuplicate(SymbolBody *Sym, InputSectionBase *ErrSec,
}
template <typename ELFT>
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 @@ void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> *File,
// 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 @@ void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> *File,
}
}
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 @@ SymbolBody *SymbolTable::addBitcode(StringRef Name, uint8_t Binding,
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 @@ SymbolBody *SymbolTable::find(StringRef Name) {
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 @@ void SymbolTable::defsym(SymbolBody *Dst, SymbolBody *Src) {
}
template <class ELFT>
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<LazyArchive>(S, F, Sym, SymbolBody::UnknownType);
replaceBody<LazyArchive>(S, F, Sym, Symbol::UnknownType);
return S;
}
if (!S->isUndefined())
@ -582,11 +579,11 @@ SymbolBody *SymbolTable::addLazyArchive(StringRef Name, ArchiveFile *F,
template <class ELFT>
void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
SymbolBody *S;
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(Name);
if (WasInserted) {
replaceBody<LazyObject>(S, &Obj, Name, SymbolBody::UnknownType);
replaceBody<LazyObject>(S, &Obj, Name, Symbol::UnknownType);
return;
}
if (!S->isUndefined())
@ -601,7 +598,7 @@ void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
// If we already saw this symbol, force loading its file.
template <class ELFT> 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 <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
template <class ELFT> void SymbolTable::scanShlibUndefined() {
for (InputFile *F : SharedFiles) {
for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
SymbolBody *Sym = find(U);
Symbol *Sym = find(U);
if (!Sym || !Sym->isDefined())
continue;
Sym->ExportDynamic = true;
@ -648,10 +645,10 @@ template <class ELFT> void SymbolTable::scanShlibUndefined() {
// 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<std::vector<SymbolBody *>> &SymbolTable::getDemangledSyms() {
StringMap<std::vector<Symbol *>> &SymbolTable::getDemangledSyms() {
if (!DemangledSyms) {
DemangledSyms.emplace();
for (SymbolBody *Sym : SymVector) {
for (Symbol *Sym : SymVector) {
if (!Sym->isInCurrentOutput())
continue;
if (Optional<std::string> S = demangle(Sym->getName()))
@ -663,17 +660,17 @@ StringMap<std::vector<SymbolBody *>> &SymbolTable::getDemangledSyms() {
return *DemangledSyms;
}
std::vector<SymbolBody *> SymbolTable::findByVersion(SymbolVersion Ver) {
std::vector<Symbol *> 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<SymbolBody *> SymbolTable::findAllByVersion(SymbolVersion Ver) {
std::vector<SymbolBody *> Res;
std::vector<Symbol *> SymbolTable::findAllByVersion(SymbolVersion Ver) {
std::vector<Symbol *> Res;
StringMatcher M(Ver.Name);
if (Ver.IsExternCpp) {
@ -683,7 +680,7 @@ std::vector<SymbolBody *> SymbolTable::findAllByVersion(SymbolVersion Ver) {
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 @@ void SymbolTable::handleAnonymousVersion() {
// Handles -dynamic-list.
void SymbolTable::handleDynamicList() {
for (SymbolVersion &Ver : Config->DynamicList) {
std::vector<SymbolBody *> Syms;
std::vector<Symbol *> 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 @@ void SymbolTable::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
return;
// Get a list of symbols which we need to assign the version to.
std::vector<SymbolBody *> Syms = findByVersion(Ver);
std::vector<Symbol *> Syms = findByVersion(Ver);
if (Syms.empty()) {
if (Config->NoUndefinedVersion)
error("version script assignment of '" + VersionName + "' to symbol '" +
@ -738,7 +735,7 @@ void SymbolTable::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
}
// 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 @@ void SymbolTable::assignWildcardVersion(SymbolVersion Ver, uint16_t VersionId) {
// 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 @@ void SymbolTable::scanVersionScript() {
// Symbol themselves might know their versions because symbols
// can contain versions in the form of <name>@<version>.
// 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<ELF32BE>(StringRef);
template void SymbolTable::addSymbolWrap<ELF64LE>(StringRef);
template void SymbolTable::addSymbolWrap<ELF64BE>(StringRef);
template SymbolBody *SymbolTable::addUndefined<ELF32LE>(StringRef);
template SymbolBody *SymbolTable::addUndefined<ELF32BE>(StringRef);
template SymbolBody *SymbolTable::addUndefined<ELF64LE>(StringRef);
template SymbolBody *SymbolTable::addUndefined<ELF64BE>(StringRef);
template Symbol *SymbolTable::addUndefined<ELF32LE>(StringRef);
template Symbol *SymbolTable::addUndefined<ELF32BE>(StringRef);
template Symbol *SymbolTable::addUndefined<ELF64LE>(StringRef);
template Symbol *SymbolTable::addUndefined<ELF64BE>(StringRef);
template SymbolBody *SymbolTable::addUndefined<ELF32LE>(StringRef, bool,
uint8_t, uint8_t,
uint8_t, bool,
InputFile *);
template SymbolBody *SymbolTable::addUndefined<ELF32BE>(StringRef, bool,
uint8_t, uint8_t,
uint8_t, bool,
InputFile *);
template SymbolBody *SymbolTable::addUndefined<ELF64LE>(StringRef, bool,
uint8_t, uint8_t,
uint8_t, bool,
InputFile *);
template SymbolBody *SymbolTable::addUndefined<ELF64BE>(StringRef, bool,
uint8_t, uint8_t,
uint8_t, bool,
InputFile *);
template Symbol *SymbolTable::addUndefined<ELF32LE>(StringRef, bool, uint8_t,
uint8_t, uint8_t, bool,
InputFile *);
template Symbol *SymbolTable::addUndefined<ELF32BE>(StringRef, bool, uint8_t,
uint8_t, uint8_t, bool,
InputFile *);
template Symbol *SymbolTable::addUndefined<ELF64LE>(StringRef, bool, uint8_t,
uint8_t, uint8_t, bool,
InputFile *);
template Symbol *SymbolTable::addUndefined<ELF64BE>(StringRef, bool, uint8_t,
uint8_t, uint8_t, bool,
InputFile *);
template void SymbolTable::addSymbolAlias<ELF32LE>(StringRef, StringRef);
template void SymbolTable::addSymbolAlias<ELF32BE>(StringRef, StringRef);
@ -833,18 +826,18 @@ template void SymbolTable::addCombinedLTOObject<ELF32BE>();
template void SymbolTable::addCombinedLTOObject<ELF64LE>();
template void SymbolTable::addCombinedLTOObject<ELF64BE>();
template SymbolBody *
SymbolTable::addRegular<ELF32LE>(StringRef, uint8_t, uint8_t, uint64_t,
uint64_t, uint8_t, SectionBase *, InputFile *);
template SymbolBody *
SymbolTable::addRegular<ELF32BE>(StringRef, uint8_t, uint8_t, uint64_t,
uint64_t, uint8_t, SectionBase *, InputFile *);
template SymbolBody *
SymbolTable::addRegular<ELF64LE>(StringRef, uint8_t, uint8_t, uint64_t,
uint64_t, uint8_t, SectionBase *, InputFile *);
template SymbolBody *
SymbolTable::addRegular<ELF64BE>(StringRef, uint8_t, uint8_t, uint64_t,
uint64_t, uint8_t, SectionBase *, InputFile *);
template Symbol *SymbolTable::addRegular<ELF32LE>(StringRef, uint8_t, uint8_t,
uint64_t, uint64_t, uint8_t,
SectionBase *, InputFile *);
template Symbol *SymbolTable::addRegular<ELF32BE>(StringRef, uint8_t, uint8_t,
uint64_t, uint64_t, uint8_t,
SectionBase *, InputFile *);
template Symbol *SymbolTable::addRegular<ELF64LE>(StringRef, uint8_t, uint8_t,
uint64_t, uint64_t, uint8_t,
SectionBase *, InputFile *);
template Symbol *SymbolTable::addRegular<ELF64BE>(StringRef, uint8_t, uint8_t,
uint64_t, uint64_t, uint8_t,
SectionBase *, InputFile *);
template DefinedRegular *SymbolTable::addAbsolute<ELF32LE>(StringRef, uint8_t,
uint8_t);
@ -855,16 +848,16 @@ template DefinedRegular *SymbolTable::addAbsolute<ELF64LE>(StringRef, uint8_t,
template DefinedRegular *SymbolTable::addAbsolute<ELF64BE>(StringRef, uint8_t,
uint8_t);
template SymbolBody *
template Symbol *
SymbolTable::addLazyArchive<ELF32LE>(StringRef, ArchiveFile *,
const object::Archive::Symbol);
template SymbolBody *
template Symbol *
SymbolTable::addLazyArchive<ELF32BE>(StringRef, ArchiveFile *,
const object::Archive::Symbol);
template SymbolBody *
template Symbol *
SymbolTable::addLazyArchive<ELF64LE>(StringRef, ArchiveFile *,
const object::Archive::Symbol);
template SymbolBody *
template Symbol *
SymbolTable::addLazyArchive<ELF64BE>(StringRef, ArchiveFile *,
const object::Archive::Symbol);

View File

@ -39,22 +39,22 @@ public:
template <class ELFT> void addSymbolWrap(StringRef Name);
void applySymbolRenames();
ArrayRef<SymbolBody *> getSymbols() const { return SymVector; }
ArrayRef<Symbol *> getSymbols() const { return SymVector; }
template <class ELFT>
DefinedRegular *addAbsolute(StringRef Name,
uint8_t Visibility = llvm::ELF::STV_HIDDEN,
uint8_t Binding = llvm::ELF::STB_GLOBAL);
template <class ELFT> SymbolBody *addUndefined(StringRef Name);
template <class ELFT> Symbol *addUndefined(StringRef Name);
template <class ELFT>
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 <class ELFT>
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 <class ELFT>
void addShared(StringRef Name, SharedFile<ELFT> *F,
@ -62,40 +62,39 @@ public:
const typename ELFT::Verdef *Verdef);
template <class ELFT>
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 <class ELFT> void addLazyObject(StringRef Name, LazyObjFile &Obj);
SymbolBody *addBitcode(StringRef Name, uint8_t Binding, uint8_t StOther,
uint8_t Type, bool CanOmitFromDynSym,
BitcodeFile *File);
Symbol *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);
Symbol *addCommon(StringRef Name, uint64_t Size, uint32_t Alignment,
uint8_t Binding, uint8_t StOther, uint8_t Type,
InputFile *File);
std::pair<SymbolBody *, bool> insert(StringRef Name);
std::pair<SymbolBody *, bool> insert(StringRef Name, uint8_t Type,
uint8_t Visibility,
bool CanOmitFromDynSym, InputFile *File);
std::pair<Symbol *, bool> insert(StringRef Name);
std::pair<Symbol *, bool> insert(StringRef Name, uint8_t Type,
uint8_t Visibility, bool CanOmitFromDynSym,
InputFile *File);
template <class ELFT> void fetchIfLazy(StringRef Name);
template <class ELFT> void scanShlibUndefined();
void scanVersionScript();
SymbolBody *find(StringRef Name);
Symbol *find(StringRef Name);
void trace(StringRef Name);
void handleDynamicList();
private:
std::vector<SymbolBody *> findByVersion(SymbolVersion Ver);
std::vector<SymbolBody *> findAllByVersion(SymbolVersion Ver);
void defsym(SymbolBody *Dst, SymbolBody *Src);
std::vector<Symbol *> findByVersion(SymbolVersion Ver);
std::vector<Symbol *> findAllByVersion(SymbolVersion Ver);
void defsym(Symbol *Dst, Symbol *Src);
llvm::StringMap<std::vector<SymbolBody *>> &getDemangledSyms();
llvm::StringMap<std::vector<Symbol *>> &getDemangledSyms();
void handleAnonymousVersion();
void assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
StringRef VersionName);
@ -115,7 +114,7 @@ private:
// FIXME: Experiment with passing in a custom hashing or sorting the symbols
// once symbol resolution is finished.
llvm::DenseMap<llvm::CachedHashStringRef, SymIndex> Symtab;
std::vector<SymbolBody *> SymVector;
std::vector<Symbol *> 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 @@ private:
// 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<llvm::StringMap<std::vector<SymbolBody *>>> DemangledSyms;
llvm::Optional<llvm::StringMap<std::vector<Symbol *>>> DemangledSyms;
struct SymbolRenaming {
SymbolBody *Dst;
SymbolBody *Src;
Symbol *Dst;
Symbol *Src;
uint8_t Binding;
};
@ -141,7 +140,7 @@ private:
std::vector<SymbolRenaming> Defsyms;
// For -wrap.
std::vector<std::pair<SymbolBody *, SymbolBody *>> WrapSymbols;
std::vector<std::pair<Symbol *, Symbol *>> WrapSymbols;
// For LTO.
std::unique_ptr<BitcodeCompiler> LTO;

View File

@ -40,9 +40,9 @@ DefinedRegular *ElfSym::MipsGp;
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<DefinedRegular>(Body);
SectionBase *IS = D.Section;
if (auto *ISB = dyn_cast_or_null<InputSectionBase>(IS))
@ -99,9 +99,9 @@ static uint64_t getSymVA(const SymbolBody &Body, int64_t &Addend) {
}
return VA;
}
case SymbolBody::DefinedCommonKind:
case Symbol::DefinedCommonKind:
llvm_unreachable("common are converted to bss");
case SymbolBody::SharedKind: {
case Symbol::SharedKind: {
auto &SS = cast<SharedSymbol>(Body);
if (SS.CopyRelSec)
return SS.CopyRelSec->getParent()->Addr + SS.CopyRelSec->OutSecOff;
@ -109,10 +109,10 @@ static uint64_t getSymVA(const SymbolBody &Body, int64_t &Addend) {
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 @@ static uint64_t getSymVA(const SymbolBody &Body, int64_t &Addend) {
}
// 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<DefinedRegular>(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<InputSectionBase>(Sec)->File : nullptr;
}
return File;
@ -139,8 +139,8 @@ InputFile *SymbolBody::getFile() const {
// 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 @@ void SymbolBody::copyFrom(SymbolBody *Other) {
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<DefinedCommon>(this))
return C->Size;
if (const auto *DR = dyn_cast<DefinedRegular>(this))
@ -193,7 +191,7 @@ uint64_t SymbolBody::getSize() const {
return 0;
}
OutputSection *SymbolBody::getOutputSection() const {
OutputSection *Symbol::getOutputSection() const {
if (auto *S = dyn_cast<DefinedRegular>(this)) {
if (S->Section)
return S->Section->getOutputSection();
@ -217,7 +215,7 @@ OutputSection *SymbolBody::getOutputSection() const {
// 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 @@ InputFile *Lazy::fetch() {
}
ArchiveFile *LazyArchive::getFile() {
return cast<ArchiveFile>(SymbolBody::getFile());
return cast<ArchiveFile>(Symbol::getFile());
}
InputFile *LazyArchive::fetch() {
@ -291,12 +289,12 @@ InputFile *LazyArchive::fetch() {
}
LazyObjFile *LazyObject::getFile() {
return cast<LazyObjFile>(SymbolBody::getFile());
return cast<LazyObjFile>(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 @@ uint8_t SymbolBody::computeBinding() const {
return Binding;
}
bool SymbolBody::includeInDynsym() const {
bool Symbol::includeInDynsym() const {
if (!Config->HasDynSymTab)
return false;
if (computeBinding() == STB_LOCAL)
@ -319,7 +317,7 @@ bool SymbolBody::includeInDynsym() const {
}
// 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 @@ void elf::printTraceSymbol(SymbolBody *Sym) {
}
// 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<std::string> S = demangle(B.getName()))
return *S;

View File

@ -35,7 +35,7 @@ class OutputSection;
template <class ELFT> class SharedFile;
// The base class for real symbol classes.
class SymbolBody {
class Symbol {
public:
enum Kind {
DefinedFirst,
@ -48,7 +48,7 @@ public:
LazyObjectKind,
};
SymbolBody(Kind K) : SymbolKind(K) {}
Symbol(Kind K) : SymbolKind(K) {}
Kind kind() const { return static_cast<Kind>(SymbolKind); }
// Symbol binding. This is not overwritten by replaceSymbol to track
@ -117,7 +117,7 @@ public:
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 @@ public:
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 @@ protected:
};
// 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 @@ public:
: 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 @@ public:
// Return true if the symbol is a PIC function.
template <class ELFT> bool isMipsPIC() const;
static bool classof(const SymbolBody *S) {
static bool classof(const Symbol *S) {
return S->kind() == DefinedRegularKind;
}
@ -240,19 +239,17 @@ public:
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 @@ public:
}
template <class ELFT> SharedFile<ELFT> *getFile() const {
return cast<SharedFile<ELFT>>(SymbolBody::getFile());
return cast<SharedFile<ELFT>>(Symbol::getFile());
}
template <class ELFT> uint32_t getAlignment() const;
@ -304,9 +301,9 @@ public:
// 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 @@ public:
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 @@ public:
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 @@ class LazyObject : public Lazy {
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 @@ struct ElfSym {
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 @@ union SymbolUnion {
alignas(LazyObject) char F[sizeof(LazyObject)];
};
void printTraceSymbol(SymbolBody *Sym);
void printTraceSymbol(Symbol *Sym);
template <typename T, typename... ArgT>
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<SymbolBody *>(static_cast<T *>(nullptr)) == nullptr &&
"Not a SymbolBody");
assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
"Not a Symbol");
SymbolBody Sym = *S;
Symbol Sym = *S;
new (S) T(std::forward<ArgT>(Arg)...);
S->File = File;
@ -423,7 +416,7 @@ void replaceBody(SymbolBody *S, InputFile *File, ArgT &&... Arg) {
}
} // namespace elf
std::string toString(const elf::SymbolBody &B);
std::string toString(const elf::Symbol &B);
} // namespace lld
#endif

View File

@ -66,7 +66,7 @@ uint64_t SyntheticSection::getVA() const {
// Create a .bss section for each common symbol and replace the common symbol
// with a DefinedRegular symbol.
template <class ELFT> void elf::createCommonSections() {
for (SymbolBody *S : Symtab->getSymbols()) {
for (Symbol *S : Symtab->getSymbols()) {
auto *Sym = dyn_cast<DefinedCommon>(S);
if (!Sym)
@ -296,8 +296,8 @@ InputSection *elf::createInterpSection() {
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<DefinedRegular>(Name, /*IsLocal*/ true, STV_DEFAULT, Type,
Value, Size, Section);
if (InX::SymTab)
@ -413,7 +413,7 @@ CieRecord *EhFrameSection::addCie(EhSectionPiece &Cie, ArrayRef<RelTy> Rels) {
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 @@ bool EhFrameSection::isFdeLive(EhSectionPiece &Fde, ArrayRef<RelTy> Rels) {
return false;
const RelTy &Rel = Rels[FirstRelI];
SymbolBody &B = Sec->template getFile<ELFT>()->getRelocTargetSym(Rel);
Symbol &B = Sec->template getFile<ELFT>()->getRelocTargetSym(Rel);
// FDEs for garbage-collected or merged-by-ICF sections are dead.
if (auto *D = dyn_cast<DefinedRegular>(&B))
@ -620,12 +620,12 @@ GotSection::GotSection()
: 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 @@ bool GotSection::addTlsIndex() {
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 @@ MipsGotSection::MipsGotSection()
: 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 @@ void MipsGotSection::addEntry(SymbolBody &Sym, int64_t Addend, RelExpr Expr) {
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 @@ void MipsGotSection::addEntry(SymbolBody &Sym, int64_t Addend, RelExpr Expr) {
}
}
bool MipsGotSection::addDynTlsEntry(SymbolBody &Sym) {
bool MipsGotSection::addDynTlsEntry(Symbol &Sym) {
if (Sym.GlobalDynIndex != -1U)
return false;
Sym.GlobalDynIndex = TlsEntries.size();
@ -768,7 +768,7 @@ static uint64_t getMipsPageCount(uint64_t Size) {
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 @@ uint64_t MipsGotSection::getPageEntryOffset(const SymbolBody &B,
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 @@ uint64_t MipsGotSection::getTlsOffset() const {
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 @@ void MipsGotSection::writeTo(uint8_t *Buf) {
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 @@ void MipsGotSection::writeTo(uint8_t *Buf) {
// 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 @@ GotPltSection::GotPltSection()
: 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 @@ size_t GotPltSection::getSize() const {
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 @@ IgotPltSection::IgotPltSection()
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 @@ size_t IgotPltSection::getSize() const {
}
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 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
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 @@ template <class ELFT> void DynamicSection<ELFT>::finalizeContents() {
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 @@ void SymbolTableBaseSection::postThunkContents() {
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 @@ void SymbolTableBaseSection::addSymbol(SymbolBody *B) {
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 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
auto *ESym = reinterpret_cast<Elf_Sym *>(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 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
auto *ESym = reinterpret_cast<Elf_Sym *>(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 @@ void GnuHashTableSection::addSymbols(std::vector<SymbolTableEntry> &V) {
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 @@ void HashTableSection::writeTo(uint8_t *Buf) {
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 @@ void PltSection::writeTo(uint8_t *Buf) {
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 @@ void PltSection::writeTo(uint8_t *Buf) {
}
}
template <class ELFT> void PltSection::addEntry(SymbolBody &Sym) {
template <class ELFT> void PltSection::addEntry(Symbol &Sym) {
Sym.PltIndex = Entries.size();
RelocationSection<ELFT> *PltRelocSection = In<ELFT>::RelaPlt;
if (HeaderSize == 0) {
@ -2638,10 +2638,10 @@ template void EhFrameSection::addSection<ELF32BE>(InputSectionBase *);
template void EhFrameSection::addSection<ELF64LE>(InputSectionBase *);
template void EhFrameSection::addSection<ELF64BE>(InputSectionBase *);
template void PltSection::addEntry<ELF32LE>(SymbolBody &Sym);
template void PltSection::addEntry<ELF32BE>(SymbolBody &Sym);
template void PltSection::addEntry<ELF64LE>(SymbolBody &Sym);
template void PltSection::addEntry<ELF64BE>(SymbolBody &Sym);
template void PltSection::addEntry<ELF32LE>(Symbol &Sym);
template void PltSection::addEntry<ELF32BE>(Symbol &Sym);
template void PltSection::addEntry<ELF64LE>(Symbol &Sym);
template void PltSection::addEntry<ELF64BE>(Symbol &Sym);
template void elf::createCommonSections<ELF32LE>();
template void elf::createCommonSections<ELF32BE>();

View File

@ -99,8 +99,7 @@ private:
std::vector<CieRecord *> CieRecords;
// CIE records are uniquified by their contents and personality functions.
llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord *>
CieMap;
llvm::DenseMap<std::pair<ArrayRef<uint8_t>, Symbol *>, CieRecord *> CieMap;
};
class GotSection : public SyntheticSection {
@ -111,11 +110,11 @@ public:
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 @@ public:
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 @@ private:
// to the first index of "Page" entries allocated for this section.
llvm::SmallMapVector<const OutputSection *, size_t, 16> PageIndexMap;
typedef std::pair<const SymbolBody *, uint64_t> GotEntry;
typedef std::pair<const Symbol *, uint64_t> GotEntry;
typedef std::vector<GotEntry> GotEntries;
// Map from Symbol-Addend pair to the GOT index.
llvm::DenseMap<GotEntry, size_t> EntryIndexMap;
@ -256,7 +255,7 @@ private:
GotEntries GlobalEntries;
// TLS entries.
std::vector<const SymbolBody *> TlsEntries;
std::vector<const Symbol *> TlsEntries;
uint32_t TlsIndexOff = -1;
uint64_t Size = 0;
@ -265,13 +264,13 @@ private:
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<const SymbolBody *> Entries;
std::vector<const Symbol *> Entries;
};
// The IgotPltSection is a Got associated with the PltSection for GNU Ifunc
@ -281,13 +280,13 @@ private:
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<const SymbolBody *> Entries;
std::vector<const Symbol *> Entries;
};
class StringTableSection final : public SyntheticSection {
@ -310,8 +309,7 @@ private:
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 @@ public:
uint32_t Type;
private:
SymbolBody *Sym;
Symbol *Sym;
const InputSectionBase *InputSec = nullptr;
uint64_t OffsetInSec;
bool UseSymVA;
@ -347,7 +345,7 @@ template <class ELFT> class DynamicSection final : public SyntheticSection {
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 @@ template <class ELFT> class DynamicSection final : public SyntheticSection {
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 @@ private:
};
struct SymbolTableEntry {
SymbolBody *Symbol;
Symbol *Symbol;
size_t StrTabOffset;
};
@ -433,9 +430,9 @@ public:
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<SymbolTableEntry> getSymbols() const { return Symbols; }
protected:
@ -445,7 +442,7 @@ protected:
StringTableSection &StrTabSec;
llvm::once_flag OnceFlag;
llvm::DenseMap<SymbolBody *, size_t> SymbolIndexMap;
llvm::DenseMap<Symbol *, size_t> SymbolIndexMap;
llvm::DenseMap<OutputSection *, size_t> SectionIndexMap;
};
@ -478,7 +475,7 @@ private:
void writeHashTable(uint8_t *Buf);
struct Entry {
SymbolBody *Body;
Symbol *Body;
size_t StrTabOffset;
uint32_t Hash;
};
@ -512,11 +509,11 @@ public:
bool empty() const override { return Entries.empty(); }
void addSymbols();
template <class ELFT> void addEntry(SymbolBody &Sym);
template <class ELFT> void addEntry(Symbol &Sym);
private:
unsigned getPltRelocOff() const;
std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
std::vector<std::pair<const Symbol *, unsigned>> Entries;
// Iplt always has HeaderSize of 0, the Plt HeaderSize is always non-zero
size_t HeaderSize;
};
@ -830,8 +827,8 @@ template <class ELFT> MergeInputSection *createCommentSection();
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 {

View File

@ -124,7 +124,7 @@ int64_t TargetInfo::getImplicitAddend(const uint8_t *Buf, RelType Type) const {
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 @@ bool TargetInfo::inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const {
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);
}

View File

@ -19,7 +19,7 @@ std::string toString(elf::RelType Type);
namespace elf {
class InputFile;
class SymbolBody;
class Symbol;
class TargetInfo {
public:
@ -27,8 +27,8 @@ public:
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 @@ public:
// 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;

View File

@ -52,7 +52,7 @@ namespace {
// 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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
// 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 @@ public:
// 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 @@ public:
// 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 @@ public:
} // 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 @@ InputSection *MicroMipsR6Thunk::getTargetInputSection() const {
return dyn_cast<InputSection>(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 @@ static Thunk *addThunkArm(RelType Reloc, SymbolBody &S) {
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<MicroMipsR6Thunk>(S);
if (S.StOther & STO_MIPS_MICROMIPS)
@ -340,7 +340,7 @@ static Thunk *addThunkMips(RelType Type, SymbolBody &S) {
return make<MipsThunk>(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)

View File

@ -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 @@ class ThunkSection;
// 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 @@ public:
// 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

View File

@ -399,7 +399,7 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
}
static bool shouldKeepInSymtab(SectionBase *Sec, StringRef SymName,
const SymbolBody &B) {
const Symbol &B) {
if (B.isFile() || B.isSection())
return false;
@ -424,7 +424,7 @@ static bool shouldKeepInSymtab(SectionBase *Sec, StringRef SymName,
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 @@ template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
return;
for (InputFile *File : ObjectFiles) {
ObjFile<ELFT> *F = cast<ObjFile<ELFT>>(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 @@ template <class ELFT>
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<ELFT>(Name, StOther, STT_NOTYPE, Val,
/*Size=*/0, Binding, Sec,
/*File=*/nullptr);
Symbol *Sym = Symtab->addRegular<ELFT>(Name, StOther, STT_NOTYPE, Val,
/*Size=*/0, Binding, Sec,
/*File=*/nullptr);
return cast<DefinedRegular>(Sym);
}
@ -1182,7 +1182,7 @@ static void removeUnusedSyntheticSections() {
// 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 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
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 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// 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 @@ template <class ELFT> void Writer<ELFT>::setPhdrs() {
// 6. the address 0.
template <class ELFT> uint64_t Writer<ELFT>::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