[lld] r285962 - Update for llvm change.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 3 13:17:25 PDT 2016


Author: rafael
Date: Thu Nov  3 15:17:25 2016
New Revision: 285962

URL: http://llvm.org/viewvc/llvm-project?rev=285962&view=rev
Log:
Update for llvm change.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/test/ELF/invalid/invalid-e_shnum.s
    lld/trunk/test/ELF/invalid/too-short.s

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=285962&r1=285961&r2=285962&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Nov  3 15:17:25 2016
@@ -103,14 +103,6 @@ std::string elf::getFilename(const Input
   return F->getName();
 }
 
-template <class ELFT> static ELFFile<ELFT> createELFObj(MemoryBufferRef MB) {
-  std::error_code EC;
-  ELFFile<ELFT> F(MB.getBuffer(), EC);
-  if (EC)
-    fatal(EC, "failed to read " + MB.getBufferIdentifier());
-  return F;
-}
-
 template <class ELFT> static ELFKind getELFKind() {
   if (ELFT::TargetEndianness == support::little)
     return ELFT::Is64Bits ? ELF64LEKind : ELF32LEKind;
@@ -119,7 +111,7 @@ template <class ELFT> static ELFKind get
 
 template <class ELFT>
 ELFFileBase<ELFT>::ELFFileBase(Kind K, MemoryBufferRef MB)
-    : InputFile(K, MB), ELFObj(createELFObj<ELFT>(MB)) {
+    : InputFile(K, MB), ELFObj(MB.getBuffer()) {
   EKind = getELFKind<ELFT>();
   EMachine = ELFObj.getHeader()->e_machine;
   OSABI = ELFObj.getHeader()->e_ident[llvm::ELF::EI_OSABI];
@@ -793,6 +785,11 @@ static InputFile *createELFFile(MemoryBu
   if (Endian != ELFDATA2LSB && Endian != ELFDATA2MSB)
     fatal("invalid data encoding: " + MB.getBufferIdentifier());
 
+  size_t BufSize = MB.getBuffer().size();
+  if ((Size == ELFCLASS32 && BufSize < sizeof(Elf32_Ehdr)) ||
+      (Size == ELFCLASS64 && BufSize < sizeof(Elf64_Ehdr)))
+    fatal("file is too short");
+
   InputFile *Obj;
   if (Size == ELFCLASS32 && Endian == ELFDATA2LSB)
     Obj = make<T<ELF32LE>>(MB);
@@ -870,7 +867,7 @@ template <class ELFT> std::vector<String
   typedef typename ELFT::Sym Elf_Sym;
   typedef typename ELFT::SymRange Elf_Sym_Range;
 
-  const ELFFile<ELFT> Obj = createELFObj<ELFT>(this->MB);
+  const ELFFile<ELFT> Obj(this->MB.getBuffer());
   ArrayRef<Elf_Shdr> Sections = check(Obj.sections());
   for (const Elf_Shdr &Sec : Sections) {
     if (Sec.sh_type != SHT_SYMTAB)

Modified: lld/trunk/test/ELF/invalid/invalid-e_shnum.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/invalid-e_shnum.s?rev=285962&r1=285961&r2=285962&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/invalid-e_shnum.s (original)
+++ lld/trunk/test/ELF/invalid/invalid-e_shnum.s Thu Nov  3 15:17:25 2016
@@ -1,4 +1,3 @@
 ## Spec says that "If a file has no section header table, e_shnum holds the value zero.", though
-## in this test case it holds non-zero and lld may crash.
-# RUN: not ld.lld %p/Inputs/invalid-e_shnum.elf -o %t2 2>&1 | FileCheck %s
-# CHECK: Invalid data was encountered while parsing the file
+## in this test case it holds non-zero and lld used to crash.
+# RUN: ld.lld %p/Inputs/invalid-e_shnum.elf -o %t2

Modified: lld/trunk/test/ELF/invalid/too-short.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/too-short.s?rev=285962&r1=285961&r2=285962&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/too-short.s (original)
+++ lld/trunk/test/ELF/invalid/too-short.s Thu Nov  3 15:17:25 2016
@@ -2,4 +2,4 @@
 
 ## too-short.elf file is a truncated ELF.
 # RUN: not ld.lld %S/Inputs/too-short.elf -o %t 2>&1 | FileCheck %s
-# CHECK: failed to read
+# CHECK: file is too short




More information about the llvm-commits mailing list