From bf55f7ea59c110df5d62d1c9b3866d374f5a86d0 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 15 Nov 2016 20:26:01 +0000 Subject: [PATCH] llvm-objdump: deal with unexpected object files more gracefully. Specifically, we don't want to segfault on release builds, so print the problem instead. llvm-svn: 287022 --- .../Inputs/malformed-unwind.macho-x86_64 | Bin 0 -> 8704 bytes .../llvm-objdump/malformed-unwind-x86_64.test | 5 ++++ llvm/tools/llvm-objdump/MachODump.cpp | 26 ++++++++++++++------- 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100755 llvm/test/tools/llvm-objdump/Inputs/malformed-unwind.macho-x86_64 create mode 100644 llvm/test/tools/llvm-objdump/malformed-unwind-x86_64.test diff --git a/llvm/test/tools/llvm-objdump/Inputs/malformed-unwind.macho-x86_64 b/llvm/test/tools/llvm-objdump/Inputs/malformed-unwind.macho-x86_64 new file mode 100755 index 0000000000000000000000000000000000000000..c4cbe2a1c3ec0d07d3c6857efbf091b8519885be GIT binary patch literal 8704 zcmeHNO>7%Q6n;(u7^s@`=KzJ!B_gQMk{=bJN*r+7T6IJVX=|h^P(Ar)6B{{pWN%vM z0J2m#SP_!%To5-@l`|Klq9VZ!fe_-rwQV95$!AnyzHdC6t~a5*_ApO+`{uow`F7@; z9cetzzx?y}zfXxIhDBOKA~FV@c|zoK@lX|hhqpD&Jz^)WWVaE!8AHSn7OOMQvsb@yU2sJdk9>5tg5F(cB7x~h#}E#KG< z#qlzueY`!kMd*hek{0ht8|dR{$*-*Xb;RO$S&R3IZBL)PZ_AGHEf)&vHw*r1pg}Gl z$7@==BNl-E0Nyrmzo5ESy;`mowOn1QAr!~^%Hn-w`_X?G9@q7RS=ZBZ**V*Z2J1Jl zuHpJd))n8JP${a*waBu<-yJW6A%57G{mFlHoT}A|Hr7}2wTi9=^&NO)=+E(mc=Y3V z(eFmJl6x4Q7sI0;#p8Dzej_MG_SM<>_ufsPo)7ng7vl}S5j#2J7+!670{eD`Wltmt zlY~vdhLZ8HpW!rNQ?P`24tmoQc^Y>0Wswf-v(N=7h4@sCpB!-i{hutLKi?Y{Y&-Fw z+&9x}jrw$@oS!bPSBmf{FF-ktL!X|!oBis!z z+l8p|DwN~<&g;+nHS6Dm@5C|S7;p?Y1{?#90mp!2;PGSNgG~GOxK;B-`gUH+cfxNZ-#~`_a36 zt2g-@+}`Bxc%J=Y{Ck+Wi@nJku$>YfvULZ@CH`F6;yZd@e%)%x@F9ZmeEkwMaS)F; zp+*u?gvB9NUhD^qrSCy`#!ccN%HOvslzEn&w`XGdJRkG7AP%)S>ki4m{;4=&&ekI5 z5hm0lr3ef*tXliX4z7V?z%k$$a11yG90QI4$ADwNG2j?*3^)cH1CJd8`zE{#9Mry) z>SA`jEa&UeL0OlZO+^a3QLE-ER(kIC&B%X$Tq4*2 literal 0 HcmV?d00001 diff --git a/llvm/test/tools/llvm-objdump/malformed-unwind-x86_64.test b/llvm/test/tools/llvm-objdump/malformed-unwind-x86_64.test new file mode 100644 index 0000000..26984a3 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/malformed-unwind-x86_64.test @@ -0,0 +1,5 @@ +# RUN: llvm-objdump -unwind-info %p/Inputs/malformed-unwind.macho-x86_64 | FileCheck %s + +# CHECK: Contents of __unwind_info section: +# [...] +# CHECK: Skipping 2nd level page with unknown kind 4 diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index 249ab7e..7e61485 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -7072,8 +7072,10 @@ printMachOCompactUnwindSection(const MachOObjectFile *Obj, std::map &Symbols, const SectionRef &CompactUnwind) { - assert(Obj->isLittleEndian() && - "There should not be a big-endian .o with __compact_unwind"); + if (!Obj->isLittleEndian()) { + outs() << "Skipping big-endian __compact_unwind section\n"; + return; + } bool Is64 = Obj->is64Bit(); uint32_t PointerSize = Is64 ? sizeof(uint64_t) : sizeof(uint32_t); @@ -7105,8 +7107,10 @@ printMachOCompactUnwindSection(const MachOObjectFile *Obj, Entry.PersonalityReloc = Reloc; else if (OffsetInEntry == 2 * PointerSize + 2 * sizeof(uint32_t)) Entry.LSDAReloc = Reloc; - else - llvm_unreachable("Unexpected relocation in __compact_unwind section"); + else { + outs() << "Invalid relocation in __compact_unwind section\n"; + return; + } } // Finally, we're ready to print the data we've gathered. @@ -7212,8 +7216,10 @@ static void printMachOUnwindInfoSection(const MachOObjectFile *Obj, std::map &Symbols, const SectionRef &UnwindInfo) { - assert(Obj->isLittleEndian() && - "There should not be a big-endian .o with __unwind_info"); + if (!Obj->isLittleEndian()) { + outs() << "Skipping big-endian __unwind_info section\n"; + return; + } outs() << "Contents of __unwind_info section:\n"; @@ -7228,7 +7234,10 @@ static void printMachOUnwindInfoSection(const MachOObjectFile *Obj, uint32_t Version = readNext(Pos); outs() << " Version: " << format("0x%" PRIx32, Version) << '\n'; - assert(Version == 1 && "only understand version 1"); + if (Version != 1) { + outs() << " Skipping section with unknown version\n"; + return; + } uint32_t CommonEncodingsStart = readNext(Pos); outs() << " Common encodings array section offset: " @@ -7368,7 +7377,8 @@ static void printMachOUnwindInfoSection(const MachOObjectFile *Obj, printCompressedSecondLevelUnwindPage(Pos, IndexEntries[i].FunctionOffset, CommonEncodings); else - llvm_unreachable("Do not know how to print this kind of 2nd level page"); + outs() << " Skipping 2nd level page with unknown kind " << Kind + << '\n'; } } -- 2.7.4