Skip to content

Commit 1bd5f34

Browse files
authored
[LLD][COFF] Move getChunk to LinkerDriver (NFC) (#123103)
The `getChunk` function returns all chunks, not just those specific to a symbol table. Move it out of the `SymbolTable` class to clarify its scope.
1 parent d004947 commit 1bd5f34

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

lld/COFF/Driver.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ llvm::Triple::ArchType LinkerDriver::getArch() {
175175
return getMachineArchType(ctx.config.machine);
176176
}
177177

178+
std::vector<Chunk *> LinkerDriver::getChunks() const {
179+
std::vector<Chunk *> res;
180+
for (ObjFile *file : ctx.objFileInstances) {
181+
ArrayRef<Chunk *> v = file->getChunks();
182+
res.insert(res.end(), v.begin(), v.end());
183+
}
184+
return res;
185+
}
186+
178187
static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) {
179188
if (mt == IMAGE_FILE_MACHINE_UNKNOWN)
180189
return true;
@@ -1093,7 +1102,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
10931102

10941103
// Get a list of all comdat sections for error checking.
10951104
DenseSet<StringRef> set;
1096-
for (Chunk *c : ctx.symtab.getChunks())
1105+
for (Chunk *c : ctx.driver.getChunks())
10971106
if (auto *sec = dyn_cast<SectionChunk>(c))
10981107
if (sec->sym)
10991108
set.insert(sec->sym->getName());

lld/COFF/Driver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class LinkerDriver {
9494

9595
void enqueuePath(StringRef path, bool wholeArchive, bool lazy);
9696

97+
// Returns a list of chunks of selected symbols.
98+
std::vector<Chunk *> getChunks() const;
99+
97100
std::unique_ptr<llvm::TarWriter> tar; // for /linkrepro
98101

99102
void pullArm64ECIcallHelper();

lld/COFF/ICF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void ICF::run() {
264264

265265
// Collect only mergeable sections and group by hash value.
266266
uint32_t nextId = 1;
267-
for (Chunk *c : ctx.symtab.getChunks()) {
267+
for (Chunk *c : ctx.driver.getChunks()) {
268268
if (auto *sc = dyn_cast<SectionChunk>(c)) {
269269
if (isEligible(sc))
270270
chunks.push_back(sc);

lld/COFF/MarkLive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void markLive(COFFLinkerContext &ctx) {
3131
// COMDAT section chunks are dead by default. Add non-COMDAT chunks. Do not
3232
// traverse DWARF sections. They are live, but they should not keep other
3333
// sections alive.
34-
for (Chunk *c : ctx.symtab.getChunks())
34+
for (Chunk *c : ctx.driver.getChunks())
3535
if (auto *sc = dyn_cast<SectionChunk>(c))
3636
if (sc->live && !sc->isDWARF())
3737
worklist.push_back(sc);

lld/COFF/SymbolTable.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -945,15 +945,6 @@ void SymbolTable::addLibcall(StringRef name) {
945945
}
946946
}
947947

948-
std::vector<Chunk *> SymbolTable::getChunks() const {
949-
std::vector<Chunk *> res;
950-
for (ObjFile *file : ctx.objFileInstances) {
951-
ArrayRef<Chunk *> v = file->getChunks();
952-
res.insert(res.end(), v.begin(), v.end());
953-
}
954-
return res;
955-
}
956-
957948
Symbol *SymbolTable::find(StringRef name) const {
958949
return symMap.lookup(CachedHashStringRef(name));
959950
}

lld/COFF/SymbolTable.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ class SymbolTable {
6767
void loadMinGWSymbols();
6868
bool handleMinGWAutomaticImport(Symbol *sym, StringRef name);
6969

70-
// Returns a list of chunks of selected symbols.
71-
std::vector<Chunk *> getChunks() const;
72-
7370
// Returns a symbol for a given name. Returns a nullptr if not found.
7471
Symbol *find(StringRef name) const;
7572
Symbol *findUnderscore(StringRef name) const;

lld/COFF/Writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ void Writer::createSections() {
10771077
dtorsSec = createSection(".dtors", data | r | w);
10781078

10791079
// Then bin chunks by name and output characteristics.
1080-
for (Chunk *c : ctx.symtab.getChunks()) {
1080+
for (Chunk *c : ctx.driver.getChunks()) {
10811081
auto *sc = dyn_cast<SectionChunk>(c);
10821082
if (sc && !sc->live) {
10831083
if (ctx.config.verbose)
@@ -2219,7 +2219,7 @@ void Writer::createECChunks() {
22192219
void Writer::createRuntimePseudoRelocs() {
22202220
std::vector<RuntimePseudoReloc> rels;
22212221

2222-
for (Chunk *c : ctx.symtab.getChunks()) {
2222+
for (Chunk *c : ctx.driver.getChunks()) {
22232223
auto *sc = dyn_cast<SectionChunk>(c);
22242224
if (!sc || !sc->live)
22252225
continue;

0 commit comments

Comments
 (0)