[lld] [lld-macho] Support archives without index (PR #132942)

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 8 07:32:03 PDT 2025


================
@@ -2156,9 +2156,34 @@ ArchiveFile::ArchiveFile(std::unique_ptr<object::Archive> &&f, bool forceHidden)
 void ArchiveFile::addLazySymbols() {
   // Avoid calling getMemoryBufferRef() on zero-symbol archive
   // since that crashes.
-  if (file->isEmpty() || file->getNumberOfSymbols() == 0)
+  if (file->isEmpty())
     return;
 
+  if (file->getNumberOfSymbols() == 0) {
+    // No index, treat each child as a lazy object file.
+    Error e = Error::success();
+    for (const object::Archive::Child &c : file->children(e)) {
+      // Check `seen` but don't insert so a future eager load can still happen.
----------------
nico wrote:

This is for when we first read a .a but it's then `-all_load` / `-force_load`ed later, yes?

Do we parse all .o files a second time then? (In any case, this isn't something that we expect to happen in practice, yes?)

(ps: good tests for this)

https://github.com/llvm/llvm-project/pull/132942


More information about the llvm-commits mailing list