Skip to content

Commit 0b1413a

Browse files
committed
Use the archive offset with --whole-archive.
The test ELF/lto/thin-archivecollision.ll was not testing what it wanted to test. It needs two archive members with the same name, but different offsets. Without this we could remove all references of OffsetInArchive and all tests would still pass. Fixing the test showed that the --whole-archive case was broken, which this patch fixes. llvm-svn: 302241
1 parent 921ab75 commit 0b1413a

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lld/ELF/Driver.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef Emul) {
123123

124124
// Returns slices of MB by parsing MB as an archive file.
125125
// Each slice consists of a member file in the archive.
126-
std::vector<MemoryBufferRef>
127-
static getArchiveMembers(MemoryBufferRef MB) {
126+
std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
127+
MemoryBufferRef MB) {
128128
std::unique_ptr<Archive> File =
129129
check(Archive::create(MB),
130130
MB.getBufferIdentifier() + ": failed to parse archive");
131131

132-
std::vector<MemoryBufferRef> V;
132+
std::vector<std::pair<MemoryBufferRef, uint64_t>> V;
133133
Error Err = Error::success();
134134
for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) {
135135
Archive::Child C =
@@ -139,7 +139,7 @@ static getArchiveMembers(MemoryBufferRef MB) {
139139
check(C.getMemoryBufferRef(),
140140
MB.getBufferIdentifier() +
141141
": could not get the buffer for a child of the archive");
142-
V.push_back(MBRef);
142+
V.push_back(std::make_pair(MBRef, C.getChildOffset()));
143143
}
144144
if (Err)
145145
fatal(MB.getBufferIdentifier() + ": Archive::children failed: " +
@@ -173,8 +173,8 @@ void LinkerDriver::addFile(StringRef Path, bool WithLOption) {
173173
case file_magic::archive: {
174174
// Handle -whole-archive.
175175
if (InWholeArchive) {
176-
for (MemoryBufferRef MB : getArchiveMembers(MBRef))
177-
Files.push_back(createObjectFile(MB, Path));
176+
for (const auto &P : getArchiveMembers(MBRef))
177+
Files.push_back(createObjectFile(P.first, Path, P.second));
178178
return;
179179
}
180180

@@ -186,8 +186,8 @@ void LinkerDriver::addFile(StringRef Path, bool WithLOption) {
186186
// understand the LLVM bitcode file. It is a pretty common error, so
187187
// we'll handle it as if it had a symbol table.
188188
if (!File->hasSymbolTable()) {
189-
for (MemoryBufferRef MB : getArchiveMembers(MBRef))
190-
Files.push_back(make<LazyObjectFile>(MB, MBRef.getBufferIdentifier()));
189+
for (const auto &P : getArchiveMembers(MBRef))
190+
Files.push_back(make<LazyObjectFile>(P.first, Path));
191191
return;
192192
}
193193

lld/test/ELF/lto/thin-archivecollision.ll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
; RUN: opt -module-summary %s -o %t.o
2-
; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t.coll.o
3-
; RUN: llvm-ar rcs %t1.a %t.coll.o
4-
; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t.coll.o
5-
; RUN: llvm-ar rcsc %t2.a %t.coll.o
2+
; RUN: mkdir -p %t1 %t2
3+
; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t1/t.coll.o
4+
; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t2/t.coll.o
5+
; RUN: rm -f %t.a
6+
; RUN: llvm-ar rcs %t.a %t1/t.coll.o %t2/t.coll.o
67

7-
; RUN: ld.lld %t.o %t1.a %t2.a -o %t
8+
; RUN: ld.lld %t.o %t.a -o %t
89
; RUN: llvm-nm %t | FileCheck %s
910

1011
; Check we handle this case correctly even in presence of --whole-archive.
11-
; RUN: ld.lld %t.o --whole-archive %t1.a %t2.a -o %t
12+
; RUN: ld.lld %t.o --whole-archive %t.a -o %t
1213
; RUN: llvm-nm %t | FileCheck %s
1314

1415
; CHECK: T _start

0 commit comments

Comments
 (0)