Skip to content

[LLD][COFF] Move getChunk to LinkerDriver (NFC) #123103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ llvm::Triple::ArchType LinkerDriver::getArch() {
return getMachineArchType(ctx.config.machine);
}

std::vector<Chunk *> LinkerDriver::getChunks() const {
std::vector<Chunk *> res;
for (ObjFile *file : ctx.objFileInstances) {
ArrayRef<Chunk *> 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;
Expand Down Expand Up @@ -1092,7 +1101,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {

// Get a list of all comdat sections for error checking.
DenseSet<StringRef> set;
for (Chunk *c : ctx.symtab.getChunks())
for (Chunk *c : ctx.driver.getChunks())
if (auto *sec = dyn_cast<SectionChunk>(c))
if (sec->sym)
set.insert(sec->sym->getName());
Expand Down
3 changes: 3 additions & 0 deletions lld/COFF/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class LinkerDriver {

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

// Returns a list of chunks of selected symbols.
std::vector<Chunk *> getChunks() const;

std::unique_ptr<llvm::TarWriter> tar; // for /linkrepro

void pullArm64ECIcallHelper();
Expand Down
2 changes: 1 addition & 1 deletion lld/COFF/ICF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SectionChunk>(c)) {
if (isEligible(sc))
chunks.push_back(sc);
Expand Down
2 changes: 1 addition & 1 deletion lld/COFF/MarkLive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SectionChunk>(c))
if (sc->live && !sc->isDWARF())
worklist.push_back(sc);
Expand Down
9 changes: 0 additions & 9 deletions lld/COFF/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,15 +945,6 @@ void SymbolTable::addLibcall(StringRef name) {
}
}

std::vector<Chunk *> SymbolTable::getChunks() const {
std::vector<Chunk *> res;
for (ObjFile *file : ctx.objFileInstances) {
ArrayRef<Chunk *> v = file->getChunks();
res.insert(res.end(), v.begin(), v.end());
}
return res;
}

Symbol *SymbolTable::find(StringRef name) const {
return symMap.lookup(CachedHashStringRef(name));
}
Expand Down
3 changes: 0 additions & 3 deletions lld/COFF/SymbolTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class SymbolTable {
void loadMinGWSymbols();
bool handleMinGWAutomaticImport(Symbol *sym, StringRef name);

// Returns a list of chunks of selected symbols.
std::vector<Chunk *> 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;
Expand Down
4 changes: 2 additions & 2 deletions lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SectionChunk>(c);
if (sc && !sc->live) {
if (ctx.config.verbose)
Expand Down Expand Up @@ -2217,7 +2217,7 @@ void Writer::createECChunks() {
void Writer::createRuntimePseudoRelocs() {
std::vector<RuntimePseudoReloc> rels;

for (Chunk *c : ctx.symtab.getChunks()) {
for (Chunk *c : ctx.driver.getChunks()) {
auto *sc = dyn_cast<SectionChunk>(c);
if (!sc || !sc->live)
continue;
Expand Down
Loading