[lld] 9a57216 - [ELF] Move InputFiles global variables (memoryBuffers, objectFiles, etc) into Ctx. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 29 18:53:42 PDT 2022
Author: Fangrui Song
Date: 2022-06-29T18:53:38-07:00
New Revision: 9a572164d592ec439fea6b635c28698e5b194546
URL: https://github.com/llvm/llvm-project/commit/9a572164d592ec439fea6b635c28698e5b194546
DIFF: https://github.com/llvm/llvm-project/commit/9a572164d592ec439fea6b635c28698e5b194546.diff
LOG: [ELF] Move InputFiles global variables (memoryBuffers, objectFiles, etc) into Ctx. NFC
Added:
Modified:
lld/ELF/AArch64ErrataFix.cpp
lld/ELF/ARMErrataFix.cpp
lld/ELF/Arch/AMDGPU.cpp
lld/ELF/Arch/AVR.cpp
lld/ELF/Arch/Hexagon.cpp
lld/ELF/Arch/MipsArchTree.cpp
lld/ELF/Arch/PPC64.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/ICF.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
lld/ELF/LTO.cpp
lld/ELF/MapFile.cpp
lld/ELF/MarkLive.cpp
lld/ELF/Relocations.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/AArch64ErrataFix.cpp b/lld/ELF/AArch64ErrataFix.cpp
index 2faee78f02602..f61a9269d6a41 100644
--- a/lld/ELF/AArch64ErrataFix.cpp
+++ b/lld/ELF/AArch64ErrataFix.cpp
@@ -439,7 +439,7 @@ void AArch64Err843419Patcher::init() {
};
// Collect mapping symbols for every executable InputSection.
- for (ELFFileBase *file : objectFiles) {
+ for (ELFFileBase *file : ctx->objectFiles) {
for (Symbol *b : file->getLocalSymbols()) {
auto *def = dyn_cast<Defined>(b);
if (!def)
diff --git a/lld/ELF/ARMErrataFix.cpp b/lld/ELF/ARMErrataFix.cpp
index 99b7bc7627fec..1cebbba55b4a6 100644
--- a/lld/ELF/ARMErrataFix.cpp
+++ b/lld/ELF/ARMErrataFix.cpp
@@ -327,7 +327,7 @@ void ARMErr657417Patcher::init() {
};
// Collect mapping symbols for every executable InputSection.
- for (ELFFileBase *file : objectFiles) {
+ for (ELFFileBase *file : ctx->objectFiles) {
for (Symbol *s : file->getLocalSymbols()) {
auto *def = dyn_cast<Defined>(s);
if (!def)
diff --git a/lld/ELF/Arch/AMDGPU.cpp b/lld/ELF/Arch/AMDGPU.cpp
index 30a9a2d2974a5..0368f82c6a653 100644
--- a/lld/ELF/Arch/AMDGPU.cpp
+++ b/lld/ELF/Arch/AMDGPU.cpp
@@ -48,10 +48,10 @@ static uint32_t getEFlags(InputFile *file) {
}
uint32_t AMDGPU::calcEFlagsV3() const {
- uint32_t ret = getEFlags(objectFiles[0]);
+ uint32_t ret = getEFlags(ctx->objectFiles[0]);
// Verify that all input files have the same e_flags.
- for (InputFile *f : makeArrayRef(objectFiles).slice(1)) {
+ for (InputFile *f : makeArrayRef(ctx->objectFiles).slice(1)) {
if (ret == getEFlags(f))
continue;
error("incompatible e_flags: " + toString(f));
@@ -61,14 +61,15 @@ uint32_t AMDGPU::calcEFlagsV3() const {
}
uint32_t AMDGPU::calcEFlagsV4() const {
- uint32_t retMach = getEFlags(objectFiles[0]) & EF_AMDGPU_MACH;
- uint32_t retXnack = getEFlags(objectFiles[0]) & EF_AMDGPU_FEATURE_XNACK_V4;
+ uint32_t retMach = getEFlags(ctx->objectFiles[0]) & EF_AMDGPU_MACH;
+ uint32_t retXnack =
+ getEFlags(ctx->objectFiles[0]) & EF_AMDGPU_FEATURE_XNACK_V4;
uint32_t retSramEcc =
- getEFlags(objectFiles[0]) & EF_AMDGPU_FEATURE_SRAMECC_V4;
+ getEFlags(ctx->objectFiles[0]) & EF_AMDGPU_FEATURE_SRAMECC_V4;
// Verify that all input files have compatible e_flags (same mach, all
// features in the same category are either ANY, ANY and ON, or ANY and OFF).
- for (InputFile *f : makeArrayRef(objectFiles).slice(1)) {
+ for (InputFile *f : makeArrayRef(ctx->objectFiles).slice(1)) {
if (retMach != (getEFlags(f) & EF_AMDGPU_MACH)) {
error("incompatible mach: " + toString(f));
return 0;
@@ -105,11 +106,13 @@ uint32_t AMDGPU::calcEFlagsV4() const {
}
uint32_t AMDGPU::calcEFlags() const {
- if (objectFiles.empty())
+ if (ctx->objectFiles.empty())
return 0;
- uint8_t abiVersion = cast<ObjFile<ELF64LE>>(objectFiles[0])->getObj()
- .getHeader().e_ident[EI_ABIVERSION];
+ uint8_t abiVersion = cast<ObjFile<ELF64LE>>(ctx->objectFiles[0])
+ ->getObj()
+ .getHeader()
+ .e_ident[EI_ABIVERSION];
switch (abiVersion) {
case ELFABIVERSION_AMDGPU_HSA_V2:
case ELFABIVERSION_AMDGPU_HSA_V3:
diff --git a/lld/ELF/Arch/AVR.cpp b/lld/ELF/Arch/AVR.cpp
index 105a71da625ba..d972f8e8fdea8 100644
--- a/lld/ELF/Arch/AVR.cpp
+++ b/lld/ELF/Arch/AVR.cpp
@@ -226,12 +226,12 @@ static uint32_t getEFlags(InputFile *file) {
}
uint32_t AVR::calcEFlags() const {
- assert(!objectFiles.empty());
+ assert(!ctx->objectFiles.empty());
- uint32_t flags = getEFlags(objectFiles[0]);
+ uint32_t flags = getEFlags(ctx->objectFiles[0]);
bool hasLinkRelaxFlag = flags & EF_AVR_LINKRELAX_PREPARED;
- for (InputFile *f : makeArrayRef(objectFiles).slice(1)) {
+ for (InputFile *f : makeArrayRef(ctx->objectFiles).slice(1)) {
uint32_t objFlags = getEFlags(f);
if ((objFlags & EF_AVR_ARCH_MASK) != (flags & EF_AVR_ARCH_MASK))
error(toString(f) +
diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index d54b4c9b52f5a..6bca4070629ec 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -59,12 +59,12 @@ Hexagon::Hexagon() {
}
uint32_t Hexagon::calcEFlags() const {
- assert(!objectFiles.empty());
+ assert(!ctx->objectFiles.empty());
// The architecture revision must always be equal to or greater than
// greatest revision in the list of inputs.
uint32_t ret = 0;
- for (InputFile *f : objectFiles) {
+ for (InputFile *f : ctx->objectFiles) {
uint32_t eflags = cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags;
if (eflags > ret)
ret = eflags;
diff --git a/lld/ELF/Arch/MipsArchTree.cpp b/lld/ELF/Arch/MipsArchTree.cpp
index 93929f2b45a4e..f1fcf1610cb10 100644
--- a/lld/ELF/Arch/MipsArchTree.cpp
+++ b/lld/ELF/Arch/MipsArchTree.cpp
@@ -295,7 +295,7 @@ static uint32_t getArchFlags(ArrayRef<FileFlags> files) {
template <class ELFT> uint32_t elf::calcMipsEFlags() {
std::vector<FileFlags> v;
- for (InputFile *f : objectFiles)
+ for (InputFile *f : ctx->objectFiles)
v.push_back({f, cast<ObjFile<ELFT>>(f)->getObj().getHeader().e_flags});
if (v.empty()) {
// If we don't have any input files, we'll have to rely on the information
diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp
index 50d1cbf0dbba7..9b72029e8e1d2 100644
--- a/lld/ELF/Arch/PPC64.cpp
+++ b/lld/ELF/Arch/PPC64.cpp
@@ -622,7 +622,7 @@ static uint32_t getEFlags(InputFile *file) {
// This file implements v2 ABI. This function makes sure that all
// object files have v2 or an unspecified version as an ABI version.
uint32_t PPC64::calcEFlags() const {
- for (InputFile *f : objectFiles) {
+ for (InputFile *f : ctx->objectFiles) {
uint32_t flag = getEFlags(f);
if (flag == 1)
error(toString(f) + ": ABI version 1 is not supported");
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index a0ea403e241d0..7ba0214eb2a7f 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -111,12 +111,12 @@ static uint32_t getEFlags(InputFile *f) {
uint32_t RISCV::calcEFlags() const {
// If there are only binary input files (from -b binary), use a
// value of 0 for the ELF header flags.
- if (objectFiles.empty())
+ if (ctx->objectFiles.empty())
return 0;
- uint32_t target = getEFlags(objectFiles.front());
+ uint32_t target = getEFlags(ctx->objectFiles.front());
- for (InputFile *f : objectFiles) {
+ for (InputFile *f : ctx->objectFiles) {
uint32_t eflags = getEFlags(f);
if (eflags & EF_RISCV_RVC)
target |= EF_RISCV_RVC;
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 915c4d94e8704..c593880d5cd31 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -29,6 +29,10 @@ namespace lld {
namespace elf {
class InputFile;
+class BinaryFile;
+class BitcodeFile;
+class ELFFileBase;
+class SharedFile;
class InputSectionBase;
class Symbol;
@@ -373,6 +377,12 @@ struct DuplicateSymbol {
};
struct Ctx {
+ SmallVector<std::unique_ptr<MemoryBuffer>> memoryBuffers;
+ SmallVector<ELFFileBase *, 0> objectFiles;
+ SmallVector<SharedFile *, 0> sharedFiles;
+ SmallVector<BinaryFile *, 0> binaryFiles;
+ SmallVector<BitcodeFile *, 0> bitcodeFiles;
+ SmallVector<BitcodeFile *, 0> lazyBitcodeFiles;
// Duplicate symbol candidates.
SmallVector<DuplicateSymbol, 0> duplicates;
// Symbols in a non-prevailing COMDAT group which should be changed to an
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 2ab698c91b019..7500b68a9beff 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -97,12 +97,6 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
ctx->e.cleanupCallback = []() {
inputSections.clear();
outputSections.clear();
- memoryBuffers.clear();
- binaryFiles.clear();
- bitcodeFiles.clear();
- lazyBitcodeFiles.clear();
- objectFiles.clear();
- sharedFiles.clear();
symAux.clear();
tar = nullptr;
@@ -198,7 +192,7 @@ std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
// Take ownership of memory buffers created for members of thin archives.
std::vector<std::unique_ptr<MemoryBuffer>> mbs = file->takeThinBuffers();
- std::move(mbs.begin(), mbs.end(), std::back_inserter(memoryBuffers));
+ std::move(mbs.begin(), mbs.end(), std::back_inserter(ctx->memoryBuffers));
return v;
}
@@ -843,7 +837,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 (ELFFileBase *file : objectFiles)
+ for (ELFFileBase *file : ctx->objectFiles)
for (Symbol *sym : file->getSymbols())
map[sym->getName()] = sym;
@@ -922,7 +916,7 @@ processCallGraphRelocations(SmallVector<uint32_t, 32> &symbolIndices,
template <class ELFT> static void readCallGraphsFromObjectFiles() {
SmallVector<uint32_t, 32> symbolIndices;
ArrayRef<typename ELFT::CGProfile> cgProfile;
- for (auto file : objectFiles) {
+ for (auto file : ctx->objectFiles) {
auto *obj = cast<ObjFile<ELFT>>(file);
if (!processCallGraphRelocations(symbolIndices, cgProfile, obj))
continue;
@@ -1757,10 +1751,10 @@ static void excludeLibs(opt::InputArgList &args) {
sym->versionId = VER_NDX_LOCAL;
};
- for (ELFFileBase *file : objectFiles)
+ for (ELFFileBase *file : ctx->objectFiles)
visit(file);
- for (BitcodeFile *file : bitcodeFiles)
+ for (BitcodeFile *file : ctx->bitcodeFiles)
visit(file);
}
@@ -1826,10 +1820,10 @@ static void writeArchiveStats() {
SmallVector<StringRef, 0> archives;
DenseMap<CachedHashStringRef, unsigned> all, extracted;
- for (ELFFileBase *file : objectFiles)
+ for (ELFFileBase *file : ctx->objectFiles)
if (file->archiveName.size())
++extracted[CachedHashStringRef(file->archiveName)];
- for (BitcodeFile *file : bitcodeFiles)
+ for (BitcodeFile *file : ctx->bitcodeFiles)
if (file->archiveName.size())
++extracted[CachedHashStringRef(file->archiveName)];
for (std::pair<StringRef, unsigned> f : driver->archiveFiles) {
@@ -1953,7 +1947,7 @@ static void writeDependencyFile() {
// symbols of type CommonSymbol.
static void replaceCommonSymbols() {
llvm::TimeTraceScope timeScope("Replace common symbols");
- for (ELFFileBase *file : objectFiles) {
+ for (ELFFileBase *file : ctx->objectFiles) {
if (!file->hasCommonSyms)
continue;
for (Symbol *sym : file->getGlobalSymbols()) {
@@ -2029,7 +2023,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) {
// Visit the address-significance table in each object file and mark each
// referenced symbol as address-significant.
- for (InputFile *f : objectFiles) {
+ for (InputFile *f : ctx->objectFiles) {
auto *obj = cast<ObjFile<ELFT>>(f);
ArrayRef<Symbol *> syms = obj->getSymbols();
if (obj->addrsigSec) {
@@ -2115,18 +2109,18 @@ static void markBuffersAsDontNeed(bool skipLinkedOutput) {
// buffers as MADV_DONTNEED so that these pages can be reused by the expensive
// thin link, saving memory.
if (skipLinkedOutput) {
- for (MemoryBuffer &mb : llvm::make_pointee_range(memoryBuffers))
+ for (MemoryBuffer &mb : llvm::make_pointee_range(ctx->memoryBuffers))
mb.dontNeedIfMmap();
return;
}
// Otherwise, just mark MemoryBuffers backing BitcodeFiles.
DenseSet<const char *> bufs;
- for (BitcodeFile *file : bitcodeFiles)
+ for (BitcodeFile *file : ctx->bitcodeFiles)
bufs.insert(file->mb.getBufferStart());
- for (BitcodeFile *file : lazyBitcodeFiles)
+ for (BitcodeFile *file : ctx->lazyBitcodeFiles)
bufs.insert(file->mb.getBufferStart());
- for (MemoryBuffer &mb : llvm::make_pointee_range(memoryBuffers))
+ for (MemoryBuffer &mb : llvm::make_pointee_range(ctx->memoryBuffers))
if (bufs.count(mb.getBufferStart()))
mb.dontNeedIfMmap();
}
@@ -2143,10 +2137,10 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
llvm::TimeTraceScope timeScope("LTO");
// Compile bitcode files and replace bitcode symbols.
lto.reset(new BitcodeCompiler);
- for (BitcodeFile *file : bitcodeFiles)
+ for (BitcodeFile *file : ctx->bitcodeFiles)
lto->add(*file);
- if (!bitcodeFiles.empty())
+ if (!ctx->bitcodeFiles.empty())
markBuffersAsDontNeed(skipLinkedOutput);
for (InputFile *file : lto->compile()) {
@@ -2158,7 +2152,7 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
for (Symbol *sym : obj->getGlobalSymbols())
if (sym->hasVersionSuffix)
sym->parseSymbolVersion();
- objectFiles.push_back(obj);
+ ctx->objectFiles.push_back(obj);
}
}
@@ -2283,7 +2277,7 @@ static void redirectSymbols(ArrayRef<WrappedSymbol> wrapped) {
return;
// Update pointers in input files.
- parallelForEach(objectFiles, [&](ELFFileBase *file) {
+ parallelForEach(ctx->objectFiles, [&](ELFFileBase *file) {
for (Symbol *&sym : file->getMutableGlobalSymbols())
if (Symbol *s = map.lookup(sym))
sym = s;
@@ -2318,7 +2312,7 @@ static uint32_t getAndFeatures() {
return 0;
uint32_t ret = -1;
- for (ELFFileBase *f : objectFiles) {
+ for (ELFFileBase *f : ctx->objectFiles) {
uint32_t features = f->andFeatures;
checkAndReportMissingFeature(
@@ -2471,7 +2465,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
// We also need one if any shared libraries are used and for pie executables
// (probably because the dynamic linker needs it).
config->hasDynSymTab =
- !sharedFiles.empty() || config->isPic || config->exportDynamic;
+ !ctx->sharedFiles.empty() || config->isPic || config->exportDynamic;
// Some symbols (such as __ehdr_start) are defined lazily only when there
// are undefined symbols for them, so we add these to trigger that logic.
@@ -2517,7 +2511,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
// to, i.e. if the symbol's definition is in bitcode. Any other required
// libcall symbols will be added to the link after LTO when we add the LTO
// object file to the link.
- if (!bitcodeFiles.empty())
+ if (!ctx->bitcodeFiles.empty())
for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
handleLibcall(s);
@@ -2526,9 +2520,10 @@ void LinkerDriver::link(opt::InputArgList &args) {
// No more lazy bitcode can be extracted at this point. Do post parse work
// like checking duplicate symbols.
- parallelForEach(objectFiles, initializeLocalSymbols);
- parallelForEach(objectFiles, postParseObjectFile);
- parallelForEach(bitcodeFiles, [](BitcodeFile *file) { file->postParse(); });
+ parallelForEach(ctx->objectFiles, initializeLocalSymbols);
+ parallelForEach(ctx->objectFiles, postParseObjectFile);
+ parallelForEach(ctx->bitcodeFiles,
+ [](BitcodeFile *file) { file->postParse(); });
for (auto &it : ctx->nonPrevailingSyms) {
Symbol &sym = *it.first;
sym.replace(Undefined{sym.file, sym.getName(), sym.binding, sym.stOther,
@@ -2591,7 +2586,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
//
// With this the symbol table should be complete. After this, no new names
// except a few linker-synthesized ones will be added to the symbol table.
- const size_t numObjsBeforeLTO = objectFiles.size();
+ const size_t numObjsBeforeLTO = ctx->objectFiles.size();
invokeELFT(compileBitcodeFiles, skipLinkedOutput);
// Symbol resolution finished. Report backward reference problems,
@@ -2608,7 +2603,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
// compileBitcodeFiles may have produced lto.tmp object files. After this, no
// more file will be added.
- auto newObjectFiles = makeArrayRef(objectFiles).slice(numObjsBeforeLTO);
+ auto newObjectFiles = makeArrayRef(ctx->objectFiles).slice(numObjsBeforeLTO);
parallelForEach(newObjectFiles, initializeLocalSymbols);
parallelForEach(newObjectFiles, postParseObjectFile);
for (const DuplicateSymbol &d : ctx->duplicates)
@@ -2631,11 +2626,11 @@ void LinkerDriver::link(opt::InputArgList &args) {
// Now that we have a complete list of input files.
// Beyond this point, no new files are added.
// Aggregate all input sections into one place.
- for (InputFile *f : objectFiles)
+ for (InputFile *f : ctx->objectFiles)
for (InputSectionBase *s : f->getSections())
if (s && s != &InputSection::discarded)
inputSections.push_back(s);
- for (BinaryFile *f : binaryFiles)
+ for (BinaryFile *f : ctx->binaryFiles)
for (InputSectionBase *s : f->getSections())
inputSections.push_back(cast<InputSection>(s));
}
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 77d32db6718a1..64fb6cb5cd972 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -560,7 +560,7 @@ template <class ELFT> void ICF<ELFT>::run() {
};
for (Symbol *sym : symtab->symbols())
fold(sym);
- parallelForEach(objectFiles, [&](ELFFileBase *file) {
+ parallelForEach(ctx->objectFiles, [&](ELFFileBase *file) {
for (Symbol *sym : file->getLocalSymbols())
fold(sym);
});
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 25632e5cf0db2..0ea2a2c74b639 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -43,13 +43,6 @@ using namespace lld::elf;
bool InputFile::isInGroup;
uint32_t InputFile::nextGroupId;
-SmallVector<std::unique_ptr<MemoryBuffer>> elf::memoryBuffers;
-SmallVector<BinaryFile *, 0> elf::binaryFiles;
-SmallVector<BitcodeFile *, 0> elf::bitcodeFiles;
-SmallVector<BitcodeFile *, 0> elf::lazyBitcodeFiles;
-SmallVector<ELFFileBase *, 0> elf::objectFiles;
-SmallVector<SharedFile *, 0> elf::sharedFiles;
-
std::unique_ptr<TarWriter> elf::tar;
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
@@ -123,7 +116,7 @@ Optional<MemoryBufferRef> elf::readFile(StringRef path) {
}
MemoryBufferRef mbref = (*mbOrErr)->getMemBufferRef();
- memoryBuffers.push_back(std::move(*mbOrErr)); // take MB ownership
+ ctx->memoryBuffers.push_back(std::move(*mbOrErr)); // take MB ownership
if (tar)
tar->append(relativeToRoot(path), mbref.getBuffer());
@@ -152,12 +145,12 @@ static bool isCompatible(InputFile *file) {
}
InputFile *existing = nullptr;
- if (!objectFiles.empty())
- existing = objectFiles[0];
- else if (!sharedFiles.empty())
- existing = sharedFiles[0];
- else if (!bitcodeFiles.empty())
- existing = bitcodeFiles[0];
+ if (!ctx->objectFiles.empty())
+ existing = ctx->objectFiles[0];
+ else if (!ctx->sharedFiles.empty())
+ existing = ctx->sharedFiles[0];
+ else if (!ctx->bitcodeFiles.empty())
+ existing = ctx->bitcodeFiles[0];
std::string with;
if (existing)
with = " with " + toString(existing);
@@ -171,7 +164,7 @@ template <class ELFT> static void doParseFile(InputFile *file) {
// Binary file
if (auto *f = dyn_cast<BinaryFile>(file)) {
- binaryFiles.push_back(f);
+ ctx->binaryFiles.push_back(f);
f->parse();
return;
}
@@ -179,7 +172,7 @@ template <class ELFT> static void doParseFile(InputFile *file) {
// Lazy object file
if (file->lazy) {
if (auto *f = dyn_cast<BitcodeFile>(file)) {
- lazyBitcodeFiles.push_back(f);
+ ctx->lazyBitcodeFiles.push_back(f);
f->parseLazy();
} else {
cast<ObjFile<ELFT>>(file)->parseLazy();
@@ -198,13 +191,13 @@ template <class ELFT> static void doParseFile(InputFile *file) {
// LLVM bitcode file
if (auto *f = dyn_cast<BitcodeFile>(file)) {
- bitcodeFiles.push_back(f);
+ ctx->bitcodeFiles.push_back(f);
f->parse<ELFT>();
return;
}
// Regular object file
- objectFiles.push_back(cast<ELFFileBase>(file));
+ ctx->objectFiles.push_back(cast<ELFFileBase>(file));
cast<ObjFile<ELFT>>(file)->parse();
}
@@ -1397,7 +1390,7 @@ template <class ELFT> void SharedFile::parse() {
if (!wasInserted)
return;
- sharedFiles.push_back(this);
+ ctx->sharedFiles.push_back(this);
verdefs = parseVerdefs<ELFT>(obj.base(), verdefSec);
std::vector<uint32_t> verneeds = parseVerneed<ELFT>(obj, verneedSec);
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index 68129d0d298d1..f89246eb645e8 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -382,13 +382,6 @@ inline bool isBitcode(MemoryBufferRef mb) {
std::string replaceThinLTOSuffix(StringRef path);
-extern SmallVector<std::unique_ptr<MemoryBuffer>> memoryBuffers;
-extern SmallVector<BinaryFile *, 0> binaryFiles;
-extern SmallVector<BitcodeFile *, 0> bitcodeFiles;
-extern SmallVector<BitcodeFile *, 0> lazyBitcodeFiles;
-extern SmallVector<ELFFileBase *, 0> objectFiles;
-extern SmallVector<SharedFile *, 0> sharedFiles;
-
} // namespace elf
} // namespace lld
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 2975f44d0b661..e44ef0d3c2c86 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -208,7 +208,7 @@ BitcodeCompiler::BitcodeCompiler() {
config->ltoPartitions);
// Initialize usedStartStop.
- if (bitcodeFiles.empty())
+ if (ctx->bitcodeFiles.empty())
return;
for (Symbol *sym : symtab->symbols()) {
if (sym->isPlaceholder())
@@ -289,7 +289,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
// This is needed because this is what GNU gold plugin does and we have a
// distributed build system that depends on that behavior.
static void thinLTOCreateEmptyIndexFiles() {
- for (BitcodeFile *f : lazyBitcodeFiles) {
+ for (BitcodeFile *f : ctx->lazyBitcodeFiles) {
if (!f->lazy)
continue;
std::string path = replaceThinLTOSuffix(getThinLTOOutputFile(f->getName()));
@@ -323,7 +323,7 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
files[task] = std::move(mb);
}));
- if (!bitcodeFiles.empty())
+ if (!ctx->bitcodeFiles.empty())
checkError(ltoObj->run(
[&](size_t task) {
return std::make_unique<CachedFileStream>(
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index bcd897a83a82a..893511929a3a5 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -55,7 +55,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 (ELFFileBase *file : objectFiles)
+ for (ELFFileBase *file : ctx->objectFiles)
for (Symbol *b : file->getSymbols())
if (auto *dr = dyn_cast<Defined>(b))
if (!dr->isSection() && dr->section && dr->section->isLive() &&
@@ -224,7 +224,7 @@ static void writeMapFile(raw_fd_ostream &os) {
static void writeCref(raw_fd_ostream &os) {
// Collect symbols and files.
MapVector<Symbol *, SetVector<InputFile *>> map;
- for (ELFFileBase *file : objectFiles) {
+ for (ELFFileBase *file : ctx->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 42875c10cb2b7..12a23390e663b 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -345,7 +345,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 (ELFFileBase *file : objectFiles)
+ for (ELFFileBase *file : ctx->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 76d448fe471be..64381ae754146 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1695,7 +1695,7 @@ void elf::postScanRelocations() {
// Local symbols may need the aforementioned non-preemptible ifunc and GOT
// handling. They don't need regular PLT.
- for (ELFFileBase *file : objectFiles)
+ for (ELFFileBase *file : ctx->objectFiles)
for (Symbol *sym : file->getLocalSymbols())
fn(*sym);
}
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 091e038365274..b8a2ebeefce93 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1336,7 +1336,7 @@ DynamicSection<ELFT>::computeContents() {
addInt(config->enableNewDtags ? DT_RUNPATH : DT_RPATH,
part.dynStrTab->addString(config->rpath));
- for (SharedFile *file : sharedFiles)
+ for (SharedFile *file : ctx->sharedFiles)
if (file->isNeeded)
addInt(DT_NEEDED, part.dynStrTab->addString(file->soName));
@@ -1505,7 +1505,7 @@ DynamicSection<ELFT>::computeContents() {
if (part.verNeed && part.verNeed->isNeeded()) {
addInSec(DT_VERNEED, *part.verNeed);
unsigned needNum = 0;
- for (SharedFile *f : sharedFiles)
+ for (SharedFile *f : ctx->sharedFiles)
if (!f->vernauxs.empty())
++needNum;
addInt(DT_VERNEEDNUM, needNum);
@@ -3179,7 +3179,7 @@ VersionNeedSection<ELFT>::VersionNeedSection()
".gnu.version_r") {}
template <class ELFT> void VersionNeedSection<ELFT>::finalizeContents() {
- for (SharedFile *f : sharedFiles) {
+ for (SharedFile *f : ctx->sharedFiles) {
if (f->vernauxs.empty())
continue;
verneeds.emplace_back();
@@ -3349,7 +3349,7 @@ template <class ELFT> void elf::splitSections() {
llvm::TimeTraceScope timeScope("Split sections");
// splitIntoPieces needs to be called on each MergeInputSection
// before calling finalizeContents().
- parallelForEach(objectFiles, [](ELFFileBase *file) {
+ parallelForEach(ctx->objectFiles, [](ELFFileBase *file) {
for (InputSectionBase *sec : file->getSections()) {
if (!sec)
continue;
@@ -3717,9 +3717,9 @@ static uint8_t getAbiVersion() {
return 0;
}
- if (config->emachine == EM_AMDGPU && !objectFiles.empty()) {
- uint8_t ver = objectFiles[0]->abiVersion;
- for (InputFile *file : makeArrayRef(objectFiles).slice(1))
+ if (config->emachine == EM_AMDGPU && !ctx->objectFiles.empty()) {
+ uint8_t ver = ctx->objectFiles[0]->abiVersion;
+ for (InputFile *file : makeArrayRef(ctx->objectFiles).slice(1))
if (file->abiVersion != ver)
error("incompatible ABI version: " + toString(file));
return ver;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 5e2cf0713c406..7bfe29eda6958 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -623,7 +623,7 @@ template <class ELFT> static void markUsedLocalSymbols() {
// See MarkLive<ELFT>::resolveReloc().
if (config->gcSections)
return;
- for (ELFFileBase *file : objectFiles) {
+ for (ELFFileBase *file : ctx->objectFiles) {
ObjFile<ELFT> *f = cast<ObjFile<ELFT>>(file);
for (InputSectionBase *s : f->getSections()) {
InputSection *isec = dyn_cast_or_null<InputSection>(s);
@@ -694,7 +694,7 @@ template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
llvm::TimeTraceScope timeScope("Add local symbols");
if (config->copyRelocs && config->discard != DiscardPolicy::None)
markUsedLocalSymbols<ELFT>();
- for (ELFFileBase *file : objectFiles) {
+ for (ELFFileBase *file : ctx->objectFiles) {
for (Symbol *b : file->getLocalSymbols()) {
assert(b->isLocal() && "should have been caught in initializeSymbols()");
auto *dr = dyn_cast<Defined>(b);
@@ -1297,7 +1297,7 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
for (Symbol *sym : symtab->symbols())
addSym(*sym);
- for (ELFFileBase *file : objectFiles)
+ for (ELFFileBase *file : ctx->objectFiles)
for (Symbol *sym : file->getLocalSymbols())
addSym(*sym);
@@ -1697,7 +1697,7 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
// block sections, input sections can shrink when the jump instructions at
// the end of the section are relaxed.
static void fixSymbolsAfterShrinking() {
- for (InputFile *File : objectFiles) {
+ for (InputFile *File : ctx->objectFiles) {
parallelForEach(File->getSymbols(), [&](Symbol *Sym) {
auto *def = dyn_cast<Defined>(Sym);
if (!def)
@@ -1947,7 +1947,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// ld.bfd traces all DT_NEEDED to emulate the logic of the dynamic linker to
// catch more cases. That is too much for us. Our approach resembles the one
// used in ld.gold, achieves a good balance to be useful but not too smart.
- for (SharedFile *file : sharedFiles) {
+ for (SharedFile *file : ctx->sharedFiles) {
bool allNeededIsKnown =
llvm::all_of(file->dtNeeded, [&](StringRef needed) {
return symtab->soNames.count(CachedHashStringRef(needed));
More information about the llvm-commits
mailing list