[lld] r321187 - Use a reference for the shared symbol file.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 20 08:28:19 PST 2017
Author: rafael
Date: Wed Dec 20 08:28:19 2017
New Revision: 321187
URL: http://llvm.org/viewvc/llvm-project?rev=321187&view=rev
Log:
Use a reference for the shared symbol file.
Every shared symbol has a file, so we can use a reference.
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/MarkLive.cpp
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/ELF/Symbols.h
lld/trunk/ELF/SyntheticSections.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=321187&r1=321186&r2=321187&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Dec 20 08:28:19 2017
@@ -841,14 +841,14 @@ template <class ELFT> void SharedFile<EL
error(toString(this) + ": alignment too large: " + Name);
if (!Hidden)
- Symtab->addShared(Name, this, Sym, Alignment, VersymIndex);
+ Symtab->addShared(Name, *this, Sym, Alignment, VersymIndex);
// Also add the symbol with the versioned name to handle undefined symbols
// with explicit versions.
if (Ver) {
StringRef VerName = this->StringTable.data() + Ver->getAux()->vda_name;
Name = Saver.save(Name + "@" + VerName);
- Symtab->addShared(Name, this, Sym, Alignment, VersymIndex);
+ Symtab->addShared(Name, *this, Sym, Alignment, VersymIndex);
}
}
}
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=321187&r1=321186&r2=321187&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Wed Dec 20 08:28:19 2017
@@ -68,7 +68,7 @@ static void resolveReloc(InputSectionBas
B.Used = true;
if (auto *SS = dyn_cast<SharedSymbol>(&B))
if (!SS->isWeak())
- SS->getFile<ELFT>()->IsNeeded = true;
+ SS->getFile<ELFT>().IsNeeded = true;
if (auto *D = dyn_cast<Defined>(&B)) {
auto *RelSec = dyn_cast_or_null<InputSectionBase>(D->Section);
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=321187&r1=321186&r2=321187&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Dec 20 08:28:19 2017
@@ -443,8 +443,8 @@ template <class ELFT> static bool isRead
typedef typename ELFT::Phdr Elf_Phdr;
// Determine if the symbol is read-only by scanning the DSO's program headers.
- const SharedFile<ELFT> *File = SS->getFile<ELFT>();
- for (const Elf_Phdr &Phdr : check(File->getObj().program_headers()))
+ const SharedFile<ELFT> &File = SS->getFile<ELFT>();
+ for (const Elf_Phdr &Phdr : check(File.getObj().program_headers()))
if ((Phdr.p_type == ELF::PT_LOAD || Phdr.p_type == ELF::PT_GNU_RELRO) &&
!(Phdr.p_flags & ELF::PF_W) && SS->Value >= Phdr.p_vaddr &&
SS->Value < Phdr.p_vaddr + Phdr.p_memsz)
@@ -461,14 +461,14 @@ template <class ELFT>
static std::vector<SharedSymbol *> getSymbolsAt(SharedSymbol *SS) {
typedef typename ELFT::Sym Elf_Sym;
- SharedFile<ELFT> *File = SS->getFile<ELFT>();
+ SharedFile<ELFT> &File = SS->getFile<ELFT>();
std::vector<SharedSymbol *> Ret;
- for (const Elf_Sym &S : File->getGlobalELFSyms()) {
+ for (const Elf_Sym &S : File.getGlobalELFSyms()) {
if (S.st_shndx == SHN_UNDEF || S.st_shndx == SHN_ABS ||
S.st_value != SS->Value)
continue;
- StringRef Name = check(S.getName(File->getStringTable()));
+ StringRef Name = check(S.getName(File.getStringTable()));
Symbol *Sym = Symtab->find(Name);
if (auto *Alias = dyn_cast_or_null<SharedSymbol>(Sym))
Ret.push_back(Alias);
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=321187&r1=321186&r2=321187&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Dec 20 08:28:19 2017
@@ -306,7 +306,7 @@ Symbol *SymbolTable::addUndefined(String
if (Binding != STB_WEAK) {
if (auto *SS = dyn_cast<SharedSymbol>(S))
if (!Config->GcSections)
- SS->getFile<ELFT>()->IsNeeded = true;
+ SS->getFile<ELFT>().IsNeeded = true;
}
if (auto *L = dyn_cast<Lazy>(S)) {
// An undefined weak will not fetch archive members. See comment on Lazy in
@@ -476,7 +476,7 @@ Symbol *SymbolTable::addRegular(StringRe
}
template <typename ELFT>
-void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> *File,
+void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> &File,
const typename ELFT::Sym &Sym, uint32_t Alignment,
uint32_t VerdefIndex) {
// DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
@@ -485,7 +485,7 @@ void SymbolTable::addShared(StringRef Na
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
- /*CanOmitFromDynSym*/ true, File);
+ /*CanOmitFromDynSym*/ true, &File);
// Make sure we preempt DSO symbols with default visibility.
if (Sym.getVisibility() == STV_DEFAULT)
S->ExportDynamic = true;
@@ -501,7 +501,7 @@ void SymbolTable::addShared(StringRef Na
if (!WasInserted) {
S->Binding = Binding;
if (!S->isWeak() && !Config->GcSections)
- File->IsNeeded = true;
+ File.IsNeeded = true;
}
}
}
@@ -837,16 +837,16 @@ template void SymbolTable::addLazyObject
template void SymbolTable::addLazyObject<ELF64LE>(StringRef, LazyObjFile &);
template void SymbolTable::addLazyObject<ELF64BE>(StringRef, LazyObjFile &);
-template void SymbolTable::addShared<ELF32LE>(StringRef, SharedFile<ELF32LE> *,
+template void SymbolTable::addShared<ELF32LE>(StringRef, SharedFile<ELF32LE> &,
const typename ELF32LE::Sym &,
uint32_t Alignment, uint32_t);
-template void SymbolTable::addShared<ELF32BE>(StringRef, SharedFile<ELF32BE> *,
+template void SymbolTable::addShared<ELF32BE>(StringRef, SharedFile<ELF32BE> &,
const typename ELF32BE::Sym &,
uint32_t Alignment, uint32_t);
-template void SymbolTable::addShared<ELF64LE>(StringRef, SharedFile<ELF64LE> *,
+template void SymbolTable::addShared<ELF64LE>(StringRef, SharedFile<ELF64LE> &,
const typename ELF64LE::Sym &,
uint32_t Alignment, uint32_t);
-template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> *,
+template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> &,
const typename ELF64BE::Sym &,
uint32_t Alignment, uint32_t);
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=321187&r1=321186&r2=321187&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Wed Dec 20 08:28:19 2017
@@ -57,7 +57,7 @@ public:
SectionBase *Section, InputFile *File);
template <class ELFT>
- void addShared(StringRef Name, SharedFile<ELFT> *F,
+ void addShared(StringRef Name, SharedFile<ELFT> &F,
const typename ELFT::Sym &Sym, uint32_t Alignment,
uint32_t VerdefIndex);
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=321187&r1=321186&r2=321187&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Dec 20 08:28:19 2017
@@ -208,10 +208,10 @@ class SharedSymbol : public Symbol {
public:
static bool classof(const Symbol *S) { return S->kind() == SharedKind; }
- SharedSymbol(InputFile *File, StringRef Name, uint8_t Binding,
+ SharedSymbol(InputFile &File, StringRef Name, uint8_t Binding,
uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size,
uint32_t Alignment, uint32_t VerdefIndex)
- : Symbol(SharedKind, File, Name, Binding, StOther, Type), Value(Value),
+ : Symbol(SharedKind, &File, Name, Binding, StOther, Type), Value(Value),
Size(Size), VerdefIndex(VerdefIndex), Alignment(Alignment) {
// GNU ifunc is a mechanism to allow user-supplied functions to
// resolve PLT slot values at load-time. This is contrary to the
@@ -233,8 +233,8 @@ public:
this->Type = llvm::ELF::STT_FUNC;
}
- template <class ELFT> SharedFile<ELFT> *getFile() const {
- return cast<SharedFile<ELFT>>(File);
+ template <class ELFT> SharedFile<ELFT> &getFile() const {
+ return *cast<SharedFile<ELFT>>(File);
}
// If not null, there is a copy relocation to this section.
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=321187&r1=321186&r2=321187&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Dec 20 08:28:19 2017
@@ -2299,8 +2299,8 @@ VersionNeedSection<ELFT>::VersionNeedSec
template <class ELFT>
void VersionNeedSection<ELFT>::addSymbol(SharedSymbol *SS) {
- SharedFile<ELFT> *File = SS->getFile<ELFT>();
- const typename ELFT::Verdef *Ver = File->Verdefs[SS->VerdefIndex];
+ SharedFile<ELFT> &File = SS->getFile<ELFT>();
+ const typename ELFT::Verdef *Ver = File.Verdefs[SS->VerdefIndex];
if (!Ver) {
SS->VersionId = VER_NDX_GLOBAL;
return;
@@ -2309,14 +2309,14 @@ void VersionNeedSection<ELFT>::addSymbol
// If we don't already know that we need an Elf_Verneed for this DSO, prepare
// to create one by adding it to our needed list and creating a dynstr entry
// for the soname.
- if (File->VerdefMap.empty())
- Needed.push_back({File, InX::DynStrTab->addString(File->SoName)});
- typename SharedFile<ELFT>::NeededVer &NV = File->VerdefMap[Ver];
+ if (File.VerdefMap.empty())
+ Needed.push_back({&File, InX::DynStrTab->addString(File.SoName)});
+ typename SharedFile<ELFT>::NeededVer &NV = File.VerdefMap[Ver];
// If we don't already know that we need an Elf_Vernaux for this Elf_Verdef,
// prepare to create one by allocating a version identifier and creating a
// dynstr entry for the version name.
if (NV.Index == 0) {
- NV.StrTab = InX::DynStrTab->addString(File->getStringTable().data() +
+ NV.StrTab = InX::DynStrTab->addString(File.getStringTable().data() +
Ver->getAux()->vda_name);
NV.Index = NextIndex++;
}
More information about the llvm-commits
mailing list