From 05e0103959f728cbf93fd2d4f5011f43f54a0d9e Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Wed, 27 Apr 2016 23:43:00 +0000 Subject: [PATCH] Fix bugs in llvm-objdump printing the last word for -section in non i386 and x86 files. Two problems, 1) for the last 4 bytes it would print them as separate bytes not a word and 2) it would print the same last byte for those bytes less than a word. rdar://25938224 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267819 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm-objdump/Inputs/section.macho-armv7 | Bin 232 -> 308 bytes test/tools/llvm-objdump/macho-sections.test | 6 +++++- tools/llvm-objdump/MachODump.cpp | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/tools/llvm-objdump/Inputs/section.macho-armv7 b/test/tools/llvm-objdump/Inputs/section.macho-armv7 index 456cd3e5f69c8aed7af99040fe8418ddb6304a01..810d5c52d339291b25513c73a09ab619bef3ca5f 100644 GIT binary patch delta 98 zcmaFCxP@tg2pLCd7`gAlLF(!IwvL-#)$`|*yH1q f^Ye;JCPqtg@j%t+041a+-sR?C1`4pSvM~SvnwJjY delta 80 zcmdnO^n!7Mh~)tW2w((KFg8>OPVoR)cYqi~vqLe{L|=WTI}8)+oR}UkOlD(L0|0e& B3E%(# diff --git a/test/tools/llvm-objdump/macho-sections.test b/test/tools/llvm-objdump/macho-sections.test index a7e2e81be5d..7b0d89ce505 100644 --- a/test/tools/llvm-objdump/macho-sections.test +++ b/test/tools/llvm-objdump/macho-sections.test @@ -4,4 +4,8 @@ # RUN: llvm-objdump -macho -section=__data %p/Inputs/section.macho-armv7 | FileCheck -check-prefix CHECK-ADDR %s -# CHECK-ADDR: 00000004 00000001 +# CHECK-ADDR: 00000004 00000001 00000002 + +# RUN: llvm-objdump -macho -section=__const %p/Inputs/section.macho-armv7 | FileCheck -check-prefix CHECK-BYTES %s + +# CHECK-BYTES: 0000000c 00000003 04 05 06 diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 3d5c6eceada..bcce08ec51b 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -1004,7 +1004,7 @@ static void DumpRawSectionContents(MachOObjectFile *O, const char *sect, outs() << format("%08" PRIx64, addr) << "\t"; for (j = 0; j < 4 * sizeof(int32_t) && i + j < size; j += sizeof(int32_t)) { - if (i + j + sizeof(int32_t) < size) { + if (i + j + sizeof(int32_t) <= size) { uint32_t long_word; memcpy(&long_word, sect + i + j, sizeof(int32_t)); if (O->isLittleEndian() != sys::IsLittleEndianHost) @@ -1012,7 +1012,7 @@ static void DumpRawSectionContents(MachOObjectFile *O, const char *sect, outs() << format("%08" PRIx32, long_word) << " "; } else { for (uint32_t k = 0; i + j + k < size; k++) { - uint8_t byte_word = *(sect + i + j); + uint8_t byte_word = *(sect + i + j + k); outs() << format("%02" PRIx32, (uint32_t)byte_word) << " "; } }