[lld] r282885 - Improve error check for an empty archive.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 30 10:56:20 PDT 2016
Author: ruiu
Date: Fri Sep 30 12:56:20 2016
New Revision: 282885
URL: http://llvm.org/viewvc/llvm-project?rev=282885&view=rev
Log:
Improve error check for an empty archive.
Previously, it warned on any archive file that has no symbol.
It turned out that that is too noisy.
With this patch, it warns on such archive file that contains no file.
Differential Revision: https://reviews.llvm.org/D25111
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/test/ELF/empty-archive.s
lld/trunk/test/ELF/lto/archive.ll
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=282885&r1=282884&r2=282885&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Sep 30 12:56:20 2016
@@ -425,18 +425,16 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
template <class ELFT> void ArchiveFile::parse() {
File = check(Archive::create(MB), "failed to parse archive");
+ // Checks for a common usage error of an ar command.
+ if (File->getNumberOfSymbols() == 0 && !File->isEmpty())
+ warn(getName() + " has no symbol."
+ " Chances are you are doing an LTO build and forgot to use an ar"
+ " command that can create a symbol table for LLVM bitcode files."
+ " If so, use llvm-ar or GNU ar + plugin.");
+
// Read the symbol table to construct Lazy objects.
- bool IsEmpty = true;
- for (const Archive::Symbol &Sym : File->symbols()) {
+ for (const Archive::Symbol &Sym : File->symbols())
Symtab<ELFT>::X->addLazyArchive(this, Sym);
- IsEmpty = false;
- }
-
- if (IsEmpty)
- warn(getName() + " has no symbol. Chances are you are doing "
- "an LTO build and forgot to use an ar command that can create "
- "a symbol table for LLVM bitcode files. If so, use llvm-ar or "
- "GNU ar + plugin.");
}
// Returns a buffer pointing to a member file containing a given symbol.
Modified: lld/trunk/test/ELF/empty-archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/empty-archive.s?rev=282885&r1=282884&r2=282885&view=diff
==============================================================================
--- lld/trunk/test/ELF/empty-archive.s (original)
+++ lld/trunk/test/ELF/empty-archive.s Fri Sep 30 12:56:20 2016
@@ -1,5 +1,3 @@
// RUN: llvm-ar rc %t.a
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-// RUN: ld.lld -shared %t.o %t.a -o t 2>&1 | FileCheck %s
-
-// CHECK: has no symbol.
+// RUN: ld.lld -shared %t.o %t.a -o t
Modified: lld/trunk/test/ELF/lto/archive.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/archive.ll?rev=282885&r1=282884&r2=282885&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/archive.ll (original)
+++ lld/trunk/test/ELF/lto/archive.ll Fri Sep 30 12:56:20 2016
@@ -8,6 +8,9 @@
; RUN: ld.lld -m elf_x86_64 %t2.o --whole-archive %t.a -o %t3 -shared
; RUN: llvm-readobj -t %t3 | FileCheck %s
+; RUN: llvm-ar rcS %t4.a %t1.o
+; RUN: ld.lld -m elf_x86_64 %t2.o %t4.a -o %t3 -shared 2>&1 \
+; RUN: | FileCheck -check-prefix=WARN %s
; CHECK: Name: g (
; CHECK-NEXT: Value:
@@ -25,6 +28,8 @@
; CHECK-NEXT: Other: 0
; CHECK-NEXT: Section: .text
+; WARN: has no symbol.
+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list