Skip to content

Commit 89db92c

Browse files
committed
[LLD][COFF] Make /wholearchive thin-archive member identifiers consistent
A thin archive is an archive/library format where the archive itself contains only references to member object files on disk, rather than embedding the file contents. For the non-/wholearchive case, we use the path to the archive member as the identifier for thin-archive members (see comments in `enqueueArchiveMember`). This patch modifies the /wholearchive path to behave the same way. Apart from consistency, my motivation for fixing this is DTLTO (#126654), where having the member identifier be the path on disk allows distribution of bitcode members during ThinLTO.
1 parent 389e9d3 commit 89db92c

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

lld/COFF/Driver.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
275275

276276
int memberIndex = 0;
277277
for (MemoryBufferRef m : getArchiveMembers(ctx, archive))
278-
addArchiveBuffer(m, "<whole-archive>", filename, memberIndex++);
278+
if (!archive->isThin())
279+
addArchiveBuffer(m, "<whole-archive>", filename, memberIndex++);
280+
else
281+
// Pass empty string as archive name so that the original filename is
282+
// used as the buffer identifier.
283+
addArchiveBuffer(m, "<whole-archive>", "", /*OffsetInArchive=*/0);
279284
return;
280285
}
281286
addFile(make<ArchiveFile>(ctx, mbref));

lld/test/COFF/thin-archive.s

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,34 @@
2222
# SYMTAB: ?f@@YAHXZ in
2323
# NO-SYMTAB-NOT: ?f@@YAHXZ in
2424

25-
# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
26-
# RUN: FileCheck --allow-empty %s
27-
# RUN: lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \
28-
# RUN: FileCheck --allow-empty %s
29-
# RUN: lld-link /entry:main %t.main.obj /wholearchive:%t_thin.lib /out:%t.exe 2>&1 | \
30-
# RUN: FileCheck --allow-empty %s
25+
# RUN: echo /entry:main %t.main.obj /out:%t.exe > %t.rsp
26+
27+
# RUN: lld-link @%t.rsp %t.lib /verbose 2>&1 | \
28+
# RUN: FileCheck %s --check-prefix=LOAD_NON_THIN
29+
# RUN: lld-link @%t.rsp %t_thin.lib /verbose 2>&1 | \
30+
# RUN: FileCheck %s --check-prefix=LOAD_THIN_SYM
31+
# RUN: lld-link @%t.rsp /wholearchive:%t_thin.lib /verbose 2>&1 | \
32+
# RUN: FileCheck %s --check-prefix=LOAD_THIN_WHOLE
33+
# RUN: lld-link @%t.rsp /wholearchive %t_thin.lib /verbose 2>&1 | \
34+
# RUN: FileCheck %s --check-prefix=LOAD_THIN_WHOLE
35+
36+
# LOAD_NON_THIN: Loaded {{.*}}.lib({{.*}}.obj) for int __cdecl f(void)
37+
# LOAD_THIN_SYM: Loaded {{.*}}.obj for int __cdecl f(void)
38+
# LOAD_THIN_WHOLE: Loaded {{.*}}.obj for <whole-archive>
3139

3240
# RUN: rm %t.lib.obj
33-
# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
34-
# RUN: FileCheck --allow-empty %s
35-
# RUN: env LLD_IN_TEST=1 not lld-link /entry:main %t.main.obj %t_thin.lib \
36-
# RUN: /out:%t.exe 2>&1 | FileCheck --check-prefix=NOOBJ %s
37-
# RUN: env LLD_IN_TEST=1 not lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe \
38-
# RUN: /demangle:no 2>&1 | FileCheck --check-prefix=NOOBJNODEMANGLE %s
39-
40-
# CHECK-NOT: error: could not get the buffer for the member defining
41+
# RUN: lld-link @%t.rsp %t.lib /out:%t.exe 2>&1 | \
42+
# RUN: FileCheck --check-prefix=ERR --allow-empty %s
43+
# RUN: env LLD_IN_TEST=1 not lld-link @%t.rsp %t_thin.lib 2>&1 | \
44+
# RUN: FileCheck --check-prefix=NOOBJ %s
45+
# RUN: env LLD_IN_TEST=1 not lld-link @%t.rsp /wholearchive:%t_thin.lib 2>&1 | \
46+
# RUN: FileCheck --check-prefix=NOOBJWHOLE %s
47+
# RUN: env LLD_IN_TEST=1 not lld-link @%t.rsp %t_thin.lib /demangle:no 2>&1 | \
48+
# RUN: FileCheck --check-prefix=NOOBJNODEMANGLE %s
49+
50+
# ERR-NOT: error: could not get the buffer for the member defining
4151
# NOOBJ: error: could not get the buffer for the member defining symbol int __cdecl f(void): {{.*}}.lib({{.*}}.lib.obj):
52+
# NOOBJWHOLE: error: {{.*}}.lib: could not get the buffer for a child of the archive: '{{.*}}.obj': no such file or directory
4253
# NOOBJNODEMANGLE: error: could not get the buffer for the member defining symbol ?f@@YAHXZ: {{.*}}.lib({{.*}}.lib.obj):
4354

4455
.text

0 commit comments

Comments
 (0)