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
This commit is contained in:
Rui Ueyama 2014-11-19 02:07:10 +00:00
parent 28b45aa83e
commit 3977e2f696
3 changed files with 23 additions and 22 deletions

View File

@ -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

View File

@ -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: ]

View File

@ -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);