[PATCH] D57974: [lld-link] better error message when failing to open archive members

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 8 13:37:41 PST 2019


inglorion created this revision.
inglorion added a reviewer: ruiu.
Herald added a project: LLVM.
inglorion added a comment.

Before:

  lld-link: error: could not get the buffer for the member defining symbol spvDiagnosticDestroy: No such file or directory

After:

  lld-link: error: could not get the buffer for the member defining symbol spvDiagnosticDestroy: obj/third_party/SPIRV-Tools/src/spvtools.lib(obj/third_party/SPIRV-Tools/src/obj/third_party/SPIRV-Tools/src/spvtools/diagnostic.obj): No such file or directory


The message "could not get the buffer for the member defining symbol"
now also contains the name of the archive and the name of the archive
member that we tried to open.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D57974

Files:
  lld/COFF/Driver.cpp


Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -224,23 +224,39 @@
 void LinkerDriver::enqueueArchiveMember(const Archive::Child &C,
                                         StringRef SymName,
                                         StringRef ParentName) {
+
+  auto ReportBufferError = [](Error &&E,
+                              StringRef SymName,
+                              StringRef ParentName,
+                              StringRef ChildName) {
+    fatal("could not get the buffer for the member defining symbol " +
+          SymName + ": " + ParentName + "(" + ChildName + "): " +
+          toString(std::move(E)));
+  };
+
   if (!C.getParent()->isThin()) {
-    MemoryBufferRef MB = CHECK(
-        C.getMemoryBufferRef(),
-        "could not get the buffer for the member defining symbol " + SymName);
+    Expected<MemoryBufferRef> MBOrErr = C.getMemoryBufferRef();
+    if (!MBOrErr)
+      ReportBufferError(MBOrErr.takeError(), SymName, ParentName,
+                        check(C.getFullName()));
+    MemoryBufferRef MB = MBOrErr.get();
     enqueueTask([=]() { Driver->addArchiveBuffer(MB, SymName, ParentName); });
     return;
   }
 
-  auto Future = std::make_shared<std::future<MBErrPair>>(createFutureForFile(
-      CHECK(C.getFullName(),
-            "could not get the filename for the member defining symbol " +
-                SymName)));
+  std::string ChildName = CHECK(
+      C.getFullName(),
+      "could not get the filename for the member defining symbol " +
+      SymName);
+  auto Future = std::make_shared<std::future<MBErrPair>>(
+      createFutureForFile(ChildName));
   enqueueTask([=]() {
     auto MBOrErr = Future->get();
     if (MBOrErr.second)
-      fatal("could not get the buffer for the member defining " + SymName +
-            ": " + MBOrErr.second.message());
+      ReportBufferError(errorCodeToError(MBOrErr.second),
+                        SymName,
+                        ParentName,
+                        ChildName);
     Driver->addArchiveBuffer(takeBuffer(std::move(MBOrErr.first)), SymName,
                              ParentName);
   });


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57974.186038.patch
Type: text/x-patch
Size: 2222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190208/6012a2f3/attachment.bin>


More information about the llvm-commits mailing list