From 95cf2f25feb6c9354961497e1987afea49a07ed3 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 16 Jun 2014 16:41:00 +0000 Subject: [PATCH] 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. llvm-svn: 211036 --- llvm/lib/Object/ELFObjectFile.cpp | 10 +++++----- llvm/test/Object/Inputs/corrupt-archive.a | Bin 0 -> 2698 bytes llvm/test/Object/nm-archive.test | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 llvm/test/Object/Inputs/corrupt-archive.a diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp index a11a9e0..356288f 100644 --- a/llvm/lib/Object/ELFObjectFile.cpp +++ b/llvm/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/llvm/test/Object/Inputs/corrupt-archive.a b/llvm/test/Object/Inputs/corrupt-archive.a new file mode 100644 index 0000000000000000000000000000000000000000..f8940ff6420c1d6c461cb4b656ec01cc61f5ce58 GIT binary patch literal 2698 zcmcImOKTHR6uxPyjnzsmKB#c_mGyNMdabS`~aEDCs1bl4_EX%v7oy1wjxu zy7Payac7}|zeI4+je9}QH*;=!J4rT*2j+g~eCM3G?=v$s?{;d9i=)$(<>hGUMMi@Je5lkrWInD8y z-Z<+joE*T5e%lj>mb=y#PuIgh-1b}E&9LEhme$*~aLsQEp@-f^DD;kBcSBbX!j7q% zLT~$_r(d~oHyea*?FqTPrpuAR^H%6q1wvzNu%?di?{us)9_)!KMK6Z7s)?TBs+HqSR_x5ivN$J>vXwJ&3imXp598~qXz=j|B>M;giN7F}=`DZ8w>-)F) z=O`Eb8}z6m`_HN*>4=3$%qe>0;O2vBD7ws()KyZzsbv7Zk7!6_DT%F}5+LnGQj%)| zUm5iR7=zeHh&@V{kVC{J*A6M;JkUEZ6iJT1-`Ej8!-L9j!YFYVL$ZHx{rWd}{71;I zO0s{|r|O9NpPz8dW2k!ycAx)rRIJs}#Cp2tmPo#L2M>@7zXMh_$ literal 0 HcmV?d00001 diff --git a/llvm/test/Object/nm-archive.test b/llvm/test/Object/nm-archive.test index fbbf051..d875d6c 100644 --- a/llvm/test/Object/nm-archive.test +++ b/llvm/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 -- 2.7.4