Skip to content

Commit 9242077

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 (llvm#126654), where having the member identifier be the path on disk allows distribution of bitcode members during ThinLTO. (cherry picked from commit 0a670a3) Signed-off-by: Dunbobbin <Ben.Dunbobbin@sony.com>
1 parent 389e9d3 commit 9242077

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@
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 /verbose > %t.rsp
26+
27+
# RUN: lld-link @%t.rsp %t.lib 2>&1 | \
28+
# RUN: FileCheck --allow-empty %s --check-prefixes=CHECK,LOAD_NON_THIN
29+
# RUN: lld-link @%t.rsp %t_thin.lib 2>&1 | \
30+
# RUN: FileCheck --allow-empty %s --check-prefixes=CHECK,LOAD_THIN_SYM
31+
# RUN: lld-link @%t.rsp /wholearchive:%t_thin.lib 2>&1 | \
32+
# RUN: FileCheck --allow-empty %s --check-prefixes=CHECK,LOAD_THIN_WHOLE
33+
# RUN: lld-link @%t.rsp /wholearchive %t_thin.lib 2>&1 | \
34+
# RUN: FileCheck --allow-empty %s --check-prefixes=CHECK,LOAD_THIN_WHOLE
35+
36+
# LOAD_NON_THIN: Loaded thin-archive{{.*}}.lib(thin-archive{{.*}}.obj) for int __cdecl f(void)
37+
# LOAD_THIN_SYM: Loaded {{.*}}thin-archive{{.*}}.obj for int __cdecl f(void)
38+
# LOAD_THIN_WHOLE: Loaded {{.*}}thin-archive{{.*}}.obj for <whole-archive>
3139

3240
# RUN: rm %t.lib.obj
3341
# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \

0 commit comments

Comments
 (0)