[lld] b529921 - [lld-link] Do not assert when reporting error about non-thin archive (#159828)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 20 11:13:50 PDT 2025
Author: Nico Weber
Date: 2025-09-20T14:13:46-04:00
New Revision: b5299210f29da7432adaf3b48332c93b9cace3b0
URL: https://github.com/llvm/llvm-project/commit/b5299210f29da7432adaf3b48332c93b9cace3b0
DIFF: https://github.com/llvm/llvm-project/commit/b5299210f29da7432adaf3b48332c93b9cace3b0.diff
LOG: [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.
Added:
Modified:
lld/COFF/Driver.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 948dd7a96c7a5..a59cc06d51836 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -404,7 +404,11 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
const Archive::Symbol &sym,
StringRef parentName) {
- auto reportBufferError = [=](Error &&e, StringRef childName) {
+ auto reportBufferError = [=](Error &&e) {
+ StringRef childName =
+ CHECK(c.getName(),
+ "could not get child name for archive " + parentName +
+ " while loading symbol " + toCOFFString(ctx, sym));
Fatal(ctx) << "could not get the buffer for the member defining symbol "
<< &sym << ": " << parentName << "(" << childName
<< "): " << std::move(e);
@@ -414,7 +418,7 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
uint64_t offsetInArchive = c.getChildOffset();
Expected<MemoryBufferRef> mbOrErr = c.getMemoryBufferRef();
if (!mbOrErr)
- reportBufferError(mbOrErr.takeError(), check(c.getFullName()));
+ reportBufferError(mbOrErr.takeError());
MemoryBufferRef mb = mbOrErr.get();
enqueueTask([=]() {
llvm::TimeTraceScope timeScope("Archive: ", mb.getBufferIdentifier());
@@ -433,7 +437,7 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
enqueueTask([=]() {
auto mbOrErr = future->get();
if (mbOrErr.second)
- reportBufferError(errorCodeToError(mbOrErr.second), childName);
+ reportBufferError(errorCodeToError(mbOrErr.second));
llvm::TimeTraceScope timeScope("Archive: ",
mbOrErr.first->getBufferIdentifier());
ctx.driver.addThinArchiveBuffer(takeBuffer(std::move(mbOrErr.first)),
More information about the llvm-commits
mailing list