From 9afbac479f3d59929a50dcf7af9e99d70b45c6e7 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sun, 11 Oct 2015 20:19:20 +0000 Subject: [PATCH] Handle a crash in conflict detection with archive members. llvm-svn: 249996 --- lld/ELF/Config.h | 2 ++ lld/ELF/InputFiles.h | 3 +++ lld/ELF/SymbolTable.cpp | 2 +- lld/test/elf2/incompatible-ar-first.s | 11 +++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 lld/test/elf2/incompatible-ar-first.s diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 021944a4c7b6..c19d136ffcea 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -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; diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 126ad3282339..488a76089415 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -249,6 +249,9 @@ std::unique_ptr 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(); diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 3aff84d5bdd8..bfad8c333b31 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -35,7 +35,7 @@ void SymbolTable::addFile(std::unique_ptr 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); } } diff --git a/lld/test/elf2/incompatible-ar-first.s b/lld/test/elf2/incompatible-ar-first.s new file mode 100644 index 000000000000..f50f2c19fcd1 --- /dev/null +++ b/lld/test/elf2/incompatible-ar-first.s @@ -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