summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2019-03-14 18:21:32 +0000
committerRui Ueyama <ruiu@google.com>2019-03-14 18:21:32 +0000
commitcc8e4e839f6e33df06fc9c98ce114c53bf811db9 (patch)
tree5481a04086e6c88782f23dea6a49413843081a14
parent0f56b22614c824bb09acebd96381b2bdb1b45a70 (diff)
downloadbcm5719-llvm-cc8e4e839f6e33df06fc9c98ce114c53bf811db9.tar.gz
bcm5719-llvm-cc8e4e839f6e33df06fc9c98ce114c53bf811db9.zip
Make a hack for LTO work only when you are actually doing LTO.
We allow an archive file without symbol table as a linker input as a workaround for a very common error in LTO build. But that logic worked even for an archive file containing non-bitcode files, which is not expected. This patch limits that workaround to one that contains only bitcode files. Differential Revision: https://reviews.llvm.org/D59373 llvm-svn: 356186
-rw-r--r--lld/ELF/Driver.cpp10
-rw-r--r--lld/test/ELF/invalid/invalid-elf.test2
-rw-r--r--lld/test/ELF/lto/archive-no-index.ll17
3 files changed, 23 insertions, 6 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index c27e36f94a2..f3abd3f450e 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -213,7 +213,15 @@ 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->isEmpty() && !File->hasSymbolTable()) {
- for (const auto &P : getArchiveMembers(MBRef))
+ // Check if all members are bitcode files. If not, ignore, which is the
+ // default action without the LTO hack described above.
+ for (const std::pair<MemoryBufferRef, uint64_t> &P :
+ getArchiveMembers(MBRef))
+ if (identify_magic(P.first.getBuffer()) != file_magic::bitcode)
+ return;
+
+ for (const std::pair<MemoryBufferRef, uint64_t> &P :
+ getArchiveMembers(MBRef))
Files.push_back(make<LazyObjFile>(P.first, Path, P.second));
return;
}
diff --git a/lld/test/ELF/invalid/invalid-elf.test b/lld/test/ELF/invalid/invalid-elf.test
index 95c7c3976a8..95c2cdc0d59 100644
--- a/lld/test/ELF/invalid/invalid-elf.test
+++ b/lld/test/ELF/invalid/invalid-elf.test
@@ -4,7 +4,7 @@
# RUN: echo > %t/empty.o
# RUN: llvm-ar --format=gnu cr %t/not-elf.a %t/empty.o
-# RUN: not ld.lld %t/simple.o %t/not-elf.a -o %t2 2>&1 | \
+# RUN: not ld.lld --whole-archive %t/not-elf.a -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=NOT-ELF %s
# NOT-ELF: not-elf.a(empty.o): not an ELF file
diff --git a/lld/test/ELF/lto/archive-no-index.ll b/lld/test/ELF/lto/archive-no-index.ll
index 5ac2628fefd..c4dd89a5435 100644
--- a/lld/test/ELF/lto/archive-no-index.ll
+++ b/lld/test/ELF/lto/archive-no-index.ll
@@ -1,8 +1,6 @@
; REQUIRES: x86
-; Tests that we suggest that LTO symbols missing from an archive index
-; may be the cause of undefined references, but only if we both
-; encountered an empty archive index and undefined references (to prevent
-; noisy false alarms).
+; Tests that we accept an archive file without symbol table
+; if all the member files are bitcode files.
; RUN: llvm-as -o %t1.o %s
; RUN: llvm-as -o %t2.o %S/Inputs/archive.ll
@@ -23,3 +21,14 @@ define i32 @main() {
call void @f()
ret i32 0
}
+
+; RUN: echo 'f:' | llvm-mc -triple=x86_64-pc-linux -filetype=obj - -o %t3.o
+; RUN: rm -f %t3.a
+; RUN: llvm-ar crS %t3.a %t3.o
+; RUN: not ld.lld -o /dev/null -emain %t1.o %t3.a 2>&1 | FileCheck -check-prefix=ERR1 %s
+; ERR1: error: undefined symbol: f
+
+; RUN: rm -f %t4.a
+; RUN: llvm-ar cr %t4.a
+; RUN: not ld.lld -o /dev/null -emain %t1.o %t4.a 2>&1 | FileCheck -check-prefix=ERR2 %s
+; ERR2: error: undefined symbol: f
OpenPOWER on IntegriCloud