@@ -97,12 +97,6 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
9797 ctx->e .cleanupCallback = []() {
9898 inputSections.clear ();
9999 outputSections.clear ();
100- memoryBuffers.clear ();
101- binaryFiles.clear ();
102- bitcodeFiles.clear ();
103- lazyBitcodeFiles.clear ();
104- objectFiles.clear ();
105- sharedFiles.clear ();
106100 symAux.clear ();
107101
108102 tar = nullptr ;
@@ -198,7 +192,7 @@ std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
198192
199193 // Take ownership of memory buffers created for members of thin archives.
200194 std::vector<std::unique_ptr<MemoryBuffer>> mbs = file->takeThinBuffers ();
201- std::move (mbs.begin (), mbs.end (), std::back_inserter (memoryBuffers));
195+ std::move (mbs.begin (), mbs.end (), std::back_inserter (ctx-> memoryBuffers ));
202196
203197 return v;
204198}
@@ -843,7 +837,7 @@ static std::pair<bool, bool> getPackDynRelocs(opt::InputArgList &args) {
843837static void readCallGraph (MemoryBufferRef mb) {
844838 // Build a map from symbol name to section
845839 DenseMap<StringRef, Symbol *> map;
846- for (ELFFileBase *file : objectFiles)
840+ for (ELFFileBase *file : ctx-> objectFiles )
847841 for (Symbol *sym : file->getSymbols ())
848842 map[sym->getName ()] = sym;
849843
@@ -922,7 +916,7 @@ processCallGraphRelocations(SmallVector<uint32_t, 32> &symbolIndices,
922916template <class ELFT > static void readCallGraphsFromObjectFiles () {
923917 SmallVector<uint32_t , 32 > symbolIndices;
924918 ArrayRef<typename ELFT::CGProfile> cgProfile;
925- for (auto file : objectFiles) {
919+ for (auto file : ctx-> objectFiles ) {
926920 auto *obj = cast<ObjFile<ELFT>>(file);
927921 if (!processCallGraphRelocations (symbolIndices, cgProfile, obj))
928922 continue ;
@@ -1757,10 +1751,10 @@ static void excludeLibs(opt::InputArgList &args) {
17571751 sym->versionId = VER_NDX_LOCAL;
17581752 };
17591753
1760- for (ELFFileBase *file : objectFiles)
1754+ for (ELFFileBase *file : ctx-> objectFiles )
17611755 visit (file);
17621756
1763- for (BitcodeFile *file : bitcodeFiles)
1757+ for (BitcodeFile *file : ctx-> bitcodeFiles )
17641758 visit (file);
17651759}
17661760
@@ -1826,10 +1820,10 @@ static void writeArchiveStats() {
18261820
18271821 SmallVector<StringRef, 0 > archives;
18281822 DenseMap<CachedHashStringRef, unsigned > all, extracted;
1829- for (ELFFileBase *file : objectFiles)
1823+ for (ELFFileBase *file : ctx-> objectFiles )
18301824 if (file->archiveName .size ())
18311825 ++extracted[CachedHashStringRef (file->archiveName )];
1832- for (BitcodeFile *file : bitcodeFiles)
1826+ for (BitcodeFile *file : ctx-> bitcodeFiles )
18331827 if (file->archiveName .size ())
18341828 ++extracted[CachedHashStringRef (file->archiveName )];
18351829 for (std::pair<StringRef, unsigned > f : driver->archiveFiles ) {
@@ -1953,7 +1947,7 @@ static void writeDependencyFile() {
19531947// symbols of type CommonSymbol.
19541948static void replaceCommonSymbols () {
19551949 llvm::TimeTraceScope timeScope (" Replace common symbols" );
1956- for (ELFFileBase *file : objectFiles) {
1950+ for (ELFFileBase *file : ctx-> objectFiles ) {
19571951 if (!file->hasCommonSyms )
19581952 continue ;
19591953 for (Symbol *sym : file->getGlobalSymbols ()) {
@@ -2029,7 +2023,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) {
20292023
20302024 // Visit the address-significance table in each object file and mark each
20312025 // referenced symbol as address-significant.
2032- for (InputFile *f : objectFiles) {
2026+ for (InputFile *f : ctx-> objectFiles ) {
20332027 auto *obj = cast<ObjFile<ELFT>>(f);
20342028 ArrayRef<Symbol *> syms = obj->getSymbols ();
20352029 if (obj->addrsigSec ) {
@@ -2115,18 +2109,18 @@ static void markBuffersAsDontNeed(bool skipLinkedOutput) {
21152109 // buffers as MADV_DONTNEED so that these pages can be reused by the expensive
21162110 // thin link, saving memory.
21172111 if (skipLinkedOutput) {
2118- for (MemoryBuffer &mb : llvm::make_pointee_range (memoryBuffers))
2112+ for (MemoryBuffer &mb : llvm::make_pointee_range (ctx-> memoryBuffers ))
21192113 mb.dontNeedIfMmap ();
21202114 return ;
21212115 }
21222116
21232117 // Otherwise, just mark MemoryBuffers backing BitcodeFiles.
21242118 DenseSet<const char *> bufs;
2125- for (BitcodeFile *file : bitcodeFiles)
2119+ for (BitcodeFile *file : ctx-> bitcodeFiles )
21262120 bufs.insert (file->mb .getBufferStart ());
2127- for (BitcodeFile *file : lazyBitcodeFiles)
2121+ for (BitcodeFile *file : ctx-> lazyBitcodeFiles )
21282122 bufs.insert (file->mb .getBufferStart ());
2129- for (MemoryBuffer &mb : llvm::make_pointee_range (memoryBuffers))
2123+ for (MemoryBuffer &mb : llvm::make_pointee_range (ctx-> memoryBuffers ))
21302124 if (bufs.count (mb.getBufferStart ()))
21312125 mb.dontNeedIfMmap ();
21322126}
@@ -2143,10 +2137,10 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
21432137 llvm::TimeTraceScope timeScope (" LTO" );
21442138 // Compile bitcode files and replace bitcode symbols.
21452139 lto.reset (new BitcodeCompiler);
2146- for (BitcodeFile *file : bitcodeFiles)
2140+ for (BitcodeFile *file : ctx-> bitcodeFiles )
21472141 lto->add (*file);
21482142
2149- if (!bitcodeFiles.empty ())
2143+ if (!ctx-> bitcodeFiles .empty ())
21502144 markBuffersAsDontNeed (skipLinkedOutput);
21512145
21522146 for (InputFile *file : lto->compile ()) {
@@ -2158,7 +2152,7 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
21582152 for (Symbol *sym : obj->getGlobalSymbols ())
21592153 if (sym->hasVersionSuffix )
21602154 sym->parseSymbolVersion ();
2161- objectFiles.push_back (obj);
2155+ ctx-> objectFiles .push_back (obj);
21622156 }
21632157}
21642158
@@ -2283,7 +2277,7 @@ static void redirectSymbols(ArrayRef<WrappedSymbol> wrapped) {
22832277 return ;
22842278
22852279 // Update pointers in input files.
2286- parallelForEach (objectFiles, [&](ELFFileBase *file) {
2280+ parallelForEach (ctx-> objectFiles , [&](ELFFileBase *file) {
22872281 for (Symbol *&sym : file->getMutableGlobalSymbols ())
22882282 if (Symbol *s = map.lookup (sym))
22892283 sym = s;
@@ -2318,7 +2312,7 @@ static uint32_t getAndFeatures() {
23182312 return 0 ;
23192313
23202314 uint32_t ret = -1 ;
2321- for (ELFFileBase *f : objectFiles) {
2315+ for (ELFFileBase *f : ctx-> objectFiles ) {
23222316 uint32_t features = f->andFeatures ;
23232317
23242318 checkAndReportMissingFeature (
@@ -2471,7 +2465,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
24712465 // We also need one if any shared libraries are used and for pie executables
24722466 // (probably because the dynamic linker needs it).
24732467 config->hasDynSymTab =
2474- !sharedFiles.empty () || config->isPic || config->exportDynamic ;
2468+ !ctx-> sharedFiles .empty () || config->isPic || config->exportDynamic ;
24752469
24762470 // Some symbols (such as __ehdr_start) are defined lazily only when there
24772471 // are undefined symbols for them, so we add these to trigger that logic.
@@ -2517,7 +2511,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
25172511 // to, i.e. if the symbol's definition is in bitcode. Any other required
25182512 // libcall symbols will be added to the link after LTO when we add the LTO
25192513 // object file to the link.
2520- if (!bitcodeFiles.empty ())
2514+ if (!ctx-> bitcodeFiles .empty ())
25212515 for (auto *s : lto::LTO::getRuntimeLibcallSymbols ())
25222516 handleLibcall (s);
25232517
@@ -2526,9 +2520,10 @@ void LinkerDriver::link(opt::InputArgList &args) {
25262520
25272521 // No more lazy bitcode can be extracted at this point. Do post parse work
25282522 // like checking duplicate symbols.
2529- parallelForEach (objectFiles, initializeLocalSymbols);
2530- parallelForEach (objectFiles, postParseObjectFile);
2531- parallelForEach (bitcodeFiles, [](BitcodeFile *file) { file->postParse (); });
2523+ parallelForEach (ctx->objectFiles , initializeLocalSymbols);
2524+ parallelForEach (ctx->objectFiles , postParseObjectFile);
2525+ parallelForEach (ctx->bitcodeFiles ,
2526+ [](BitcodeFile *file) { file->postParse (); });
25322527 for (auto &it : ctx->nonPrevailingSyms ) {
25332528 Symbol &sym = *it.first ;
25342529 sym.replace (Undefined{sym.file , sym.getName (), sym.binding , sym.stOther ,
@@ -2591,7 +2586,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
25912586 //
25922587 // With this the symbol table should be complete. After this, no new names
25932588 // except a few linker-synthesized ones will be added to the symbol table.
2594- const size_t numObjsBeforeLTO = objectFiles.size ();
2589+ const size_t numObjsBeforeLTO = ctx-> objectFiles .size ();
25952590 invokeELFT (compileBitcodeFiles, skipLinkedOutput);
25962591
25972592 // Symbol resolution finished. Report backward reference problems,
@@ -2608,7 +2603,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
26082603
26092604 // compileBitcodeFiles may have produced lto.tmp object files. After this, no
26102605 // more file will be added.
2611- auto newObjectFiles = makeArrayRef (objectFiles).slice (numObjsBeforeLTO);
2606+ auto newObjectFiles = makeArrayRef (ctx-> objectFiles ).slice (numObjsBeforeLTO);
26122607 parallelForEach (newObjectFiles, initializeLocalSymbols);
26132608 parallelForEach (newObjectFiles, postParseObjectFile);
26142609 for (const DuplicateSymbol &d : ctx->duplicates )
@@ -2631,11 +2626,11 @@ void LinkerDriver::link(opt::InputArgList &args) {
26312626 // Now that we have a complete list of input files.
26322627 // Beyond this point, no new files are added.
26332628 // Aggregate all input sections into one place.
2634- for (InputFile *f : objectFiles)
2629+ for (InputFile *f : ctx-> objectFiles )
26352630 for (InputSectionBase *s : f->getSections ())
26362631 if (s && s != &InputSection::discarded)
26372632 inputSections.push_back (s);
2638- for (BinaryFile *f : binaryFiles)
2633+ for (BinaryFile *f : ctx-> binaryFiles )
26392634 for (InputSectionBase *s : f->getSections ())
26402635 inputSections.push_back (cast<InputSection>(s));
26412636 }
0 commit comments