[PATCH] D92456: [mac/lld] Make --reproduce work with thin archives

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 2 06:48:51 PST 2020


This revision was automatically updated to reflect the committed changes.
thakis marked 2 inline comments as done.
Closed by commit rGca634393fc79: [mac/lld] Make --reproduce work with thin archives (authored by thakis).
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D92456?vs=308862&id=308952#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92456/new/

https://reviews.llvm.org/D92456

Files:
  lld/MachO/Driver.cpp
  lld/MachO/InputFiles.cpp
  lld/test/MachO/reproduce-thin-archives.s


Index: lld/test/MachO/reproduce-thin-archives.s
===================================================================
--- /dev/null
+++ lld/test/MachO/reproduce-thin-archives.s
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %s -o %t.dir/foo.o
+# RUN: cd %t.dir
+# RUN: llvm-ar rcsT foo.a foo.o
+
+# RUN: %lld foo.a -o /dev/null --reproduce repro.tar
+# RUN: tar tf repro.tar | FileCheck -DPATH='repro/%:t.dir' %s
+
+# RUN: %lld -all_load foo.a -o /dev/null --reproduce repro2.tar
+# RUN: tar tf repro2.tar | FileCheck -DPATH='repro2/%:t.dir' %s
+
+# CHECK-DAG: [[PATH]]/foo.a
+# CHECK-DAG: [[PATH]]/foo.o
+
+.globl _main
+_main:
+  nop
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -610,6 +610,9 @@
                 ": could not get the buffer for the member defining symbol " +
                 toMachOString(sym));
 
+  if (tar && c.getParent()->isThin())
+    tar->append(relativeToRoot(CHECK(c.getFullName(), this)), mb.getBuffer());
+
   uint32_t modTime = toTimeT(
       CHECK(c.getLastModified(), toString(this) +
                                      ": could not get the modification time "
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -24,6 +24,7 @@
 #include "lld/Common/ErrorHandler.h"
 #include "lld/Common/LLVM.h"
 #include "lld/Common/Memory.h"
+#include "lld/Common/Reproduce.h"
 #include "lld/Common/Version.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringExtras.h"
@@ -230,11 +231,17 @@
 
   std::vector<ArchiveMember> v;
   Error err = Error::success();
+
+  // Thin archives refer to .o files, so --reproduces needs the .o files too.
+  bool addToTar = archive->isThin() && tar;
+
   for (const Archive::Child &c : archive->children(err)) {
     MemoryBufferRef mbref =
         CHECK(c.getMemoryBufferRef(),
               mb.getBufferIdentifier() +
                   ": could not get the buffer for a child of the archive");
+    if (addToTar)
+      tar->append(relativeToRoot(check(c.getFullName())), mbref.getBuffer());
     uint32_t modTime = toTimeT(
         CHECK(c.getLastModified(), mb.getBufferIdentifier() +
                                        ": could not get the modification "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92456.308952.patch
Type: text/x-patch
Size: 2441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201202/94a9f518/attachment.bin>


More information about the llvm-commits mailing list