[lld] 47d18be - [ELF] Remove SharedSymbol::getFile. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 23 17:57:56 PST 2022
Author: Fangrui Song
Date: 2022-02-23T17:57:52-08:00
New Revision: 47d18be58b61f80f9be0b84c2ac00f0741608a83
URL: https://github.com/llvm/llvm-project/commit/47d18be58b61f80f9be0b84c2ac00f0741608a83
DIFF: https://github.com/llvm/llvm-project/commit/47d18be58b61f80f9be0b84c2ac00f0741608a83.diff
LOG: [ELF] Remove SharedSymbol::getFile. NFC
Symbol.h depends on InputFiles.h. This change moves us toward dropping the
weird dependency.
The call sites will become slightly uglier (`cast<SharedFile>(s->file)`), but
the compromise is acceptable.
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/MarkLive.cpp
lld/ELF/Relocations.cpp
lld/ELF/Symbols.h
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index cfc99dd115dc1..d34ee094506d6 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1832,7 +1832,7 @@ static void demoteSharedAndLazySymbols() {
llvm::TimeTraceScope timeScope("Demote shared and lazy symbols");
for (Symbol *sym : symtab->symbols()) {
auto *s = dyn_cast<SharedSymbol>(sym);
- if (!(s && !s->getFile().isNeeded) && !sym->isLazy())
+ if (!(s && !cast<SharedFile>(s->file)->isNeeded) && !sym->isLazy())
continue;
bool used = sym->used;
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index b197dd45d765b..cf8e639ad6482 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -118,7 +118,7 @@ void MarkLive<ELFT>::resolveReloc(InputSectionBase &sec, RelTy &rel,
if (auto *ss = dyn_cast<SharedSymbol>(&sym))
if (!ss->isWeak())
- ss->getFile().isNeeded = true;
+ cast<SharedFile>(ss->file)->isNeeded = true;
for (InputSectionBase *sec : cNamedSections.lookup(sym.getName()))
enqueue(sec, 0);
@@ -373,7 +373,7 @@ template <class ELFT> void elf::markLive() {
for (Symbol *sym : symtab->symbols())
if (auto *s = dyn_cast<SharedSymbol>(sym))
if (s->isUsedInRegularObj && !s->isWeak())
- s->getFile().isNeeded = true;
+ cast<SharedFile>(s->file)->isNeeded = true;
return;
}
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 8bc52ed2e3771..33b5b3dd098b0 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -247,7 +247,7 @@ template <class ELFT> static bool isReadOnly(SharedSymbol &ss) {
using Elf_Phdr = typename ELFT::Phdr;
// Determine if the symbol is read-only by scanning the DSO's program headers.
- const SharedFile &file = ss.getFile();
+ const auto &file = cast<SharedFile>(*ss.file);
for (const Elf_Phdr &phdr :
check(file.template getObj<ELFT>().program_headers()))
if ((phdr.p_type == ELF::PT_LOAD || phdr.p_type == ELF::PT_GNU_RELRO) &&
@@ -266,7 +266,7 @@ template <class ELFT>
static SmallSet<SharedSymbol *, 4> getSymbolsAt(SharedSymbol &ss) {
using Elf_Sym = typename ELFT::Sym;
- SharedFile &file = ss.getFile();
+ const auto &file = cast<SharedFile>(*ss.file);
SmallSet<SharedSymbol *, 4> ret;
for (const Elf_Sym &s : file.template getGlobalELFSyms<ELFT>()) {
@@ -382,7 +382,7 @@ template <class ELFT> static void addCopyRelSymbolImpl(SharedSymbol &ss) {
}
static void addCopyRelSymbol(SharedSymbol &ss) {
- const SharedFile &file = ss.getFile();
+ const auto &file = cast<SharedFile>(*ss.file);
switch (file.ekind) {
case ELF32LEKind:
addCopyRelSymbolImpl<ELF32LE>(ss);
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index dd245660d13d5..77b1e62e1986d 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -403,8 +403,6 @@ class SharedSymbol : public Symbol {
this->type = llvm::ELF::STT_FUNC;
}
- SharedFile &getFile() const { return *cast<SharedFile>(file); }
-
uint64_t value; // st_value
uint64_t size; // st_size
uint32_t alignment;
More information about the llvm-commits
mailing list