[PATCH] D25233: [ELF] - Do not crash when unable to parse ELF object file.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 6 03:28:33 PDT 2016


grimar updated this revision to Diff 73752.
grimar added a comment.

- Addressed review comments.


https://reviews.llvm.org/D25233

Files:
  ELF/Error.cpp
  ELF/Error.h
  ELF/InputFiles.cpp
  test/ELF/invalid/Inputs/too-short.elf
  test/ELF/invalid/too-short.s


Index: test/ELF/invalid/too-short.s
===================================================================
--- test/ELF/invalid/too-short.s
+++ test/ELF/invalid/too-short.s
@@ -0,0 +1,5 @@
+# REQUIRES: x86
+
+## 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
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -57,7 +57,7 @@
   std::error_code EC;
   ELFFile<ELFT> F(MB.getBuffer(), EC);
   if (EC)
-    error(EC, "failed to read " + MB.getBufferIdentifier());
+    fatal(EC, "failed to read " + MB.getBufferIdentifier());
   return F;
 }
 
Index: ELF/Error.h
===================================================================
--- ELF/Error.h
+++ ELF/Error.h
@@ -46,6 +46,7 @@
 
 LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
 LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg, const Twine &Prefix);
+LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
 
 template <class T> T check(ErrorOr<T> E) {
   if (auto EC = E.getError())
Index: ELF/Error.cpp
===================================================================
--- ELF/Error.cpp
+++ ELF/Error.cpp
@@ -51,4 +51,8 @@
   fatal(Prefix + ": " + Msg);
 }
 
+void elf::fatal(std::error_code EC, const Twine &Prefix) {
+  fatal(Prefix + ": " + EC.message());
+}
+
 } // namespace lld


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25233.73752.patch
Type: text/x-patch
Size: 1473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161006/9f08c39c/attachment.bin>


More information about the llvm-commits mailing list