summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-11-29 22:47:35 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-11-29 22:47:35 +0000
commitdfebd3601de1d80fddab606636e8bff1c96dace8 (patch)
treeb97ccf0e179075c5ba629f59003acd7abc4c4dd9
parent52d036e6935f9340ca2d7502842d515accb02ee5 (diff)
downloadbcm5719-llvm-dfebd3601de1d80fddab606636e8bff1c96dace8.tar.gz
bcm5719-llvm-dfebd3601de1d80fddab606636e8bff1c96dace8.zip
Use Symbol::File directly.
We are already paying the cost of storing a InputFile in every Symbol, so use it uniformly. llvm-svn: 319378
-rw-r--r--lld/ELF/InputFiles.cpp4
-rw-r--r--lld/ELF/LTO.cpp2
-rw-r--r--lld/ELF/MapFile.cpp2
-rw-r--r--lld/ELF/Relocations.cpp4
-rw-r--r--lld/ELF/SymbolTable.cpp3
-rw-r--r--lld/ELF/Symbols.cpp23
-rw-r--r--lld/ELF/Symbols.h46
-rw-r--r--lld/ELF/SyntheticSections.cpp4
-rw-r--r--lld/ELF/Writer.cpp5
9 files changed, 40 insertions, 53 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index b25dc34b0fa..115de3f8cd8 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -635,9 +635,9 @@ template <class ELFT> Symbol *ObjFile<ELFT>::createSymbol(const Elf_Sym *Sym) {
StringRefZ Name = this->StringTable.data() + Sym->st_name;
if (Sym->st_shndx == SHN_UNDEF)
- return make<Undefined>(Name, Binding, StOther, Type);
+ return make<Undefined>(this, Name, Binding, StOther, Type);
- return make<Defined>(Name, Binding, StOther, Type, Value, Size, Sec);
+ return make<Defined>(this, Name, Binding, StOther, Type, Value, Size, Sec);
}
StringRef Name = check(Sym->getName(this->StringTable), toString(this));
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 7ff8b1882da..bfd85288d18 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -145,7 +145,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
// flags an undefined in IR with a definition in ASM as prevailing.
// Once IRObjectFile is fixed to report only one symbol this hack can
// be removed.
- R.Prevailing = !ObjSym.isUndefined() && Sym->getFile() == &F;
+ R.Prevailing = !ObjSym.isUndefined() && Sym->File == &F;
// We ask LTO to preserve following global symbols:
// 1) All symbols when doing relocatable link, so that them can be used
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index b1c84075ddd..47156eeceec 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -52,7 +52,7 @@ static std::vector<Defined *> getSymbols() {
for (InputFile *File : ObjectFiles)
for (Symbol *B : File->getSymbols())
if (auto *DR = dyn_cast<Defined>(B))
- if (DR->getFile() == File && !DR->isSection() && DR->Section &&
+ if (DR->File == File && !DR->isSection() && DR->Section &&
DR->Section->Live)
V.push_back(DR);
return V;
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 4280f10741f..4ec1d0ec99b 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -73,7 +73,7 @@ template <class ELFT>
static std::string getLocation(InputSectionBase &S, const Symbol &Sym,
uint64_t Off) {
std::string Msg =
- "\n>>> defined in " + toString(Sym.getFile()) + "\n>>> referenced by ";
+ "\n>>> defined in " + toString(Sym.File) + "\n>>> referenced by ";
std::string Src = S.getSrcMsg<ELFT>(Sym, Off);
if (!Src.empty())
Msg += Src + "\n>>> ";
@@ -641,7 +641,7 @@ static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type,
}
errorOrWarn("symbol '" + toString(Sym) + "' defined in " +
- toString(Sym.getFile()) + " has no type");
+ toString(Sym.File) + " has no type");
return Expr;
}
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index a82046ba008..fb61cc29fed 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -421,8 +421,7 @@ static void warnOrError(const Twine &Msg) {
static void reportDuplicate(Symbol *Sym, InputFile *NewFile) {
warnOrError("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " +
- toString(Sym->getFile()) + "\n>>> defined in " +
- toString(NewFile));
+ toString(Sym->File) + "\n>>> defined in " + toString(NewFile));
}
template <class ELFT>
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 5d496a6aeb4..7985e300e0e 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -93,7 +93,7 @@ static uint64_t getSymVA(const Symbol &Sym, int64_t &Addend) {
if (D.isTls() && !Config->Relocatable) {
if (!Out::TlsPhdr)
- fatal(toString(D.getFile()) +
+ fatal(toString(D.File) +
" has an STT_TLS symbol but doesn't have an SHF_TLS section");
return VA - Out::TlsPhdr->p_vaddr;
}
@@ -123,17 +123,6 @@ bool Symbol::isUndefWeak() const {
return !isLocal() && isWeak() && (isUndefined() || isLazy());
}
-InputFile *Symbol::getFile() const {
- if (isLocal()) {
- 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.
- return Sec ? cast<InputSectionBase>(Sec)->File : nullptr;
- }
- return File;
-}
-
uint64_t Symbol::getVA(int64_t Addend) const {
uint64_t OutVA = getSymVA(*this, Addend);
return OutVA + Addend;
@@ -226,7 +215,7 @@ void Symbol::parseSymbolVersion() {
// but we may still want to override a versioned symbol from DSO,
// so we do not report error in this case.
if (Config->Shared)
- error(toString(getFile()) + ": symbol " + S + " has undefined version " +
+ error(toString(File) + ": symbol " + S + " has undefined version " +
Verstr);
}
@@ -236,9 +225,7 @@ InputFile *Lazy::fetch() {
return cast<LazyObject>(this)->fetch();
}
-ArchiveFile *LazyArchive::getFile() {
- return cast<ArchiveFile>(Symbol::getFile());
-}
+ArchiveFile *LazyArchive::getFile() { return cast<ArchiveFile>(File); }
InputFile *LazyArchive::fetch() {
std::pair<MemoryBufferRef, uint64_t> MBInfo = getFile()->getMember(&Sym);
@@ -250,9 +237,7 @@ InputFile *LazyArchive::fetch() {
return createObjectFile(MBInfo.first, getFile()->getName(), MBInfo.second);
}
-LazyObjFile *LazyObject::getFile() {
- return cast<LazyObjFile>(Symbol::getFile());
-}
+LazyObjFile *LazyObject::getFile() { return cast<LazyObjFile>(File); }
InputFile *LazyObject::fetch() { return getFile()->fetch(); }
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 7a3ed4ffcaa..0158f4f60fa 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -85,7 +85,7 @@ public:
unsigned InVersionScript : 1;
// The file from which this symbol was created.
- InputFile *File = nullptr;
+ InputFile *File;
bool includeInDynsym() const;
uint8_t computeBinding() const;
@@ -104,7 +104,6 @@ public:
// all input files have been added.
bool isUndefWeak() const;
- InputFile *getFile() const;
StringRef getName() const { return Name; }
uint8_t getVisibility() const { return StOther & 0x3; }
void parseSymbolVersion();
@@ -129,9 +128,9 @@ public:
uint32_t GlobalDynIndex = -1;
protected:
- Symbol(Kind K, StringRefZ Name, uint8_t Binding, uint8_t StOther,
- uint8_t Type)
- : Binding(Binding), SymbolKind(K), NeedsPltAddr(false),
+ Symbol(Kind K, InputFile *File, StringRefZ Name, uint8_t Binding,
+ uint8_t StOther, uint8_t Type)
+ : Binding(Binding), File(File), SymbolKind(K), NeedsPltAddr(false),
IsInGlobalMipsGot(false), Is32BitMipsGot(false), IsInIplt(false),
IsInIgot(false), IsPreemptible(false), Used(!Config->GcSections),
Type(Type), StOther(StOther), Name(Name) {}
@@ -184,9 +183,9 @@ protected:
// Represents a symbol that is defined in the current output file.
class Defined : public Symbol {
public:
- Defined(StringRefZ Name, uint8_t Binding, uint8_t StOther, uint8_t Type,
- uint64_t Value, uint64_t Size, SectionBase *Section)
- : Symbol(DefinedKind, Name, Binding, StOther, Type), Value(Value),
+ Defined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t StOther,
+ uint8_t Type, uint64_t Value, uint64_t Size, SectionBase *Section)
+ : Symbol(DefinedKind, File, Name, Binding, StOther, Type), Value(Value),
Size(Size), Section(Section) {}
static bool classof(const Symbol *S) { return S->isDefined(); }
@@ -198,8 +197,9 @@ public:
class Undefined : public Symbol {
public:
- Undefined(StringRefZ Name, uint8_t Binding, uint8_t StOther, uint8_t Type)
- : Symbol(UndefinedKind, Name, Binding, StOther, Type) {}
+ Undefined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t StOther,
+ uint8_t Type)
+ : Symbol(UndefinedKind, File, Name, Binding, StOther, Type) {}
static bool classof(const Symbol *S) { return S->kind() == UndefinedKind; }
};
@@ -208,10 +208,10 @@ class SharedSymbol : public Symbol {
public:
static bool classof(const Symbol *S) { return S->kind() == SharedKind; }
- SharedSymbol(StringRef Name, uint8_t Binding, uint8_t StOther, uint8_t Type,
- uint64_t Value, uint64_t Size, uint32_t Alignment,
- const void *Verdef)
- : Symbol(SharedKind, Name, Binding, StOther, Type), Verdef(Verdef),
+ SharedSymbol(InputFile *File, StringRef Name, uint8_t Binding,
+ uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size,
+ uint32_t Alignment, const void *Verdef)
+ : Symbol(SharedKind, File, Name, Binding, StOther, Type), Verdef(Verdef),
Value(Value), Size(Size), 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
@@ -234,7 +234,7 @@ public:
}
template <class ELFT> SharedFile<ELFT> *getFile() const {
- return cast<SharedFile<ELFT>>(Symbol::getFile());
+ return cast<SharedFile<ELFT>>(File);
}
// This field is a pointer to the symbol's version definition.
@@ -266,8 +266,9 @@ public:
InputFile *fetch();
protected:
- Lazy(Kind K, StringRef Name, uint8_t Type)
- : Symbol(K, Name, llvm::ELF::STB_GLOBAL, llvm::ELF::STV_DEFAULT, Type) {}
+ Lazy(Kind K, InputFile *File, StringRef Name, uint8_t Type)
+ : Symbol(K, File, Name, llvm::ELF::STB_GLOBAL, llvm::ELF::STV_DEFAULT,
+ Type) {}
};
// This class represents a symbol defined in an archive file. It is
@@ -276,8 +277,9 @@ protected:
// symbol.
class LazyArchive : public Lazy {
public:
- LazyArchive(const llvm::object::Archive::Symbol S, uint8_t Type)
- : Lazy(LazyArchiveKind, S.getName(), Type), Sym(S) {}
+ LazyArchive(InputFile *File, const llvm::object::Archive::Symbol S,
+ uint8_t Type)
+ : Lazy(LazyArchiveKind, File, S.getName(), Type), Sym(S) {}
static bool classof(const Symbol *S) { return S->kind() == LazyArchiveKind; }
@@ -292,7 +294,8 @@ private:
// --start-lib and --end-lib options.
class LazyObject : public Lazy {
public:
- LazyObject(StringRef Name, uint8_t Type) : Lazy(LazyObjectKind, Name, Type) {}
+ LazyObject(InputFile *File, StringRef Name, uint8_t Type)
+ : Lazy(LazyObjectKind, File, Name, Type) {}
static bool classof(const Symbol *S) { return S->kind() == LazyObjectKind; }
@@ -343,7 +346,7 @@ union SymbolUnion {
void printTraceSymbol(Symbol *Sym);
template <typename T, typename... ArgT>
-void replaceSymbol(Symbol *S, InputFile *File, ArgT &&... Arg) {
+void replaceSymbol(Symbol *S, ArgT &&... Arg) {
static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
static_assert(alignof(T) <= alignof(SymbolUnion),
"SymbolUnion not aligned enough");
@@ -353,7 +356,6 @@ void replaceSymbol(Symbol *S, InputFile *File, ArgT &&... Arg) {
Symbol Sym = *S;
new (S) T(std::forward<ArgT>(Arg)...);
- S->File = File;
S->VersionId = Sym.VersionId;
S->Visibility = Sym.Visibility;
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 79fd0ef298f..8d775d9ba6e 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -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<Defined>(Name, STB_LOCAL, STV_DEFAULT, Type, Value, Size, Section);
+ auto *S = make<Defined>(Section->File, Name, STB_LOCAL, STV_DEFAULT, Type,
+ Value, Size, Section);
if (InX::SymTab)
InX::SymTab->addSymbol(S);
return S;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index e8e0235ac45..90902375ff3 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -508,8 +508,9 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
if (isa<SyntheticSection>(IS) && !(IS->Flags & SHF_MERGE))
continue;
- auto *Sym = make<Defined>("", STB_LOCAL, /*StOther=*/0, STT_SECTION,
- /*Value=*/0, /*Size=*/0, IS);
+ auto *Sym =
+ make<Defined>(IS->File, "", STB_LOCAL, /*StOther=*/0, STT_SECTION,
+ /*Value=*/0, /*Size=*/0, IS);
InX::SymTab->addSymbol(Sym);
}
}
OpenPOWER on IntegriCloud