[llvm-objdump] Fix mach-o binding decompression error
authorNick Kledzik <kledzik@apple.com>
Sat, 18 Oct 2014 01:21:02 +0000 (01:21 +0000)
committerNick Kledzik <kledzik@apple.com>
Sat, 18 Oct 2014 01:21:02 +0000 (01:21 +0000)
llvm-svn: 220119

llvm/lib/Object/MachOObjectFile.cpp
llvm/test/tools/llvm-objdump/Inputs/bind2.macho-x86_64 [new file with mode: 0755]
llvm/test/tools/llvm-objdump/macho-bind2.test [new file with mode: 0644]

index 4435815..6e83d81 100644 (file)
@@ -1974,20 +1974,20 @@ void MachOBindEntry::moveNext() {
                                              SegmentOffset) << "\n");
       return;
      case MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB:
-      AdvanceAmount = readULEB128();
+      AdvanceAmount = readULEB128() + PointerSize;
       RemainingLoopCount = 0;
       if (TableKind == Kind::Lazy)
         Malformed = true;
       DEBUG_WITH_TYPE(
           "mach-o-bind",
-          llvm::dbgs() << "BIND_OPCODE_DO_BIND_IMM_TIMES: "
+          llvm::dbgs() << "BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: "
                        << format("SegmentOffset=0x%06X", SegmentOffset)
                        << ", AdvanceAmount=" << AdvanceAmount
                        << ", RemainingLoopCount=" << RemainingLoopCount
                        << "\n");
       return;
     case MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED:
-      AdvanceAmount = ImmValue * PointerSize;
+      AdvanceAmount = ImmValue * PointerSize + PointerSize;
       RemainingLoopCount = 0;
       if (TableKind == Kind::Lazy)
         Malformed = true;
diff --git a/llvm/test/tools/llvm-objdump/Inputs/bind2.macho-x86_64 b/llvm/test/tools/llvm-objdump/Inputs/bind2.macho-x86_64
new file mode 100755 (executable)
index 0000000..f756fbb
Binary files /dev/null and b/llvm/test/tools/llvm-objdump/Inputs/bind2.macho-x86_64 differ
diff --git a/llvm/test/tools/llvm-objdump/macho-bind2.test b/llvm/test/tools/llvm-objdump/macho-bind2.test
new file mode 100644 (file)
index 0000000..2eee2fc
--- /dev/null
@@ -0,0 +1,5 @@
+# RUN: llvm-objdump -macho -bind %p/Inputs/bind2.macho-x86_64 | FileCheck %s  
+
+# CHECK: __DATA   __data             0x00001008 pointer         0 libSystem        _malloc
+# CHECK: __DATA   __data             0x00001050 pointer         0 libSystem        _malloc
+# CHECK: __DATA   __data             0x00001458 pointer         0 libSystem        _malloc