From 47d18be58b61f80f9be0b84c2ac00f0741608a83 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 23 Feb 2022 17:57:52 -0800 Subject: [PATCH] [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(s->file)`), but the compromise is acceptable. --- lld/ELF/Driver.cpp | 2 +- lld/ELF/MarkLive.cpp | 4 ++-- lld/ELF/Relocations.cpp | 6 +++--- lld/ELF/Symbols.h | 2 -- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index cfc99dd..d34ee09 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(sym); - if (!(s && !s->getFile().isNeeded) && !sym->isLazy()) + if (!(s && !cast(s->file)->isNeeded) && !sym->isLazy()) continue; bool used = sym->used; diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index b197dd4..cf8e639 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -118,7 +118,7 @@ void MarkLive::resolveReloc(InputSectionBase &sec, RelTy &rel, if (auto *ss = dyn_cast(&sym)) if (!ss->isWeak()) - ss->getFile().isNeeded = true; + cast(ss->file)->isNeeded = true; for (InputSectionBase *sec : cNamedSections.lookup(sym.getName())) enqueue(sec, 0); @@ -373,7 +373,7 @@ template void elf::markLive() { for (Symbol *sym : symtab->symbols()) if (auto *s = dyn_cast(sym)) if (s->isUsedInRegularObj && !s->isWeak()) - s->getFile().isNeeded = true; + cast(s->file)->isNeeded = true; return; } diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 8bc52ed..33b5b3d 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -247,7 +247,7 @@ template 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(*ss.file); for (const Elf_Phdr &phdr : check(file.template getObj().program_headers())) if ((phdr.p_type == ELF::PT_LOAD || phdr.p_type == ELF::PT_GNU_RELRO) && @@ -266,7 +266,7 @@ template static SmallSet getSymbolsAt(SharedSymbol &ss) { using Elf_Sym = typename ELFT::Sym; - SharedFile &file = ss.getFile(); + const auto &file = cast(*ss.file); SmallSet ret; for (const Elf_Sym &s : file.template getGlobalELFSyms()) { @@ -382,7 +382,7 @@ template static void addCopyRelSymbolImpl(SharedSymbol &ss) { } static void addCopyRelSymbol(SharedSymbol &ss) { - const SharedFile &file = ss.getFile(); + const auto &file = cast(*ss.file); switch (file.ekind) { case ELF32LEKind: addCopyRelSymbolImpl(ss); diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index dd24566..77b1e62 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -403,8 +403,6 @@ public: this->type = llvm::ELF::STT_FUNC; } - SharedFile &getFile() const { return *cast(file); } - uint64_t value; // st_value uint64_t size; // st_size uint32_t alignment; -- 2.7.4