Skip to content

Commit 8df4e6c

Browse files
committed
Use common function to add thin archive members. Improve comment explaining parameter choice.
1 parent c244331 commit 8df4e6c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lld/COFF/Driver.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,13 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
274274
make<std::unique_ptr<Archive>>(std::move(file)); // take ownership
275275

276276
int memberIndex = 0;
277-
for (MemoryBufferRef m : getArchiveMembers(ctx, archive))
277+
for (MemoryBufferRef m : getArchiveMembers(ctx, archive)) {
278278
if (!archive->isThin())
279279
addArchiveBuffer(m, "<whole-archive>", filename, memberIndex++);
280280
else
281-
// Pass empty string as archive name so that the original filename is
282-
// used as the buffer identifier.
283-
addArchiveBuffer(m, "<whole-archive>", "", /*OffsetInArchive=*/0);
281+
addThinArchiveBuffer(m, "<whole-archive>");
282+
}
283+
284284
return;
285285
}
286286
addFile(make<ArchiveFile>(ctx, mbref));
@@ -391,6 +391,16 @@ void LinkerDriver::addArchiveBuffer(MemoryBufferRef mb, StringRef symName,
391391
Log(ctx) << "Loaded " << obj << " for " << symName;
392392
}
393393

394+
void LinkerDriver::addThinArchiveBuffer(MemoryBufferRef mb, StringRef symName) {
395+
// Pass an empty string as the archive name and an offset of 0 so that
396+
// the original filename is used as the buffer identifier. This
397+
// ensures the naming of thin archive members is consistent with the
398+
// non-`whole-archive` path, and is useful for DTLTO, where having the
399+
// member identifier be the actual path on disk enables distribution
400+
// of bitcode files during ThinLTO.
401+
addArchiveBuffer(mb, symName, /*parentName=*/"", /*OffsetInArchive=*/0);
402+
}
403+
394404
void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
395405
const Archive::Symbol &sym,
396406
StringRef parentName) {
@@ -427,11 +437,8 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
427437
reportBufferError(errorCodeToError(mbOrErr.second), childName);
428438
llvm::TimeTraceScope timeScope("Archive: ",
429439
mbOrErr.first->getBufferIdentifier());
430-
// Pass empty string as archive name so that the original filename is
431-
// used as the buffer identifier.
432-
ctx.driver.addArchiveBuffer(takeBuffer(std::move(mbOrErr.first)),
433-
toCOFFString(ctx, sym), "",
434-
/*OffsetInArchive=*/0);
440+
ctx.driver.addThinArchiveBuffer(takeBuffer(std::move(mbOrErr.first)),
441+
toCOFFString(ctx, sym));
435442
});
436443
}
437444

lld/COFF/Driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class LinkerDriver {
173173
bool lazy);
174174
void addArchiveBuffer(MemoryBufferRef mbref, StringRef symName,
175175
StringRef parentName, uint64_t offsetInArchive);
176+
void addThinArchiveBuffer(MemoryBufferRef mbref, StringRef symName);
176177

177178
void enqueueTask(std::function<void()> task);
178179
bool run();

0 commit comments

Comments
 (0)