@@ -97,12 +97,6 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
97
97
ctx->e .cleanupCallback = []() {
98
98
inputSections.clear ();
99
99
outputSections.clear ();
100
- memoryBuffers.clear ();
101
- binaryFiles.clear ();
102
- bitcodeFiles.clear ();
103
- lazyBitcodeFiles.clear ();
104
- objectFiles.clear ();
105
- sharedFiles.clear ();
106
100
symAux.clear ();
107
101
108
102
tar = nullptr ;
@@ -198,7 +192,7 @@ std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
198
192
199
193
// Take ownership of memory buffers created for members of thin archives.
200
194
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 ));
202
196
203
197
return v;
204
198
}
@@ -843,7 +837,7 @@ static std::pair<bool, bool> getPackDynRelocs(opt::InputArgList &args) {
843
837
static void readCallGraph (MemoryBufferRef mb) {
844
838
// Build a map from symbol name to section
845
839
DenseMap<StringRef, Symbol *> map;
846
- for (ELFFileBase *file : objectFiles)
840
+ for (ELFFileBase *file : ctx-> objectFiles )
847
841
for (Symbol *sym : file->getSymbols ())
848
842
map[sym->getName ()] = sym;
849
843
@@ -922,7 +916,7 @@ processCallGraphRelocations(SmallVector<uint32_t, 32> &symbolIndices,
922
916
template <class ELFT > static void readCallGraphsFromObjectFiles () {
923
917
SmallVector<uint32_t , 32 > symbolIndices;
924
918
ArrayRef<typename ELFT::CGProfile> cgProfile;
925
- for (auto file : objectFiles) {
919
+ for (auto file : ctx-> objectFiles ) {
926
920
auto *obj = cast<ObjFile<ELFT>>(file);
927
921
if (!processCallGraphRelocations (symbolIndices, cgProfile, obj))
928
922
continue ;
@@ -1757,10 +1751,10 @@ static void excludeLibs(opt::InputArgList &args) {
1757
1751
sym->versionId = VER_NDX_LOCAL;
1758
1752
};
1759
1753
1760
- for (ELFFileBase *file : objectFiles)
1754
+ for (ELFFileBase *file : ctx-> objectFiles )
1761
1755
visit (file);
1762
1756
1763
- for (BitcodeFile *file : bitcodeFiles)
1757
+ for (BitcodeFile *file : ctx-> bitcodeFiles )
1764
1758
visit (file);
1765
1759
}
1766
1760
@@ -1826,10 +1820,10 @@ static void writeArchiveStats() {
1826
1820
1827
1821
SmallVector<StringRef, 0 > archives;
1828
1822
DenseMap<CachedHashStringRef, unsigned > all, extracted;
1829
- for (ELFFileBase *file : objectFiles)
1823
+ for (ELFFileBase *file : ctx-> objectFiles )
1830
1824
if (file->archiveName .size ())
1831
1825
++extracted[CachedHashStringRef (file->archiveName )];
1832
- for (BitcodeFile *file : bitcodeFiles)
1826
+ for (BitcodeFile *file : ctx-> bitcodeFiles )
1833
1827
if (file->archiveName .size ())
1834
1828
++extracted[CachedHashStringRef (file->archiveName )];
1835
1829
for (std::pair<StringRef, unsigned > f : driver->archiveFiles ) {
@@ -1953,7 +1947,7 @@ static void writeDependencyFile() {
1953
1947
// symbols of type CommonSymbol.
1954
1948
static void replaceCommonSymbols () {
1955
1949
llvm::TimeTraceScope timeScope (" Replace common symbols" );
1956
- for (ELFFileBase *file : objectFiles) {
1950
+ for (ELFFileBase *file : ctx-> objectFiles ) {
1957
1951
if (!file->hasCommonSyms )
1958
1952
continue ;
1959
1953
for (Symbol *sym : file->getGlobalSymbols ()) {
@@ -2029,7 +2023,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) {
2029
2023
2030
2024
// Visit the address-significance table in each object file and mark each
2031
2025
// referenced symbol as address-significant.
2032
- for (InputFile *f : objectFiles) {
2026
+ for (InputFile *f : ctx-> objectFiles ) {
2033
2027
auto *obj = cast<ObjFile<ELFT>>(f);
2034
2028
ArrayRef<Symbol *> syms = obj->getSymbols ();
2035
2029
if (obj->addrsigSec ) {
@@ -2115,18 +2109,18 @@ static void markBuffersAsDontNeed(bool skipLinkedOutput) {
2115
2109
// buffers as MADV_DONTNEED so that these pages can be reused by the expensive
2116
2110
// thin link, saving memory.
2117
2111
if (skipLinkedOutput) {
2118
- for (MemoryBuffer &mb : llvm::make_pointee_range (memoryBuffers))
2112
+ for (MemoryBuffer &mb : llvm::make_pointee_range (ctx-> memoryBuffers ))
2119
2113
mb.dontNeedIfMmap ();
2120
2114
return ;
2121
2115
}
2122
2116
2123
2117
// Otherwise, just mark MemoryBuffers backing BitcodeFiles.
2124
2118
DenseSet<const char *> bufs;
2125
- for (BitcodeFile *file : bitcodeFiles)
2119
+ for (BitcodeFile *file : ctx-> bitcodeFiles )
2126
2120
bufs.insert (file->mb .getBufferStart ());
2127
- for (BitcodeFile *file : lazyBitcodeFiles)
2121
+ for (BitcodeFile *file : ctx-> lazyBitcodeFiles )
2128
2122
bufs.insert (file->mb .getBufferStart ());
2129
- for (MemoryBuffer &mb : llvm::make_pointee_range (memoryBuffers))
2123
+ for (MemoryBuffer &mb : llvm::make_pointee_range (ctx-> memoryBuffers ))
2130
2124
if (bufs.count (mb.getBufferStart ()))
2131
2125
mb.dontNeedIfMmap ();
2132
2126
}
@@ -2143,10 +2137,10 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
2143
2137
llvm::TimeTraceScope timeScope (" LTO" );
2144
2138
// Compile bitcode files and replace bitcode symbols.
2145
2139
lto.reset (new BitcodeCompiler);
2146
- for (BitcodeFile *file : bitcodeFiles)
2140
+ for (BitcodeFile *file : ctx-> bitcodeFiles )
2147
2141
lto->add (*file);
2148
2142
2149
- if (!bitcodeFiles.empty ())
2143
+ if (!ctx-> bitcodeFiles .empty ())
2150
2144
markBuffersAsDontNeed (skipLinkedOutput);
2151
2145
2152
2146
for (InputFile *file : lto->compile ()) {
@@ -2158,7 +2152,7 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
2158
2152
for (Symbol *sym : obj->getGlobalSymbols ())
2159
2153
if (sym->hasVersionSuffix )
2160
2154
sym->parseSymbolVersion ();
2161
- objectFiles.push_back (obj);
2155
+ ctx-> objectFiles .push_back (obj);
2162
2156
}
2163
2157
}
2164
2158
@@ -2283,7 +2277,7 @@ static void redirectSymbols(ArrayRef<WrappedSymbol> wrapped) {
2283
2277
return ;
2284
2278
2285
2279
// Update pointers in input files.
2286
- parallelForEach (objectFiles, [&](ELFFileBase *file) {
2280
+ parallelForEach (ctx-> objectFiles , [&](ELFFileBase *file) {
2287
2281
for (Symbol *&sym : file->getMutableGlobalSymbols ())
2288
2282
if (Symbol *s = map.lookup (sym))
2289
2283
sym = s;
@@ -2318,7 +2312,7 @@ static uint32_t getAndFeatures() {
2318
2312
return 0 ;
2319
2313
2320
2314
uint32_t ret = -1 ;
2321
- for (ELFFileBase *f : objectFiles) {
2315
+ for (ELFFileBase *f : ctx-> objectFiles ) {
2322
2316
uint32_t features = f->andFeatures ;
2323
2317
2324
2318
checkAndReportMissingFeature (
@@ -2471,7 +2465,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
2471
2465
// We also need one if any shared libraries are used and for pie executables
2472
2466
// (probably because the dynamic linker needs it).
2473
2467
config->hasDynSymTab =
2474
- !sharedFiles.empty () || config->isPic || config->exportDynamic ;
2468
+ !ctx-> sharedFiles .empty () || config->isPic || config->exportDynamic ;
2475
2469
2476
2470
// Some symbols (such as __ehdr_start) are defined lazily only when there
2477
2471
// are undefined symbols for them, so we add these to trigger that logic.
@@ -2517,7 +2511,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
2517
2511
// to, i.e. if the symbol's definition is in bitcode. Any other required
2518
2512
// libcall symbols will be added to the link after LTO when we add the LTO
2519
2513
// object file to the link.
2520
- if (!bitcodeFiles.empty ())
2514
+ if (!ctx-> bitcodeFiles .empty ())
2521
2515
for (auto *s : lto::LTO::getRuntimeLibcallSymbols ())
2522
2516
handleLibcall (s);
2523
2517
@@ -2526,9 +2520,10 @@ void LinkerDriver::link(opt::InputArgList &args) {
2526
2520
2527
2521
// No more lazy bitcode can be extracted at this point. Do post parse work
2528
2522
// 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 (); });
2532
2527
for (auto &it : ctx->nonPrevailingSyms ) {
2533
2528
Symbol &sym = *it.first ;
2534
2529
sym.replace (Undefined{sym.file , sym.getName (), sym.binding , sym.stOther ,
@@ -2591,7 +2586,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
2591
2586
//
2592
2587
// With this the symbol table should be complete. After this, no new names
2593
2588
// 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 ();
2595
2590
invokeELFT (compileBitcodeFiles, skipLinkedOutput);
2596
2591
2597
2592
// Symbol resolution finished. Report backward reference problems,
@@ -2608,7 +2603,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
2608
2603
2609
2604
// compileBitcodeFiles may have produced lto.tmp object files. After this, no
2610
2605
// more file will be added.
2611
- auto newObjectFiles = makeArrayRef (objectFiles).slice (numObjsBeforeLTO);
2606
+ auto newObjectFiles = makeArrayRef (ctx-> objectFiles ).slice (numObjsBeforeLTO);
2612
2607
parallelForEach (newObjectFiles, initializeLocalSymbols);
2613
2608
parallelForEach (newObjectFiles, postParseObjectFile);
2614
2609
for (const DuplicateSymbol &d : ctx->duplicates )
@@ -2631,11 +2626,11 @@ void LinkerDriver::link(opt::InputArgList &args) {
2631
2626
// Now that we have a complete list of input files.
2632
2627
// Beyond this point, no new files are added.
2633
2628
// Aggregate all input sections into one place.
2634
- for (InputFile *f : objectFiles)
2629
+ for (InputFile *f : ctx-> objectFiles )
2635
2630
for (InputSectionBase *s : f->getSections ())
2636
2631
if (s && s != &InputSection::discarded)
2637
2632
inputSections.push_back (s);
2638
- for (BinaryFile *f : binaryFiles)
2633
+ for (BinaryFile *f : ctx-> binaryFiles )
2639
2634
for (InputSectionBase *s : f->getSections ())
2640
2635
inputSections.push_back (cast<InputSection>(s));
2641
2636
}
0 commit comments