[PATCH] D32867: Warn about archives with no symbol table
Rafael Ávila de Espíndola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 4 08:29:13 PDT 2017
rafael created this revision.
Not having a symbol table is an indication of something missing in a build setup. We can handle it, but it is probably a good idea to inform the user.
This patch only warns once and only if a member is actually used in the build. This should avoid any false warnings with dead or empty archives.
https://reviews.llvm.org/D32867
Files:
ELF/Config.h
ELF/Driver.cpp
ELF/InputFiles.cpp
ELF/InputFiles.h
test/ELF/lto/archive-no-index.ll
Index: test/ELF/lto/archive-no-index.ll
===================================================================
--- test/ELF/lto/archive-no-index.ll
+++ test/ELF/lto/archive-no-index.ll
@@ -11,9 +11,11 @@
; RUN: llvm-ar crS %t1.a %t2.o
; RUN: llvm-ar crs %t2.a %t2.o
-; RUN: ld.lld -o %t -emain -m elf_x86_64 %t1.o %t1.a
+; RUN: ld.lld -o %t -emain -m elf_x86_64 %t1.o %t1.a 2>&1 | FileCheck %s
; RUN: ld.lld -o %t -emain -m elf_x86_64 %t1.o %t2.a
+; CHECK: warning: At least the {{.*}}archive-no-index.ll.tmp1.a archive listed no symbols in its index. This can happen when creating archives with a version of ar that does not understand the object files in the archive. For example, if you are using LLVM bitcode objects (such as created by -flto), you may need to use llvm-ar or GNU ar with a plugin.
+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -219,7 +219,10 @@
// archive file semantics.
class LazyObjectFile : public InputFile {
public:
- explicit LazyObjectFile(MemoryBufferRef M) : InputFile(LazyObjectKind, M) {}
+ explicit LazyObjectFile(MemoryBufferRef M, StringRef ArchiveName)
+ : InputFile(LazyObjectKind, M) {
+ this->ArchiveName = ArchiveName;
+ }
static bool classof(const InputFile *F) {
return F->kind() == LazyObjectKind;
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -981,6 +981,16 @@
MemoryBufferRef MBRef = getBuffer();
if (MBRef.getBuffer().empty())
return nullptr;
+ if (!ArchiveName.empty() && !Config->ArchiveWithoutSymbolsWarned) {
+ warn("At least the " + ArchiveName +
+ " archive listed no symbols in its index. This can happen when "
+ "creating archives with a version of ar that does not understand the "
+ "object files in the archive. For example, if you are using LLVM "
+ "bitcode objects (such as created by -flto), you may need to use "
+ "llvm-ar or GNU ar with a plugin.");
+ // Set to true so that we print the message only once.
+ Config->ArchiveWithoutSymbolsWarned = true;
+ }
return createObjectFile(MBRef);
}
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -187,7 +187,7 @@
// 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));
+ Files.push_back(make<LazyObjectFile>(MB, MBRef.getBufferIdentifier()));
return;
}
@@ -215,7 +215,7 @@
return;
default:
if (InLib)
- Files.push_back(make<LazyObjectFile>(MBRef));
+ Files.push_back(make<LazyObjectFile>(MBRef, ""));
else
Files.push_back(createObjectFile(MBRef));
}
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -99,6 +99,7 @@
std::vector<SymbolVersion> VersionScriptLocals;
std::vector<uint8_t> BuildIdVector;
bool AllowMultipleDefinition;
+ bool ArchiveWithoutSymbolsWarned = false;
bool AsNeeded = false;
bool Bsymbolic;
bool BsymbolicFunctions;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32867.97831.patch
Type: text/x-patch
Size: 3419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170504/aefc1c7b/attachment.bin>
More information about the llvm-commits
mailing list