[lld] 7a54ae9 - [ELF] Change objectFiles to ELFFileBase *
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 15 00:37:15 PST 2021
Author: Fangrui Song
Date: 2021-12-15T00:37:10-08:00
New Revision: 7a54ae9c1d42f38ce45a2072055e68a790100fd8
URL: https://github.com/llvm/llvm-project/commit/7a54ae9c1d42f38ce45a2072055e68a790100fd8
DIFF: https://github.com/llvm/llvm-project/commit/7a54ae9c1d42f38ce45a2072055e68a790100fd8.diff
LOG: [ELF] Change objectFiles to ELFFileBase *
This can sometimes avoid `cast<ObjFile<...>>`.
I intentionally do not touch postScanRelocations to wait for its stabilization.
Added:
Modified:
lld/ELF/AArch64ErrataFix.cpp
lld/ELF/ARMErrataFix.cpp
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
lld/ELF/MapFile.cpp
lld/ELF/MarkLive.cpp
lld/ELF/Relocations.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/AArch64ErrataFix.cpp b/lld/ELF/AArch64ErrataFix.cpp
index 741ff26a7e6c..50d4c237778b 100644
--- a/lld/ELF/AArch64ErrataFix.cpp
+++ b/lld/ELF/AArch64ErrataFix.cpp
@@ -440,9 +440,8 @@ void AArch64Err843419Patcher::init() {
};
// Collect mapping symbols for every executable InputSection.
- for (InputFile *file : objectFiles) {
- auto *f = cast<ObjFile<ELF64LE>>(file);
- for (Symbol *b : f->getLocalSymbols()) {
+ for (ELFFileBase *file : objectFiles) {
+ for (Symbol *b : file->getLocalSymbols()) {
auto *def = dyn_cast<Defined>(b);
if (!def)
continue;
diff --git a/lld/ELF/ARMErrataFix.cpp b/lld/ELF/ARMErrataFix.cpp
index fe6ec09bd979..5ad55f1326b3 100644
--- a/lld/ELF/ARMErrataFix.cpp
+++ b/lld/ELF/ARMErrataFix.cpp
@@ -329,9 +329,8 @@ void ARMErr657417Patcher::init() {
};
// Collect mapping symbols for every executable InputSection.
- for (InputFile *file : objectFiles) {
- auto *f = cast<ObjFile<ELF32LE>>(file);
- for (Symbol *s : f->getLocalSymbols()) {
+ for (ELFFileBase *file : objectFiles) {
+ for (Symbol *s : file->getLocalSymbols()) {
auto *def = dyn_cast<Defined>(s);
if (!def)
continue;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 1376e6c2c253..4d6fec26bd3a 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -798,7 +798,7 @@ static std::pair<bool, bool> getPackDynRelocs(opt::InputArgList &args) {
static void readCallGraph(MemoryBufferRef mb) {
// Build a map from symbol name to section
DenseMap<StringRef, Symbol *> map;
- for (InputFile *file : objectFiles)
+ for (ELFFileBase *file : objectFiles)
for (Symbol *sym : file->getSymbols())
map[sym->getName()] = sym;
@@ -1662,7 +1662,7 @@ static void excludeLibs(opt::InputArgList &args) {
sym->versionId = VER_NDX_LOCAL;
};
- for (InputFile *file : objectFiles)
+ for (ELFFileBase *file : objectFiles)
visit(file);
for (BitcodeFile *file : bitcodeFiles)
@@ -1975,7 +1975,7 @@ template <class ELFT> void LinkerDriver::compileBitcodeFiles() {
if (!config->relocatable)
for (Symbol *sym : obj->getGlobalSymbols())
sym->parseSymbolVersion();
- objectFiles.push_back(file);
+ objectFiles.push_back(obj);
}
}
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 8b1d1827e24e..ddfa1c9bccd4 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -47,7 +47,7 @@ std::vector<ArchiveFile *> elf::archiveFiles;
std::vector<BinaryFile *> elf::binaryFiles;
std::vector<BitcodeFile *> elf::bitcodeFiles;
std::vector<LazyObjFile *> elf::lazyObjFiles;
-std::vector<InputFile *> elf::objectFiles;
+std::vector<ELFFileBase *> elf::objectFiles;
std::vector<SharedFile *> elf::sharedFiles;
std::unique_ptr<TarWriter> elf::tar;
@@ -209,7 +209,7 @@ template <class ELFT> static void doParseFile(InputFile *file) {
}
// Regular object file
- objectFiles.push_back(file);
+ objectFiles.push_back(cast<ELFFileBase>(file));
cast<ObjFile<ELFT>>(file)->parse();
}
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index d359a49616e2..1075029b8df9 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -417,7 +417,7 @@ extern std::vector<ArchiveFile *> archiveFiles;
extern std::vector<BinaryFile *> binaryFiles;
extern std::vector<BitcodeFile *> bitcodeFiles;
extern std::vector<LazyObjFile *> lazyObjFiles;
-extern std::vector<InputFile *> objectFiles;
+extern std::vector<ELFFileBase *> objectFiles;
extern std::vector<SharedFile *> sharedFiles;
} // namespace elf
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index 275983527538..1998192bfba6 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -54,7 +54,7 @@ static void writeHeader(raw_ostream &os, uint64_t vma, uint64_t lma,
// Returns a list of all symbols that we want to print out.
static std::vector<Defined *> getSymbols() {
std::vector<Defined *> v;
- for (InputFile *file : objectFiles)
+ for (ELFFileBase *file : objectFiles)
for (Symbol *b : file->getSymbols())
if (auto *dr = dyn_cast<Defined>(b))
if (!dr->isSection() && dr->section && dr->section->isLive() &&
@@ -243,7 +243,7 @@ void elf::writeWhyExtract() {
static void writeCref(raw_fd_ostream &os) {
// Collect symbols and files.
MapVector<Symbol *, SetVector<InputFile *>> map;
- for (InputFile *file : objectFiles) {
+ for (ELFFileBase *file : objectFiles) {
for (Symbol *sym : file->getSymbols()) {
if (isa<SharedSymbol>(sym))
map[sym].insert(file);
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 11e0466b1157..48ef87bb7bb3 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -312,7 +312,7 @@ template <class ELFT> void MarkLive<ELFT>::mark() {
// to from __start_/__stop_ symbols because there will only be one set of
// symbols for the whole program.
template <class ELFT> void MarkLive<ELFT>::moveToMain() {
- for (InputFile *file : objectFiles)
+ for (ELFFileBase *file : objectFiles)
for (Symbol *s : file->getSymbols())
if (auto *d = dyn_cast<Defined>(s))
if ((d->type == STT_GNU_IFUNC || d->type == STT_TLS) && d->section &&
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 6bd7e2f00179..e3782f342897 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1645,7 +1645,7 @@ void elf::postScanRelocations() {
// Local symbols may need the aforementioned non-preemptible ifunc and GOT
// handling. They don't need regular PLT.
- for (InputFile *file : objectFiles)
+ for (ELFFileBase *file : objectFiles)
for (Symbol *sym : cast<ELFFileBase>(file)->getLocalSymbols())
fn(*sym);
}
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index b5ec50a4092a..17ece08835c1 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -622,7 +622,7 @@ template <class ELFT> static void markUsedLocalSymbols() {
return;
// Without --gc-sections, the field is initialized with "true".
// Drop the flag first and then rise for symbols referenced in relocations.
- for (InputFile *file : objectFiles) {
+ for (ELFFileBase *file : objectFiles) {
ObjFile<ELFT> *f = cast<ObjFile<ELFT>>(file);
for (Symbol *b : f->getLocalSymbols())
b->used = false;
@@ -704,9 +704,8 @@ template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
llvm::TimeTraceScope timeScope("Add local symbols");
if (config->copyRelocs && config->discard != DiscardPolicy::None)
markUsedLocalSymbols<ELFT>();
- for (InputFile *file : objectFiles) {
- ObjFile<ELFT> *f = cast<ObjFile<ELFT>>(file);
- for (Symbol *b : f->getLocalSymbols()) {
+ for (ELFFileBase *file : objectFiles) {
+ for (Symbol *b : file->getLocalSymbols()) {
assert(b->isLocal() && "should have been caught in initializeSymbols()");
auto *dr = dyn_cast<Defined>(b);
@@ -1322,7 +1321,7 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
if (!sym->isLazy())
addSym(*sym);
- for (InputFile *file : objectFiles)
+ for (ELFFileBase *file : objectFiles)
for (Symbol *sym : file->getSymbols()) {
if (!sym->isLocal())
break;
More information about the llvm-commits
mailing list