[lld] [lld-macho] Fix unchecked Error crash for thin archive missing child (PR #97169)
Daniel Bertalan via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 29 09:59:28 PDT 2024
https://github.com/BertalanD created https://github.com/llvm/llvm-project/pull/97169
The repro file in #94716 contains a few thin archives without their member object files present. I couldn't figure out why this happened (issue in repro tarball generation?), but this caused an "unhandled Error" crash on `LLVM_ENABLE_ABI_BREAKING_CHECKS` builds.
>From 059c08241e6af264242fe0c3fffe23ac19f34021 Mon Sep 17 00:00:00 2001
From: Daniel Bertalan <dani at danielbertalan.dev>
Date: Sat, 29 Jun 2024 18:47:06 +0200
Subject: [PATCH] [lld-macho] Fix unchecked Error crash for thin archive
missing child
The repro file in #94716 contains a few thin archives without their
member object files present. I couldn't figure out why this happened
(issue in repro tarball generation?), but this caused an "unhandled
Error" crash on `LLVM_ENABLE_ABI_BREAKING_CHECKS` builds.
---
lld/MachO/Driver.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 9dddabcf3680c..eb64e764100b2 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -349,7 +349,12 @@ static InputFile *addFile(StringRef path, LoadType loadType,
Error e = Error::success();
for (const object::Archive::Child &c : file->getArchive().children(e)) {
Expected<MemoryBufferRef> mb = c.getMemoryBufferRef();
- if (!mb || !hasObjCSection(*mb))
+ if (!mb) {
+ llvm::consumeError(mb.takeError());
+ continue;
+ }
+
+ if (!hasObjCSection(*mb))
continue;
if (Error e = file->fetch(c, "-ObjC"))
error(toString(file) + ": -ObjC failed to load archive member: " +
More information about the llvm-commits
mailing list