[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.
This commit is contained in:
Fangrui Song 2022-02-23 17:57:52 -08:00
parent 7e3606f43c
commit 47d18be58b
4 changed files with 6 additions and 8 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -403,8 +403,6 @@ public:
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;