ELF: Merge DefinedRegular and Defined.

Now that DefinedRegular is the only remaining derived class of
Defined, we can merge the two classes.

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

llvm-svn: 317448
This commit is contained in:
Peter Collingbourne 2017-11-06 04:35:31 +00:00
parent 6c55a70838
commit e9a9e0a1e7
20 changed files with 111 additions and 127 deletions

View File

@ -346,7 +346,7 @@ bool MIPS<ELFT>::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,
// If current file has PIC code, LA25 stub is not required.
if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
return false;
auto *D = dyn_cast<DefinedRegular>(&S);
auto *D = dyn_cast<Defined>(&S);
// LA25 is required if target file has PIC code
// or target symbol is a PIC symbol.
return D && D->isMipsPIC<ELFT>();

View File

@ -67,7 +67,7 @@ LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
const typename ELFT::Sym &Sym = File->getELFSyms()[SymIndex];
uint32_t SecIndex = File->getSectionIndex(Sym);
Symbol &B = File->getRelocTargetSym(Rel);
auto &DR = cast<DefinedRegular>(B);
auto &DR = cast<Defined>(B);
uint64_t Val = DR.Value + getAddend<ELFT>(Rel);
// FIXME: We should be consistent about always adding the file

View File

@ -228,8 +228,8 @@ bool ICF<ELFT>::constantEq(const InputSection *SecA, ArrayRef<RelTy> RA,
return false;
}
auto *DA = dyn_cast<DefinedRegular>(&SA);
auto *DB = dyn_cast<DefinedRegular>(&SB);
auto *DA = dyn_cast<Defined>(&SA);
auto *DB = dyn_cast<Defined>(&SB);
if (!DA || !DB)
return false;
@ -300,8 +300,8 @@ bool ICF<ELFT>::variableEq(const InputSection *SecA, ArrayRef<RelTy> RA,
if (&SA == &SB)
continue;
auto *DA = cast<DefinedRegular>(&SA);
auto *DB = cast<DefinedRegular>(&SB);
auto *DA = cast<Defined>(&SA);
auto *DB = cast<Defined>(&SB);
// We already dealt with absolute and non-InputSection symbols in
// constantEq, and for InputSections we have already checked everything

View File

@ -600,8 +600,8 @@ template <class ELFT> Symbol *ObjFile<ELFT>::createSymbol(const Elf_Sym *Sym) {
if (Sym->st_shndx == SHN_UNDEF)
return make<Undefined>(Name, /*IsLocal=*/true, StOther, Type);
return make<DefinedRegular>(Name, /*IsLocal=*/true, StOther, Type, Value,
Size, Sec);
return make<Defined>(Name, /*IsLocal=*/true, StOther, Type, Value, Size,
Sec);
}
StringRef Name = check(Sym->getName(this->StringTable), toString(this));

View File

@ -61,7 +61,7 @@ DenseMap<SectionBase *, int> elf::buildSectionOrder() {
// Build a map from sections to their priorities.
for (InputFile *File : ObjectFiles) {
for (Symbol *Sym : File->getSymbols()) {
auto *D = dyn_cast<DefinedRegular>(Sym);
auto *D = dyn_cast<Defined>(Sym);
if (!D || !D->Section)
continue;
int &Priority = SectionOrder[D->Section];
@ -214,7 +214,7 @@ void InputSectionBase::maybeUncompress() {
this->Flags &= ~(uint64_t)SHF_COMPRESSED;
}
uint64_t SectionBase::getOffset(const DefinedRegular &Sym) const {
uint64_t SectionBase::getOffset(const Defined &Sym) const {
return getOffset(Sym.Value);
}
@ -251,7 +251,7 @@ std::string InputSectionBase::getLocation(uint64_t Offset) {
// Find a function symbol that encloses a given location.
for (Symbol *B : File->getSymbols())
if (auto *D = dyn_cast<DefinedRegular>(B))
if (auto *D = dyn_cast<Defined>(B))
if (D->Section == this && D->Type == STT_FUNC)
if (D->Value <= Offset && Offset < D->Value + D->Size)
return SrcFile + ":(function " + toString(*D) + ")";
@ -317,7 +317,7 @@ std::string InputSectionBase::getObjMsg(uint64_t Off) {
// Find a symbol that encloses a given location.
for (Symbol *B : File->getSymbols())
if (auto *D = dyn_cast<DefinedRegular>(B))
if (auto *D = dyn_cast<Defined>(B))
if (D->Section == this && D->Value <= Off && Off < D->Value + D->Size)
return Filename + ":(" + toString(*D) + ")" + Archive;
@ -404,7 +404,7 @@ void InputSection::copyRelocations(uint8_t *Buf, ArrayRef<RelTy> Rels) {
// avoid having to parse and recreate .eh_frame, we just replace any
// relocation in it pointing to discarded sections with R_*_NONE, which
// hopefully creates a frame that is ignored at runtime.
SectionBase *Section = cast<DefinedRegular>(Sym).Section;
SectionBase *Section = cast<Defined>(Sym).Section;
if (Section == &InputSection::Discarded) {
P->setSymbolAndType(0, 0, false);
continue;

View File

@ -27,7 +27,7 @@ namespace elf {
class Symbol;
struct SectionPiece;
class DefinedRegular;
class Defined;
class SyntheticSection;
class MergeSyntheticSection;
template <class ELFT> class ObjFile;
@ -73,7 +73,7 @@ public:
// section.
uint64_t getOffset(uint64_t Offset) const;
uint64_t getOffset(const DefinedRegular &Sym) const;
uint64_t getOffset(const Defined &Sym) const;
protected:
SectionBase(Kind SectionKind, StringRef Name, uint64_t Flags,

View File

@ -149,9 +149,9 @@ void LinkerScript::addSymbol(SymbolAssignment *Cmd) {
// write expressions like this: `alignment = 16; . = ALIGN(., alignment)`.
uint64_t SymValue = Value.Sec ? 0 : Value.getValue();
replaceSymbol<DefinedRegular>(Sym, nullptr, Cmd->Name, /*IsLocal=*/false,
Visibility, STT_NOTYPE, SymValue, 0, Sec);
Cmd->Sym = cast<DefinedRegular>(Sym);
replaceSymbol<Defined>(Sym, nullptr, Cmd->Name, /*IsLocal=*/false, Visibility,
STT_NOTYPE, SymValue, 0, Sec);
Cmd->Sym = cast<Defined>(Sym);
}
// This function is called from assignAddresses, while we are
@ -977,7 +977,7 @@ ExprValue LinkerScript::getSymbolValue(StringRef Name, const Twine &Loc) {
return 0;
}
if (auto *Sym = dyn_cast_or_null<DefinedRegular>(Symtab->find(Name)))
if (auto *Sym = dyn_cast_or_null<Defined>(Symtab->find(Name)))
return {Sym->Section, false, Sym->Value, Loc};
error(Loc + ": symbol not found: " + Name);

View File

@ -29,7 +29,7 @@
namespace lld {
namespace elf {
class DefinedRegular;
class Defined;
class Symbol;
class InputSectionBase;
class InputSection;
@ -96,7 +96,7 @@ struct SymbolAssignment : BaseCommand {
// The LHS of an expression. Name is either a symbol name or ".".
StringRef Name;
DefinedRegular *Sym = nullptr;
Defined *Sym = nullptr;
// The RHS of an expression.
Expr Expression;

View File

@ -51,7 +51,7 @@ static std::vector<Defined *> getSymbols() {
std::vector<Defined *> V;
for (InputFile *File : ObjectFiles)
for (Symbol *B : File->getSymbols())
if (auto *DR = dyn_cast<DefinedRegular>(B))
if (auto *DR = dyn_cast<Defined>(B))
if (DR->getFile() == File && !DR->isSection() && DR->Section &&
DR->Section->Live)
V.push_back(DR);
@ -62,7 +62,7 @@ static std::vector<Defined *> getSymbols() {
static SymbolMapTy getSectionSyms(ArrayRef<Defined *> Syms) {
SymbolMapTy Ret;
for (Defined *S : Syms)
if (auto *DR = dyn_cast<DefinedRegular>(S))
if (auto *DR = dyn_cast<Defined>(S))
Ret[DR->Section].push_back(S);
// Sort symbols by address. We want to print out symbols in the

View File

@ -64,7 +64,7 @@ static void resolveReloc(InputSectionBase &Sec, RelT &Rel,
std::function<void(InputSectionBase *, uint64_t)> Fn) {
Symbol &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
if (auto *D = dyn_cast<DefinedRegular>(&B)) {
if (auto *D = dyn_cast<Defined>(&B)) {
if (!D->Section)
return;
uint64_t Offset = D->Value;
@ -212,7 +212,7 @@ template <class ELFT> static void doGcSections() {
};
auto MarkSymbol = [&](Symbol *Sym) {
if (auto *D = dyn_cast_or_null<DefinedRegular>(Sym))
if (auto *D = dyn_cast_or_null<Defined>(Sym))
if (auto *IS = cast_or_null<InputSectionBase>(D->Section))
Enqueue(IS, D->Value);
};

View File

@ -33,7 +33,7 @@ class OutputSection;
template <class ELFT> class ObjFile;
template <class ELFT> class SharedFile;
class SharedSymbol;
class DefinedRegular;
class Defined;
// This represents a section in an output file.
// It is composed of multiple InputSections.

View File

@ -326,7 +326,7 @@ static RelType getMipsPairType(RelType Type, bool IsLocal) {
static bool isAbsolute(const Symbol &Sym) {
if (Sym.isUndefWeak())
return true;
if (const auto *DR = dyn_cast<DefinedRegular>(&Sym))
if (const auto *DR = dyn_cast<Defined>(&Sym))
return DR->Section == nullptr; // Absolute symbol.
return false;
}

View File

@ -135,11 +135,11 @@ template <class ELFT> void SymbolTable::addCombinedLTOObject() {
}
template <class ELFT>
DefinedRegular *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
uint8_t Binding) {
Defined *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
uint8_t Binding) {
Symbol *Sym = addRegular<ELFT>(Name, Visibility, STT_NOTYPE, 0, 0, Binding,
nullptr, nullptr);
return cast<DefinedRegular>(Sym);
return cast<Defined>(Sym);
}
// Set a flag for --trace-symbol so that we can print out a log message
@ -366,7 +366,7 @@ static int compareDefinedNonCommon(Symbol *S, bool WasInserted, uint8_t Binding,
S->Binding = Binding;
return Cmp;
}
if (auto *R = dyn_cast<DefinedRegular>(S)) {
if (auto *R = dyn_cast<Defined>(S)) {
if (R->Section && isa<BssSection>(R->Section)) {
// Non-common symbols take precedence over common symbols.
if (Config->WarnCommon)
@ -395,10 +395,10 @@ Symbol *SymbolTable::addCommon(StringRef N, uint64_t Size, uint32_t Alignment,
InputSections.push_back(Bss);
S->Binding = Binding;
replaceSymbol<DefinedRegular>(S, File, N, /*IsLocal=*/false, StOther, Type,
0, Size, Bss);
replaceSymbol<Defined>(S, File, N, /*IsLocal=*/false, StOther, Type, 0,
Size, Bss);
} else if (Cmp == 0) {
auto *D = cast<DefinedRegular>(S);
auto *D = cast<Defined>(S);
auto *Bss = dyn_cast_or_null<BssSection>(D->Section);
if (!Bss) {
// Non-common symbols take precedence over common symbols.
@ -435,7 +435,7 @@ static void reportDuplicate(Symbol *Sym, InputFile *NewFile) {
template <class ELFT>
static void reportDuplicate(Symbol *Sym, InputSectionBase *ErrSec,
typename ELFT::uint ErrOffset) {
DefinedRegular *D = dyn_cast<DefinedRegular>(Sym);
Defined *D = dyn_cast<Defined>(Sym);
if (!D || !D->Section || !ErrSec) {
reportDuplicate(Sym, ErrSec ? ErrSec->File : nullptr);
return;
@ -475,8 +475,8 @@ Symbol *SymbolTable::addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
int Cmp = compareDefinedNonCommon(S, WasInserted, Binding, Section == nullptr,
Value, Name);
if (Cmp > 0)
replaceSymbol<DefinedRegular>(S, File, Name, /*IsLocal=*/false, StOther,
Type, Value, Size, Section);
replaceSymbol<Defined>(S, File, Name, /*IsLocal=*/false, StOther, Type,
Value, Size, Section);
else if (Cmp == 0)
reportDuplicate<ELFT>(S, dyn_cast_or_null<InputSectionBase>(Section),
Value);
@ -519,8 +519,8 @@ Symbol *SymbolTable::addBitcode(StringRef Name, uint8_t Binding,
int Cmp = compareDefinedNonCommon(S, WasInserted, Binding,
/*IsAbs*/ false, /*Value*/ 0, Name);
if (Cmp > 0)
replaceSymbol<DefinedRegular>(S, F, Name, /*IsLocal=*/false, StOther, Type,
0, 0, nullptr);
replaceSymbol<Defined>(S, F, Name, /*IsLocal=*/false, StOther, Type, 0, 0,
nullptr);
else if (Cmp == 0)
reportDuplicate(S, F);
return S;
@ -818,14 +818,14 @@ 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);
template DefinedRegular *SymbolTable::addAbsolute<ELF32BE>(StringRef, uint8_t,
uint8_t);
template DefinedRegular *SymbolTable::addAbsolute<ELF64LE>(StringRef, uint8_t,
uint8_t);
template DefinedRegular *SymbolTable::addAbsolute<ELF64BE>(StringRef, uint8_t,
uint8_t);
template Defined *SymbolTable::addAbsolute<ELF32LE>(StringRef, uint8_t,
uint8_t);
template Defined *SymbolTable::addAbsolute<ELF32BE>(StringRef, uint8_t,
uint8_t);
template Defined *SymbolTable::addAbsolute<ELF64LE>(StringRef, uint8_t,
uint8_t);
template Defined *SymbolTable::addAbsolute<ELF64BE>(StringRef, uint8_t,
uint8_t);
template Symbol *
SymbolTable::addLazyArchive<ELF32LE>(StringRef, ArchiveFile *,

View File

@ -41,9 +41,9 @@ public:
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);
Defined *addAbsolute(StringRef Name,
uint8_t Visibility = llvm::ELF::STV_HIDDEN,
uint8_t Binding = llvm::ELF::STB_GLOBAL);
template <class ELFT> Symbol *addUndefined(StringRef Name);
template <class ELFT>

View File

@ -28,22 +28,22 @@ using namespace llvm::ELF;
using namespace lld;
using namespace lld::elf;
DefinedRegular *ElfSym::Bss;
DefinedRegular *ElfSym::Etext1;
DefinedRegular *ElfSym::Etext2;
DefinedRegular *ElfSym::Edata1;
DefinedRegular *ElfSym::Edata2;
DefinedRegular *ElfSym::End1;
DefinedRegular *ElfSym::End2;
DefinedRegular *ElfSym::GlobalOffsetTable;
DefinedRegular *ElfSym::MipsGp;
DefinedRegular *ElfSym::MipsGpDisp;
DefinedRegular *ElfSym::MipsLocalGp;
Defined *ElfSym::Bss;
Defined *ElfSym::Etext1;
Defined *ElfSym::Etext2;
Defined *ElfSym::Edata1;
Defined *ElfSym::Edata2;
Defined *ElfSym::End1;
Defined *ElfSym::End2;
Defined *ElfSym::GlobalOffsetTable;
Defined *ElfSym::MipsGp;
Defined *ElfSym::MipsGpDisp;
Defined *ElfSym::MipsLocalGp;
static uint64_t getSymVA(const Symbol &Sym, int64_t &Addend) {
switch (Sym.kind()) {
case Symbol::DefinedRegularKind: {
auto &D = cast<DefinedRegular>(Sym);
case Symbol::DefinedKind: {
auto &D = cast<Defined>(Sym);
SectionBase *IS = D.Section;
if (auto *ISB = dyn_cast_or_null<InputSectionBase>(IS))
IS = ISB->Repl;
@ -125,7 +125,7 @@ bool Symbol::isUndefWeak() const {
InputFile *Symbol::getFile() const {
if (isLocal()) {
const SectionBase *Sec = cast<DefinedRegular>(this)->Section;
const SectionBase *Sec = cast<Defined>(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
// Symbol, or having a special absolute section if needed.
@ -180,7 +180,7 @@ uint64_t Symbol::getPltVA() const {
}
uint64_t Symbol::getSize() const {
if (const auto *DR = dyn_cast<DefinedRegular>(this))
if (const auto *DR = dyn_cast<Defined>(this))
return DR->Size;
if (const auto *S = dyn_cast<SharedSymbol>(this))
return S->Size;
@ -188,7 +188,7 @@ uint64_t Symbol::getSize() const {
}
OutputSection *Symbol::getOutputSection() const {
if (auto *S = dyn_cast<DefinedRegular>(this)) {
if (auto *S = dyn_cast<Defined>(this)) {
if (S->Section)
return S->Section->getOutputSection();
return nullptr;
@ -247,7 +247,7 @@ void Symbol::parseSymbolVersion() {
Verstr);
}
template <class ELFT> bool DefinedRegular::isMipsPIC() const {
template <class ELFT> bool Defined::isMipsPIC() const {
typedef typename ELFT::Ehdr Elf_Ehdr;
if (!Section || !isFunc())
return false;
@ -315,7 +315,7 @@ void elf::printTraceSymbol(Symbol *Sym) {
S = ": lazy definition of ";
else if (Sym->isShared())
S = ": shared definition of ";
else if (dyn_cast_or_null<BssSection>(cast<DefinedRegular>(Sym)->Section))
else if (dyn_cast_or_null<BssSection>(cast<Defined>(Sym)->Section))
S = ": common definition of ";
else
S = ": definition of ";
@ -331,7 +331,7 @@ std::string lld::toString(const Symbol &B) {
return B.getName();
}
template bool DefinedRegular::template isMipsPIC<ELF32LE>() const;
template bool DefinedRegular::template isMipsPIC<ELF32BE>() const;
template bool DefinedRegular::template isMipsPIC<ELF64LE>() const;
template bool DefinedRegular::template isMipsPIC<ELF64BE>() const;
template bool Defined::template isMipsPIC<ELF32LE>() const;
template bool Defined::template isMipsPIC<ELF32BE>() const;
template bool Defined::template isMipsPIC<ELF64LE>() const;
template bool Defined::template isMipsPIC<ELF64BE>() const;

View File

@ -38,9 +38,7 @@ template <class ELFT> class SharedFile;
class Symbol {
public:
enum Kind {
DefinedFirst,
DefinedRegularKind = DefinedFirst,
DefinedLast = DefinedRegularKind,
DefinedKind,
SharedKind,
UndefinedKind,
LazyArchiveKind,
@ -95,7 +93,7 @@ public:
bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; }
bool isUndefined() const { return SymbolKind == UndefinedKind; }
bool isDefined() const { return SymbolKind <= DefinedLast; }
bool isDefined() const { return SymbolKind == DefinedKind; }
bool isShared() const { return SymbolKind == SharedKind; }
bool isLocal() const { return IsLocal; }
@ -103,9 +101,7 @@ public:
return SymbolKind == LazyArchiveKind || SymbolKind == LazyObjectKind;
}
bool isInCurrentOutput() const {
return SymbolKind == DefinedRegularKind;
}
bool isInCurrentOutput() const { return isDefined(); }
// True is this is an undefined weak symbol. This only works once
// all input files have been added.
@ -188,29 +184,18 @@ protected:
StringRefZ Name;
};
// The base class for any defined symbols.
// Represents a symbol that is defined in the current output file.
class Defined : public Symbol {
public:
Defined(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type)
: Symbol(K, Name, IsLocal, StOther, Type) {}
static bool classof(const Symbol *S) { return S->isDefined(); }
};
// Regular defined symbols read from object file symbol tables.
class DefinedRegular : public Defined {
public:
DefinedRegular(StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type,
uint64_t Value, uint64_t Size, SectionBase *Section)
: Defined(DefinedRegularKind, Name, IsLocal, StOther, Type), Value(Value),
Defined(StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type,
uint64_t Value, uint64_t Size, SectionBase *Section)
: Symbol(DefinedKind, Name, IsLocal, StOther, Type), Value(Value),
Size(Size), Section(Section) {}
// Return true if the symbol is a PIC function.
template <class ELFT> bool isMipsPIC() const;
static bool classof(const Symbol *S) {
return S->kind() == DefinedRegularKind;
}
static bool classof(const Symbol *S) { return S->isDefined(); }
uint64_t Value;
uint64_t Size;
@ -323,39 +308,39 @@ public:
};
// Some linker-generated symbols need to be created as
// DefinedRegular symbols.
// Defined symbols.
struct ElfSym {
// __bss_start
static DefinedRegular *Bss;
static Defined *Bss;
// etext and _etext
static DefinedRegular *Etext1;
static DefinedRegular *Etext2;
static Defined *Etext1;
static Defined *Etext2;
// edata and _edata
static DefinedRegular *Edata1;
static DefinedRegular *Edata2;
static Defined *Edata1;
static Defined *Edata2;
// end and _end
static DefinedRegular *End1;
static DefinedRegular *End2;
static Defined *End1;
static Defined *End2;
// The _GLOBAL_OFFSET_TABLE_ symbol is defined by target convention to
// be at some offset from the base of the .got section, usually 0 or
// the end of the .got.
static DefinedRegular *GlobalOffsetTable;
static Defined *GlobalOffsetTable;
// _gp, _gp_disp and __gnu_local_gp symbols. Only for MIPS.
static DefinedRegular *MipsGp;
static DefinedRegular *MipsGpDisp;
static DefinedRegular *MipsLocalGp;
static Defined *MipsGp;
static Defined *MipsGpDisp;
static Defined *MipsLocalGp;
};
// 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 {
alignas(DefinedRegular) char A[sizeof(DefinedRegular)];
alignas(Defined) char A[sizeof(Defined)];
alignas(Undefined) char C[sizeof(Undefined)];
alignas(SharedSymbol) char D[sizeof(SharedSymbol)];
alignas(LazyArchive) char E[sizeof(LazyArchive)];

View File

@ -275,8 +275,8 @@ InputSection *elf::createInterpSection() {
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);
auto *S = make<Defined>(Name, /*IsLocal*/ true, STV_DEFAULT, Type, Value,
Size, Section);
if (InX::SymTab)
InX::SymTab->addSymbol(S);
return S;
@ -428,7 +428,7 @@ bool EhFrameSection::isFdeLive(EhSectionPiece &Fde, ArrayRef<RelTy> Rels) {
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))
if (auto *D = dyn_cast<Defined>(&B))
if (auto *Sec = cast_or_null<InputSectionBase>(D->Section))
return Sec->Live && (Sec == Sec->Repl);
return false;
@ -1576,13 +1576,13 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
// Set a section index.
BssSection *CommonSec = nullptr;
if (!Config->DefineCommon)
if (auto *D = dyn_cast<DefinedRegular>(Sym))
if (auto *D = dyn_cast<Defined>(Sym))
CommonSec = dyn_cast_or_null<BssSection>(D->Section);
if (CommonSec)
ESym->st_shndx = SHN_COMMON;
else if (const OutputSection *OutSec = Sym->getOutputSection())
ESym->st_shndx = OutSec->SectionIndex;
else if (isa<DefinedRegular>(Sym))
else if (isa<Defined>(Sym))
ESym->st_shndx = SHN_ABS;
else
ESym->st_shndx = SHN_UNDEF;
@ -1621,7 +1621,7 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
ESym->st_other |= STO_MIPS_PLT;
if (Config->Relocatable)
if (auto *D = dyn_cast<DefinedRegular>(Sym))
if (auto *D = dyn_cast<Defined>(Sym))
if (D->isMipsPIC<ELFT>())
ESym->st_other |= STO_MIPS_PIC;
++ESym;

View File

@ -251,7 +251,7 @@ void MipsThunk::addSymbols(ThunkSection &IS) {
}
InputSection *MipsThunk::getTargetInputSection() const {
auto *DR = dyn_cast<DefinedRegular>(&Destination);
auto *DR = dyn_cast<Defined>(&Destination);
return dyn_cast<InputSection>(DR->Section);
}
@ -276,7 +276,7 @@ void MicroMipsThunk::addSymbols(ThunkSection &IS) {
}
InputSection *MicroMipsThunk::getTargetInputSection() const {
auto *DR = dyn_cast<DefinedRegular>(&Destination);
auto *DR = dyn_cast<Defined>(&Destination);
return dyn_cast<InputSection>(DR->Section);
}
@ -301,7 +301,7 @@ void MicroMipsR6Thunk::addSymbols(ThunkSection &IS) {
}
InputSection *MicroMipsR6Thunk::getTargetInputSection() const {
auto *DR = dyn_cast<DefinedRegular>(&Destination);
auto *DR = dyn_cast<Defined>(&Destination);
return dyn_cast<InputSection>(DR->Section);
}

View File

@ -23,7 +23,7 @@ class ThunkSection;
// include transferring control from non-pi to pi and changing state on
// targets like ARM.
//
// Thunks can be created for DefinedRegular, Shared and Undefined Symbols.
// Thunks can be created for Defined, Shared and Undefined Symbols.
// Thunks are assigned to synthetic ThunkSections
class Thunk {
public:

View File

@ -426,7 +426,7 @@ static bool includeInSymtab(const Symbol &B) {
if (!B.isLocal() && !B.IsUsedInRegularObj)
return false;
if (auto *D = dyn_cast<DefinedRegular>(&B)) {
if (auto *D = dyn_cast<Defined>(&B)) {
// Always include absolute symbols.
SectionBase *Sec = D->Section;
if (!Sec)
@ -456,7 +456,7 @@ template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
if (!B->isLocal())
fatal(toString(F) +
": broken object: getLocalSymbols returns a non-local symbol");
auto *DR = dyn_cast<DefinedRegular>(B);
auto *DR = dyn_cast<Defined>(B);
// No reason to keep local undefined symbol in symtab.
if (!DR)
@ -491,9 +491,8 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
IS->Type == SHT_RELA)
continue;
auto *Sym =
make<DefinedRegular>("", /*IsLocal=*/true, /*StOther=*/0, STT_SECTION,
/*Value=*/0, /*Size=*/0, IS);
auto *Sym = make<Defined>("", /*IsLocal=*/true, /*StOther=*/0, STT_SECTION,
/*Value=*/0, /*Size=*/0, IS);
InX::SymTab->addSymbol(Sym);
}
}
@ -735,16 +734,16 @@ void PhdrEntry::add(OutputSection *Sec) {
}
template <class ELFT>
static DefinedRegular *
addOptionalRegular(StringRef Name, SectionBase *Sec, uint64_t Val,
uint8_t StOther = STV_HIDDEN, uint8_t Binding = STB_GLOBAL) {
static Defined *addOptionalRegular(StringRef Name, SectionBase *Sec,
uint64_t Val, uint8_t StOther = STV_HIDDEN,
uint8_t Binding = STB_GLOBAL) {
Symbol *S = Symtab->find(Name);
if (!S || S->isInCurrentOutput())
return nullptr;
Symbol *Sym = Symtab->addRegular<ELFT>(Name, StOther, STT_NOTYPE, Val,
/*Size=*/0, Binding, Sec,
/*File=*/nullptr);
return cast<DefinedRegular>(Sym);
return cast<Defined>(Sym);
}
// The beginning and the ending of .rel[a].plt section are marked