Skip to content

Commit 89efb03

Browse files
committed
[LLD][COFF] Add index to disambiguate archive members when using -wholearchive
Patch by Markus Böck. PR42951: When linking an archive with members that have the same name linking fails when using the -wholearchive option. This patch passes the index of the member in the archive to the offset parameter to disambiguate the member. Differential Revision: https://reviews.llvm.org/D66239 llvm-svn: 371509
1 parent c2d292f commit 89efb03

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lld/COFF/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
188188
Archive *archive = file.get();
189189
make<std::unique_ptr<Archive>>(std::move(file)); // take ownership
190190

191+
int memberIndex = 0;
191192
for (MemoryBufferRef m : getArchiveMembers(archive))
192-
addArchiveBuffer(m, "<whole-archive>", filename, 0);
193+
addArchiveBuffer(m, "<whole-archive>", filename, memberIndex++);
193194
return;
194195
}
195196
symtab->addFile(make<ArchiveFile>(mbref));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; REQUIRES: x86
2+
; RUN: rm -fr %T/thinlto-whole-archives
3+
; RUN: mkdir %T/thinlto-whole-archives %T/thinlto-whole-archives/a %T/thinlto-whole-archives/b
4+
; RUN: opt -thinlto-bc -o %T/thinlto-whole-archives/main.obj %s
5+
; RUN: opt -thinlto-bc -o %T/thinlto-whole-archives/a/bar.obj %S/Inputs/lto-dep.ll
6+
; RUN: opt -thinlto-bc -o %T/thinlto-whole-archives/b/bar.obj %S/Inputs/bar.ll
7+
; RUN: llvm-ar crs %T/thinlto-whole-archives/a.lib %T/thinlto-whole-archives/a/bar.obj %T/thinlto-whole-archives/b/bar.obj
8+
; RUN: lld-link -out:%T/thinlto-whole-archives/main.exe -entry:main \
9+
; RUN: -wholearchive -lldsavetemps -subsystem:console %T/thinlto-whole-archives/main.obj \
10+
; RUN: %T/thinlto-whole-archives/a.lib
11+
; RUN: FileCheck %s < %T/thinlto-whole-archives/main.exe.resolution.txt
12+
13+
; CHECK: {{[/\\]thinlto-whole-archives[/\\]main.obj$}}
14+
; CHECK: {{^-r=.*[/\\]thinlto-whole-archives[/\\]main.obj,main,px$}}
15+
; CHECK: {{[/\\]thinlto-whole-archives[/\\]a.libbar.obj[0-9]+$}}
16+
; CHECK-NEXT: {{^-r=.*[/\\]thinlto-whole-archives[/\\]a.libbar.obj[0-9]+,foo,p$}}
17+
; CHECK-NEXT: {{[/\\]thinlto-whole-archives[/\\]a.libbar.obj[0-9]+$}}
18+
; CHECK-NEXT: {{^-r=.*[/\\]thinlto-whole-archives[/\\]a.libbar.obj[0-9]+,bar,p$}}
19+
20+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
21+
target triple = "x86_64-pc-windows-msvc"
22+
23+
declare void @bar()
24+
declare void @foo()
25+
26+
define i32 @main() {
27+
call void @foo()
28+
call void @bar()
29+
ret i32 0
30+
}

0 commit comments

Comments
 (0)