[ELF] Change objectFiles to ELFFileBase *

This can sometimes avoid `cast<ObjFile<...>>`.

I intentionally do not touch postScanRelocations to wait for its stabilization.
This commit is contained in:
Fangrui Song 2021-12-15 00:37:10 -08:00
parent b4f46555d7
commit 7a54ae9c1d
9 changed files with 18 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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