Skip to content

Commit 6cd171d

Browse files
authored
[lld/COFF] Support thin archives in /reproduce: files (#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.)
1 parent 119fc72 commit 6cd171d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lld/COFF/InputFiles.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,19 @@ std::vector<MemoryBufferRef>
149149
lld::coff::getArchiveMembers(COFFLinkerContext &ctx, Archive *file) {
150150
std::vector<MemoryBufferRef> v;
151151
Error err = Error::success();
152+
153+
// Thin archives refer to .o files, so --reproduces needs the .o files too.
154+
bool addToTar = file->isThin() && ctx.driver.tar;
155+
152156
for (const Archive::Child &c : file->children(err)) {
153157
MemoryBufferRef mbref =
154158
CHECK(c.getMemoryBufferRef(),
155159
file->getFileName() +
156160
": could not get the buffer for a child of the archive");
161+
if (addToTar) {
162+
ctx.driver.tar->append(relativeToRoot(check(c.getFullName())),
163+
mbref.getBuffer());
164+
}
157165
v.push_back(mbref);
158166
}
159167
if (err)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# REQUIRES: x86
2+
3+
# RUN: rm -rf %t.dir; split-file %s %t.dir
4+
5+
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-windows %t.dir/foo.s -o %t.dir/foo.obj
6+
# RUN: cd %t.dir
7+
# RUN: llvm-ar rcsT foo.lib foo.obj
8+
9+
# RUN: lld-link foo.lib /out:/dev/null /reproduce:repro.tar \
10+
# RUN: /subsystem:console /machine:x64
11+
# RUN: tar tf repro.tar | FileCheck -DPATH='repro/%:t.dir' %s
12+
13+
# RUN: lld-link /wholearchive foo.lib /out:/dev/null /reproduce:repro2.tar \
14+
# RUN: /subsystem:console /machine:x64
15+
# RUN: tar tf repro2.tar | FileCheck -DPATH='repro2/%:t.dir' %s
16+
17+
# CHECK-DAG: [[PATH]]/foo.lib
18+
# CHECK-DAG: [[PATH]]/foo.obj
19+
20+
#--- foo.s
21+
.globl mainCRTStartup
22+
mainCRTStartup:
23+
nop

0 commit comments

Comments
 (0)