Skip to content

Commit ba737e0

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

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lld/COFF/Driver.cpp

Lines changed: 14 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,14 @@ 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 is
397+
// useful for DTLTO, where having the member identifier be the actual
398+
// path on disk enables distribution of bitcode files during ThinLTO.
399+
addArchiveBuffer(mb, symName, /*parentName=*/"", /*OffsetInArchive=*/0);
400+
}
401+
394402
void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
395403
const Archive::Symbol &sym,
396404
StringRef parentName) {
@@ -427,11 +435,8 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
427435
reportBufferError(errorCodeToError(mbOrErr.second), childName);
428436
llvm::TimeTraceScope timeScope("Archive: ",
429437
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);
438+
ctx.driver.addThinArchiveBuffer(takeBuffer(std::move(mbOrErr.first)),
439+
toCOFFString(ctx, sym));
435440
});
436441
}
437442

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)