From 3977e2f696513537dfa6cdbf4768dad4853097e8 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 19 Nov 2014 02:07:10 +0000 Subject: [PATCH] llvm-readobj: fix off-by-one error in COFFDumper It printed out base relocation table header as table entry. This patch also makes llvm-readobj to not skip ABSOLUTE entries becuase it was confusing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222299 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/COFFObjectFile.cpp | 2 +- test/tools/llvm-readobj/coff-basereloc.test | 38 ++++++++++++--------- tools/llvm-readobj/COFFDumper.cpp | 5 +-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index c5d7c409519..d5ff7d6439c 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -1491,7 +1491,7 @@ void BaseRelocRef::moveNext() { // Header->BlockSize is the size of the current block, including the // size of the header itself. uint32_t Size = sizeof(*Header) + - sizeof(coff_base_reloc_block_entry) * Index; + sizeof(coff_base_reloc_block_entry) * (Index + 1); if (Size == Header->BlockSize) { // .reloc contains a list of base relocation blocks. Each block // consists of the header followed by entries. The header contains diff --git a/test/tools/llvm-readobj/coff-basereloc.test b/test/tools/llvm-readobj/coff-basereloc.test index 752e73ab2d4..cd6687cae44 100644 --- a/test/tools/llvm-readobj/coff-basereloc.test +++ b/test/tools/llvm-readobj/coff-basereloc.test @@ -1,20 +1,24 @@ RUN: llvm-readobj -coff-basereloc %p/Inputs/basereloc.obj.coff-i386 | FileCheck %s -CHECK: Format: COFF-i386 -CHECK: Arch: i386 -CHECK: AddressSize: 32bit -CHECK: BaseReloc [ -CHECK: Entry { -CHECK: Type: HIGHLOW -CHECK: Address: 0x1004 -CHECK: } -CHECK: Entry { -CHECK: Type: HIGHLOW -CHECK: Address: 0x100A -CHECK: } -CHECK: Entry { -CHECK: Type: HIGHLOW -CHECK: Address: 0x1010 -CHECK: } -CHECK: ] +CHECK: Format: COFF-i386 +CHECK-NEXT: Arch: i386 +CHECK-NEXT: AddressSize: 32bit +CHECK-NEXT: BaseReloc [ +CHECK-NEXT: Entry { +CHECK-NEXT: Type: HIGHLOW +CHECK-NEXT: Address: 0x1004 +CHECK-NEXT: } +CHECK-NEXT: Entry { +CHECK-NEXT: Type: HIGHLOW +CHECK-NEXT: Address: 0x100A +CHECK-NEXT: } +CHECK-NEXT: Entry { +CHECK-NEXT: Type: HIGHLOW +CHECK-NEXT: Address: 0x1010 +CHECK-NEXT: } +CHECK-NEXT: Entry { +CHECK-NEXT: Type: ABSOLUTE +CHECK-NEXT: Address: 0x1000 +CHECK-NEXT: } +CHECK-NEXT: ] diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 2ea3cd8a3da..4e1bf2cbbd3 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -1086,7 +1086,7 @@ static StringRef getBaseRelocTypeName(uint8_t Type) { case COFF::IMAGE_REL_BASED_HIGHLOW: return "HIGHLOW"; case COFF::IMAGE_REL_BASED_HIGHADJ: return "HIGHADJ"; case COFF::IMAGE_REL_BASED_DIR64: return "DIR64"; - default: return "unknown"; + default: return "unknown (" + std::to_string(Type) + ")"; } } @@ -1099,9 +1099,6 @@ void COFFDumper::printCOFFBaseReloc() { continue; if (error(I.getType(Type))) continue; - // IMAGE_REL_BASED_ABSOLUTE is a NOP entry. - if (Type == COFF::IMAGE_REL_BASED_ABSOLUTE) - continue; DictScope Import(W, "Entry"); W.printString("Type", getBaseRelocTypeName(Type)); W.printHex("Address", RVA);