diff options
author | Kevin Enderby <enderby@apple.com> | 2015-10-06 22:27:08 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2015-10-06 22:27:08 +0000 |
commit | a59824a174f69fc07f715efc220e26f8c2620e3c (patch) | |
tree | af074e3aee6b6e3f478cd9766317ccc1ffeb440a | |
parent | 702c4b865e0f4767c3c39b022b8b37dafe5197ef (diff) | |
download | bcm5719-llvm-a59824a174f69fc07f715efc220e26f8c2620e3c.tar.gz bcm5719-llvm-a59824a174f69fc07f715efc220e26f8c2620e3c.zip |
Fix two bugs in llvm-objdump’s printing of Objective-C meta data
from malformed Mach-O files that caused crashes.
We recently got about 700 malformed Mach-O files which we have
been using the improve the robustness of tools that deal with reading
data from object files. These resulted in about 20 small bug fixes to
the darwin based tools.
The goal here is to also improve the robustness of llvm-objdump and
this is the first two fixes. In talking with Tim Northover the approach
we thought might be best is to:
1) Only include tests for the malformed Mach-O files that cause crashes
(not all 700+ tests).
2) The test should only contain the command line option that caused the
crash and not all the others that don’t matter.
3) There should be only one line for the FileCheck that is past the point
of the crash if possible and if possible indicates the malformation.
Again the goal is to fix crashes and not so much care about how the
printing of malformed data comes out.
Tim also suggested if we really wanted to add test cases for all 700+
malformed Mach-O files putting them in the regression tests might be
an option. But many of these do not cause crashes.
llvm-svn: 249479
-rw-r--r-- | llvm/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0001.macho | bin | 0 -> 9248 bytes | |||
-rw-r--r-- | llvm/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0006.macho | bin | 0 -> 9248 bytes | |||
-rw-r--r-- | llvm/test/tools/llvm-objdump/malformed-machos.test | 14 | ||||
-rw-r--r-- | llvm/tools/llvm-objdump/MachODump.cpp | 6 |
4 files changed, 18 insertions, 2 deletions
diff --git a/llvm/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0001.macho b/llvm/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0001.macho Binary files differnew file mode 100644 index 00000000000..d81f9f00f4a --- /dev/null +++ b/llvm/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0001.macho diff --git a/llvm/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0006.macho b/llvm/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0006.macho Binary files differnew file mode 100644 index 00000000000..13a4e9aea7f --- /dev/null +++ b/llvm/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0006.macho diff --git a/llvm/test/tools/llvm-objdump/malformed-machos.test b/llvm/test/tools/llvm-objdump/malformed-machos.test new file mode 100644 index 00000000000..4e1765f7f42 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/malformed-machos.test @@ -0,0 +1,14 @@ +// These test checks that llvm-objdump will not crash with malformed Mach-O +// files. So the check line is not all that important but the bug fixes to +// make sure llvm-objdump is robust is what matters. +# RUN: llvm-objdump -macho -objc-meta-data \ +# RUN: %p/Inputs/malformed-machos/mem-crup-0001.macho \ +# RUN: | FileCheck -check-prefix=m0001 %s + +# m0001: (method_t extends past the end of the section) + +# RUN: llvm-objdump -macho -objc-meta-data \ +# RUN: %p/Inputs/malformed-machos/mem-crup-0006.macho \ +# RUN: | FileCheck -check-prefix=m0006 %s + +# m0006: ivarLayout 0x8 diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index 164fb4ce4bc..0e9bf3695d8 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -3236,6 +3236,8 @@ walk_pointer_list_32(const char *listname, const SectionRef S, } static void print_layout_map(const char *layout_map, uint32_t left) { + if (layout_map == nullptr) + return; outs() << " layout map: "; do { outs() << format("0x%02" PRIx32, (*layout_map) & 0xff) << " "; @@ -3299,8 +3301,8 @@ static void print_method_list64_t(uint64_t p, struct DisassembleInfo *info, return; memset(&m, '\0', sizeof(struct method64_t)); if (left < sizeof(struct method64_t)) { - memcpy(&ml, r, left); - outs() << indent << " (method_t entends past the end of the section)\n"; + memcpy(&m, r, left); + outs() << indent << " (method_t extends past the end of the section)\n"; } else memcpy(&m, r, sizeof(struct method64_t)); if (info->O->isLittleEndian() != sys::IsLittleEndianHost) |