Handle a crash in conflict detection with archive members.

llvm-svn: 249996
This commit is contained in:
Rafael Espindola 2015-10-11 20:19:20 +00:00
parent 4546181e12
commit 9afbac479f
4 changed files with 17 additions and 1 deletions

View File

@ -18,6 +18,7 @@
namespace lld {
namespace elf2 {
class ELFFileBase;
class SymbolBody;
enum ELFKind {
@ -30,6 +31,7 @@ enum ELFKind {
struct Configuration {
SymbolBody *EntrySym = nullptr;
ELFFileBase *FirstElf = nullptr;
llvm::StringRef DynamicLinker;
llvm::StringRef Entry;
llvm::StringRef Emulation;

View File

@ -249,6 +249,9 @@ std::unique_ptr<ELFFileBase> createELFFile(MemoryBufferRef MB) {
error("Invalid file class: " + MB.getBufferIdentifier());
}
if (!Config->FirstElf)
Config->FirstElf = Ret.get();
if (Config->ElfKind == ELFNoneKind) {
Config->ElfKind = Ret->getELFKind();
Config->EMachine = Ret->getEMachine();

View File

@ -35,7 +35,7 @@ void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
StringRef A = E->getName();
StringRef B = Config->Emulation;
if (B.empty())
B = getFirstELF()->getName();
B = Config->FirstElf->getName();
error(A + " is incompatible with " + B);
}
}

View File

@ -0,0 +1,11 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/archive.s -o %ta.o
// RUN: llvm-ar rc %t.a %ta.o
// RUN: llvm-mc -filetype=obj -triple=i686-linux %s -o %tb.o
// RUN: not ld.lld2 %t.a %tb.o 2>&1 | FileCheck %s
// We used to crash when
// * The first object seen by the symbol table is from an archive.
// * -m was not used.
// CHECK: a.o is incompatible with {{.*}}b.o
// REQUIRES: x86