From: Rafael Espindola Date: Mon, 16 Jun 2014 16:41:00 +0000 (+0000) Subject: Fix pr17056. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7f2f94faeb04e0f97990d9d941745a630aaa5a54;p=oota-llvm.git Fix pr17056. This makes llvm-nm ignore members that are not sufficiently aligned for lib/Object to handle. These archives are invalid. GNU AR is able to handle this, but in general just warns about broken archive members. We should probably start warning too, but for now just make sure llvm-nm exits with an 0. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211036 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index a11a9e016df..356288ffc51 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -36,7 +36,7 @@ ErrorOr ObjectFile::createELFObjectFile(MemoryBuffer *Obj, R.reset(new ELFObjectFile >( Obj, EC, BufferOwned)); else - llvm_unreachable("Invalid alignment for ELF file!"); + return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB) #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 4) @@ -48,7 +48,7 @@ ErrorOr ObjectFile::createELFObjectFile(MemoryBuffer *Obj, R.reset(new ELFObjectFile >(Obj, EC, BufferOwned)); else - llvm_unreachable("Invalid alignment for ELF file!"); + return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB) #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 8) @@ -60,7 +60,7 @@ ErrorOr ObjectFile::createELFObjectFile(MemoryBuffer *Obj, R.reset(new ELFObjectFile >(Obj, EC, BufferOwned)); else - llvm_unreachable("Invalid alignment for ELF file!"); + return object_error::parse_failed; else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) { #if !LLVM_IS_UNALIGNED_ACCESS_FAST if (MaxAlignment >= 8) @@ -72,10 +72,10 @@ ErrorOr ObjectFile::createELFObjectFile(MemoryBuffer *Obj, R.reset(new ELFObjectFile >( Obj, EC, BufferOwned)); else - llvm_unreachable("Invalid alignment for ELF file!"); + return object_error::parse_failed; } else - report_fatal_error("Buffer is not an ELF object file!"); + llvm_unreachable("Buffer is not an ELF object file!"); if (EC) return EC; diff --git a/test/Object/Inputs/corrupt-archive.a b/test/Object/Inputs/corrupt-archive.a new file mode 100644 index 00000000000..f8940ff6420 Binary files /dev/null and b/test/Object/Inputs/corrupt-archive.a differ diff --git a/test/Object/nm-archive.test b/test/Object/nm-archive.test index fbbf051b478..d875d6c991c 100644 --- a/test/Object/nm-archive.test +++ b/test/Object/nm-archive.test @@ -33,3 +33,9 @@ RUN: llvm-nm -s %p/Inputs/archive-test.a-gnu-minimal Don't reject an empty archive. RUN: llvm-nm %p/Inputs/archive-test.a-empty + +This archive has an unaligned member and a unknown format member. +GNU AR is able to parse the unaligned member and warns about the member with +the unknown format. We should probably simply warn on both. For now just check +that we don't produce an error. +RUN: llvm-nm %p/Inputs/corrupt-archive.a