From 1ea35c2d5253e1ab7066e9433aa5e1dde02e8723 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 4 Jun 2015 22:58:25 +0000 Subject: [PATCH] [Object, ELF] Don't call llvm_unreachable() from createELFObjectFile. Instead, return a proper error code from factory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239113 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/ELFObjectFile.cpp | 4 ++-- test/DebugInfo/Inputs/invalid.elf.2 | 1 + test/DebugInfo/dwarfdump-invalid.test | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 test/DebugInfo/Inputs/invalid.elf.2 diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index 8847a20d96e..1ffdc01bcd3 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -38,7 +38,7 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj) { else if (Ident.second == ELF::ELFDATA2MSB) R.reset(new ELFObjectFile>(Obj, EC)); else - llvm_unreachable("Buffer is not an ELF object file!"); + return object_error::parse_failed; } else { assert(Ident.first == ELF::ELFCLASS64); if (Ident.second == ELF::ELFDATA2LSB) @@ -46,7 +46,7 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj) { else if (Ident.second == ELF::ELFDATA2MSB) R.reset(new ELFObjectFile>(Obj, EC)); else - llvm_unreachable("Buffer is not an ELF object file!"); + return object_error::parse_failed; } if (EC) diff --git a/test/DebugInfo/Inputs/invalid.elf.2 b/test/DebugInfo/Inputs/invalid.elf.2 new file mode 100644 index 00000000000..16528a55a93 --- /dev/null +++ b/test/DebugInfo/Inputs/invalid.elf.2 @@ -0,0 +1 @@ +ELF'L:þB“ELFï \ No newline at end of file diff --git a/test/DebugInfo/dwarfdump-invalid.test b/test/DebugInfo/dwarfdump-invalid.test index dcbdd739190..5b616bd5581 100644 --- a/test/DebugInfo/dwarfdump-invalid.test +++ b/test/DebugInfo/dwarfdump-invalid.test @@ -1,4 +1,5 @@ ; Verify that llvm-dwarfdump doesn't crash on broken input files. RUN: llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INVALID-ELF +RUN: llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF INVALID-ELF: Invalid data was encountered while parsing the file -- 2.34.1