[lld] [lld/COFF] Support thin archives in /reproduce: files (PR #121512)
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 2 10:24:48 PST 2025
https://github.com/nico created https://github.com/llvm/llvm-project/pull/121512
This already worked without /wholearchive; now it works with it too. (Only for thin archives containing relative file names, matching the ELF and Mach-O ports.)
>From c8c4b4033a725f202856a3afc0d36ef5fc9928bc Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Thu, 2 Jan 2025 13:21:44 -0500
Subject: [PATCH] [lld/COFF] Support thin archives in /reproduce: files
This already worked without /wholearchive; now it works with it
too. (Only for thin archives containing relative file names, matching
the ELF and Mach-O ports.)
---
lld/COFF/InputFiles.cpp | 8 ++++++++
lld/test/COFF/linkrepro-thin-archives.s | 23 +++++++++++++++++++++++
2 files changed, 31 insertions(+)
create mode 100644 lld/test/COFF/linkrepro-thin-archives.s
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index e698f66b84f623..a94c984cfd4870 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -149,11 +149,19 @@ std::vector<MemoryBufferRef>
lld::coff::getArchiveMembers(COFFLinkerContext &ctx, Archive *file) {
std::vector<MemoryBufferRef> v;
Error err = Error::success();
+
+ // Thin archives refer to .o files, so --reproduces needs the .o files too.
+ bool addToTar = file->isThin() && ctx.driver.tar;
+
for (const Archive::Child &c : file->children(err)) {
MemoryBufferRef mbref =
CHECK(c.getMemoryBufferRef(),
file->getFileName() +
": could not get the buffer for a child of the archive");
+ if (addToTar) {
+ ctx.driver.tar->append(relativeToRoot(check(c.getFullName())),
+ mbref.getBuffer());
+ }
v.push_back(mbref);
}
if (err)
diff --git a/lld/test/COFF/linkrepro-thin-archives.s b/lld/test/COFF/linkrepro-thin-archives.s
new file mode 100644
index 00000000000000..6fde36b84e0af0
--- /dev/null
+++ b/lld/test/COFF/linkrepro-thin-archives.s
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+
+# RUN: rm -rf %t.dir; split-file %s %t.dir
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-windows %t.dir/foo.s -o %t.dir/foo.obj
+# RUN: cd %t.dir
+# RUN: llvm-ar rcsT foo.lib foo.obj
+
+# RUN: lld-link foo.lib /out:/dev/null /reproduce:repro.tar \
+# RUN: /subsystem:console /machine:x64
+# RUN: tar tf repro.tar | FileCheck -DPATH='repro/%:t.dir' %s
+
+# RUN: lld-link /wholearchive foo.lib /out:/dev/null /reproduce:repro2.tar \
+# RUN: /subsystem:console /machine:x64
+# RUN: tar tf repro2.tar | FileCheck -DPATH='repro2/%:t.dir' %s
+
+# CHECK-DAG: [[PATH]]/foo.lib
+# CHECK-DAG: [[PATH]]/foo.obj
+
+#--- foo.s
+.globl mainCRTStartup
+mainCRTStartup:
+ nop
More information about the llvm-commits
mailing list