forked from OSchip/llvm-project
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
This commit is contained in:
parent
921ab75854
commit
0b1413a881
|
@ -123,13 +123,13 @@ static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef Emul) {
|
|||
|
||||
// Returns slices of MB by parsing MB as an archive file.
|
||||
// Each slice consists of a member file in the archive.
|
||||
std::vector<MemoryBufferRef>
|
||||
static getArchiveMembers(MemoryBufferRef MB) {
|
||||
std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
|
||||
MemoryBufferRef MB) {
|
||||
std::unique_ptr<Archive> File =
|
||||
check(Archive::create(MB),
|
||||
MB.getBufferIdentifier() + ": failed to parse archive");
|
||||
|
||||
std::vector<MemoryBufferRef> V;
|
||||
std::vector<std::pair<MemoryBufferRef, uint64_t>> V;
|
||||
Error Err = Error::success();
|
||||
for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) {
|
||||
Archive::Child C =
|
||||
|
@ -139,7 +139,7 @@ static getArchiveMembers(MemoryBufferRef MB) {
|
|||
check(C.getMemoryBufferRef(),
|
||||
MB.getBufferIdentifier() +
|
||||
": could not get the buffer for a child of the archive");
|
||||
V.push_back(MBRef);
|
||||
V.push_back(std::make_pair(MBRef, C.getChildOffset()));
|
||||
}
|
||||
if (Err)
|
||||
fatal(MB.getBufferIdentifier() + ": Archive::children failed: " +
|
||||
|
@ -173,8 +173,8 @@ void LinkerDriver::addFile(StringRef Path, bool WithLOption) {
|
|||
case file_magic::archive: {
|
||||
// Handle -whole-archive.
|
||||
if (InWholeArchive) {
|
||||
for (MemoryBufferRef MB : getArchiveMembers(MBRef))
|
||||
Files.push_back(createObjectFile(MB, Path));
|
||||
for (const auto &P : getArchiveMembers(MBRef))
|
||||
Files.push_back(createObjectFile(P.first, Path, P.second));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -186,8 +186,8 @@ void LinkerDriver::addFile(StringRef Path, bool WithLOption) {
|
|||
// understand the LLVM bitcode file. It is a pretty common error, so
|
||||
// we'll handle it as if it had a symbol table.
|
||||
if (!File->hasSymbolTable()) {
|
||||
for (MemoryBufferRef MB : getArchiveMembers(MBRef))
|
||||
Files.push_back(make<LazyObjectFile>(MB, MBRef.getBufferIdentifier()));
|
||||
for (const auto &P : getArchiveMembers(MBRef))
|
||||
Files.push_back(make<LazyObjectFile>(P.first, Path));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
; RUN: opt -module-summary %s -o %t.o
|
||||
; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t.coll.o
|
||||
; RUN: llvm-ar rcs %t1.a %t.coll.o
|
||||
; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t.coll.o
|
||||
; RUN: llvm-ar rcsc %t2.a %t.coll.o
|
||||
; RUN: mkdir -p %t1 %t2
|
||||
; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t1/t.coll.o
|
||||
; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t2/t.coll.o
|
||||
; RUN: rm -f %t.a
|
||||
; RUN: llvm-ar rcs %t.a %t1/t.coll.o %t2/t.coll.o
|
||||
|
||||
; RUN: ld.lld %t.o %t1.a %t2.a -o %t
|
||||
; RUN: ld.lld %t.o %t.a -o %t
|
||||
; RUN: llvm-nm %t | FileCheck %s
|
||||
|
||||
; Check we handle this case correctly even in presence of --whole-archive.
|
||||
; RUN: ld.lld %t.o --whole-archive %t1.a %t2.a -o %t
|
||||
; RUN: ld.lld %t.o --whole-archive %t.a -o %t
|
||||
; RUN: llvm-nm %t | FileCheck %s
|
||||
|
||||
; CHECK: T _start
|
||||
|
|
Loading…
Reference in New Issue