Author: Nico Weber Date: 2020-12-02T09:48:31-05:00 New Revision: ca634393fc797f766a68e8537e20a1bf0ec8ca94
URL: https://github.com/llvm/llvm-project/commit/ca634393fc797f766a68e8537e20a1bf0ec8ca94 DIFF: https://github.com/llvm/llvm-project/commit/ca634393fc797f766a68e8537e20a1bf0ec8ca94.diff LOG: [mac/lld] Make --reproduce work with thin archives See http://reviews.llvm.org/rL268229 and http://reviews.llvm.org/rL313832 which did the same for the ELF port. Differential Revision: https://reviews.llvm.org/D92456 Added: lld/test/MachO/reproduce-thin-archives.s Modified: lld/MachO/Driver.cpp lld/MachO/InputFiles.cpp Removed: ################################################################################ diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index c3b8224750ab..426101f4f9e1 100644 --- a/lld/MachO/Driver.cpp +++ b/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 @@ static std::vector<ArchiveMember> getArchiveMembers(MemoryBufferRef mb) { 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 " diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index 3a87a42ded08..4fd9873bcbd3 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -610,6 +610,9 @@ void ArchiveFile::fetch(const object::Archive::Symbol &sym) { ": 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 " diff --git a/lld/test/MachO/reproduce-thin-archives.s b/lld/test/MachO/reproduce-thin-archives.s new file mode 100644 index 000000000000..9dee3f400e06 --- /dev/null +++ b/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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits