[lld] [lld-link] Do not assert when reporting error about non-thin archive (PR #159828)
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 19 11:35:00 PDT 2025
https://github.com/nico updated https://github.com/llvm/llvm-project/pull/159828
>From d9ca58e06b212c7f3da9d8d5b330bce75dc3f3da Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Fri, 19 Sep 2025 14:27:13 -0400
Subject: [PATCH 1/2] [lld-link] Do not assert when reporting error about
non-thin archive
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.
---
lld/COFF/Driver.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index acba156ce341d..fc6073dc3ec4e 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -404,9 +404,9 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
const Archive::Symbol &sym,
StringRef parentName) {
- auto reportBufferError = [=](Error &&e, StringRef childName) {
+ auto reportBufferError = [=](Error &&e) {
Fatal(ctx) << "could not get the buffer for the member defining symbol "
- << &sym << ": " << parentName << "(" << childName
+ << &sym << ": " << parentName << "(" << check(c.getName())
<< "): " << std::move(e);
};
@@ -414,7 +414,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 +433,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)),
>From 35515ffe55f6f0383b2a82ac06cb14ddf23e2690 Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Fri, 19 Sep 2025 14:34:49 -0400
Subject: [PATCH 2/2] CHECK for child name too
---
lld/COFF/Driver.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index fc6073dc3ec4e..a515b39dcae03 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -405,8 +405,12 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
StringRef parentName) {
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 << "(" << check(c.getName())
+ << &sym << ": " << parentName << "(" << childName
<< "): " << std::move(e);
};
More information about the llvm-commits
mailing list