Skip to content

Commit b529921

Browse files
authored
[lld-link] Do not assert when reporting error about non-thin archive (#159828)
Follow-up to https://reviews.llvm.org/D57974, which added calls to Archive::Child::getFullName() to produce strings in errors. But getFullName() is only valid on thin archives, and should only be used to open the file the archive points to. For diagnostics, getName() is better: It works for both thin and non-thin files, and it doesn't make a very long string for thin files. And we already prepend the name of the parent archive file anyways.
1 parent f847c2a commit b529921

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lld/COFF/Driver.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
404404
const Archive::Symbol &sym,
405405
StringRef parentName) {
406406

407-
auto reportBufferError = [=](Error &&e, StringRef childName) {
407+
auto reportBufferError = [=](Error &&e) {
408+
StringRef childName =
409+
CHECK(c.getName(),
410+
"could not get child name for archive " + parentName +
411+
" while loading symbol " + toCOFFString(ctx, sym));
408412
Fatal(ctx) << "could not get the buffer for the member defining symbol "
409413
<< &sym << ": " << parentName << "(" << childName
410414
<< "): " << std::move(e);
@@ -414,7 +418,7 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
414418
uint64_t offsetInArchive = c.getChildOffset();
415419
Expected<MemoryBufferRef> mbOrErr = c.getMemoryBufferRef();
416420
if (!mbOrErr)
417-
reportBufferError(mbOrErr.takeError(), check(c.getFullName()));
421+
reportBufferError(mbOrErr.takeError());
418422
MemoryBufferRef mb = mbOrErr.get();
419423
enqueueTask([=]() {
420424
llvm::TimeTraceScope timeScope("Archive: ", mb.getBufferIdentifier());
@@ -433,7 +437,7 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
433437
enqueueTask([=]() {
434438
auto mbOrErr = future->get();
435439
if (mbOrErr.second)
436-
reportBufferError(errorCodeToError(mbOrErr.second), childName);
440+
reportBufferError(errorCodeToError(mbOrErr.second));
437441
llvm::TimeTraceScope timeScope("Archive: ",
438442
mbOrErr.first->getBufferIdentifier());
439443
ctx.driver.addThinArchiveBuffer(takeBuffer(std::move(mbOrErr.first)),

0 commit comments

Comments
 (0)