[llvm] r222299 - llvm-readobj: fix off-by-one error in COFFDumper

Rui Ueyama ruiu at google.com
Tue Nov 18 18:07:10 PST 2014


Author: ruiu
Date: Tue Nov 18 20:07:10 2014
New Revision: 222299

URL: http://llvm.org/viewvc/llvm-project?rev=222299&view=rev
Log:
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.


Modified:
    llvm/trunk/lib/Object/COFFObjectFile.cpp
    llvm/trunk/test/tools/llvm-readobj/coff-basereloc.test
    llvm/trunk/tools/llvm-readobj/COFFDumper.cpp

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=222299&r1=222298&r2=222299&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Tue Nov 18 20:07:10 2014
@@ -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

Modified: llvm/trunk/test/tools/llvm-readobj/coff-basereloc.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/coff-basereloc.test?rev=222299&r1=222298&r2=222299&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/coff-basereloc.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/coff-basereloc.test Tue Nov 18 20:07:10 2014
@@ -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: ]
 

Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=222299&r1=222298&r2=222299&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Tue Nov 18 20:07:10 2014
@@ -1086,7 +1086,7 @@ static StringRef getBaseRelocTypeName(ui
   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);





More information about the llvm-commits mailing list