diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 0de4c8ff5b25..8b1a8dc3e5af 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -175,6 +175,15 @@ llvm::Triple::ArchType LinkerDriver::getArch() { return getMachineArchType(ctx.config.machine); } +std::vector LinkerDriver::getChunks() const { + std::vector res; + for (ObjFile *file : ctx.objFileInstances) { + ArrayRef v = file->getChunks(); + res.insert(res.end(), v.begin(), v.end()); + } + return res; +} + static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) { if (mt == IMAGE_FILE_MACHINE_UNKNOWN) return true; @@ -1093,7 +1102,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) { // Get a list of all comdat sections for error checking. DenseSet set; - for (Chunk *c : ctx.symtab.getChunks()) + for (Chunk *c : ctx.driver.getChunks()) if (auto *sec = dyn_cast(c)) if (sec->sym) set.insert(sec->sym->getName()); diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h index 4558f68c041f..8ce2e13129ba 100644 --- a/lld/COFF/Driver.h +++ b/lld/COFF/Driver.h @@ -94,6 +94,9 @@ public: void enqueuePath(StringRef path, bool wholeArchive, bool lazy); + // Returns a list of chunks of selected symbols. + std::vector getChunks() const; + std::unique_ptr tar; // for /linkrepro void pullArm64ECIcallHelper(); diff --git a/lld/COFF/ICF.cpp b/lld/COFF/ICF.cpp index 796d3a4108ba..e6c965160e4e 100644 --- a/lld/COFF/ICF.cpp +++ b/lld/COFF/ICF.cpp @@ -264,7 +264,7 @@ void ICF::run() { // Collect only mergeable sections and group by hash value. uint32_t nextId = 1; - for (Chunk *c : ctx.symtab.getChunks()) { + for (Chunk *c : ctx.driver.getChunks()) { if (auto *sc = dyn_cast(c)) { if (isEligible(sc)) chunks.push_back(sc); diff --git a/lld/COFF/MarkLive.cpp b/lld/COFF/MarkLive.cpp index 3c09baa73a9f..ad50536892eb 100644 --- a/lld/COFF/MarkLive.cpp +++ b/lld/COFF/MarkLive.cpp @@ -31,7 +31,7 @@ void markLive(COFFLinkerContext &ctx) { // COMDAT section chunks are dead by default. Add non-COMDAT chunks. Do not // traverse DWARF sections. They are live, but they should not keep other // sections alive. - for (Chunk *c : ctx.symtab.getChunks()) + for (Chunk *c : ctx.driver.getChunks()) if (auto *sc = dyn_cast(c)) if (sc->live && !sc->isDWARF()) worklist.push_back(sc); diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index 7c43ada3d136..36dcd0dfe138 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -945,15 +945,6 @@ void SymbolTable::addLibcall(StringRef name) { } } -std::vector SymbolTable::getChunks() const { - std::vector res; - for (ObjFile *file : ctx.objFileInstances) { - ArrayRef v = file->getChunks(); - res.insert(res.end(), v.begin(), v.end()); - } - return res; -} - Symbol *SymbolTable::find(StringRef name) const { return symMap.lookup(CachedHashStringRef(name)); } diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h index 809b5d9dfea3..9e316fcdbe63 100644 --- a/lld/COFF/SymbolTable.h +++ b/lld/COFF/SymbolTable.h @@ -67,9 +67,6 @@ public: void loadMinGWSymbols(); bool handleMinGWAutomaticImport(Symbol *sym, StringRef name); - // Returns a list of chunks of selected symbols. - std::vector getChunks() const; - // Returns a symbol for a given name. Returns a nullptr if not found. Symbol *find(StringRef name) const; Symbol *findUnderscore(StringRef name) const; diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 1fb5b7292f05..8247f131dcf0 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -1077,7 +1077,7 @@ void Writer::createSections() { dtorsSec = createSection(".dtors", data | r | w); // Then bin chunks by name and output characteristics. - for (Chunk *c : ctx.symtab.getChunks()) { + for (Chunk *c : ctx.driver.getChunks()) { auto *sc = dyn_cast(c); if (sc && !sc->live) { if (ctx.config.verbose) @@ -2219,7 +2219,7 @@ void Writer::createECChunks() { void Writer::createRuntimePseudoRelocs() { std::vector rels; - for (Chunk *c : ctx.symtab.getChunks()) { + for (Chunk *c : ctx.driver.getChunks()) { auto *sc = dyn_cast(c); if (!sc || !sc->live) continue;