Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -99,6 +99,7 @@ std::vector VersionScriptLocals; std::vector BuildIdVector; bool AllowMultipleDefinition; + bool ArchiveWithoutSymbolsWarned = false; bool AsNeeded = false; bool Bsymbolic; bool BsymbolicFunctions; 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(MB)); + Files.push_back(make(MB, MBRef.getBufferIdentifier())); return; } @@ -215,7 +215,7 @@ return; default: if (InLib) - Files.push_back(make(MBRef)); + Files.push_back(make(MBRef, "")); else Files.push_back(createObjectFile(MBRef)); } 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: 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"