[dwarfdump] Ignore scattered relocations for mach-o.
authorFrederic Riss <friss@apple.com>
Fri, 31 Jul 2015 20:22:50 +0000 (20:22 +0000)
committerFrederic Riss <friss@apple.com>
Fri, 31 Jul 2015 20:22:50 +0000 (20:22 +0000)
When encountering a scattered relocation, the code would assert trying to
access an unexisting section. I couldn't find a way to expose the result
of the processing of a scattered reloc, and I'm really unsure what the
right thing to do is. This patch just skips them during the processing in
DwarfContext and adds a mach-o file to the tests that exposed the asserting
behavior.
(This is a new failure that is being exposed by Rafael's recent work on
the libObject interfaces. I think the wrong behavior has always happened,
but now it's asserting)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243778 91177308-0d34-0410-b5e6-96231b3b80d8

lib/DebugInfo/DWARF/DWARFContext.cpp
test/DebugInfo/Inputs/dwarfdump-test.cc
test/DebugInfo/Inputs/dwarfdump-test.macho-i386.o [new file with mode: 0644]
test/DebugInfo/dwarfdump-dump-flags.test

index 4858f3633d038481d0442c54fbebf0a8c5f7595a..408214339a8dab2ae04945c455bc9f924f48412e 100644 (file)
@@ -689,9 +689,15 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
         } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
           // MachO also has relocations that point to sections and
           // scattered relocations.
         } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {
           // MachO also has relocations that point to sections and
           // scattered relocations.
-          // FIXME: We are not handling scattered relocations, do we have to?
-          RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
-          SymAddr = RSec->getAddress();
+          auto RelocInfo = MObj->getRelocation(Reloc.getRawDataRefImpl());
+          if (MObj->isRelocationScattered(RelocInfo)) {
+            // FIXME: it's not clear how to correctly handle scattered
+            // relocations.
+            continue;
+          } else {
+            RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
+            SymAddr = RSec->getAddress();
+          }
         }
 
         // If we are given load addresses for the sections, we need to adjust:
         }
 
         // If we are given load addresses for the sections, we need to adjust:
index 14295d3cffa0a15ad41273732d5e3b86b6514ec5..815c33dd3ac3bf2d678f749e2cf04cb7c3b8077c 100644 (file)
@@ -27,3 +27,5 @@ int main() {
 // $ cp <output> output2.dwz
 // $ dwz -m output.dwz -r output1.dwz output2.dwz
 // $ rm output2.dwz
 // $ cp <output> output2.dwz
 // $ dwz -m output.dwz -r output1.dwz output2.dwz
 // $ rm output2.dwz
+
+// The mach-o version was generated using clang-3.6.2.
diff --git a/test/DebugInfo/Inputs/dwarfdump-test.macho-i386.o b/test/DebugInfo/Inputs/dwarfdump-test.macho-i386.o
new file mode 100644 (file)
index 0000000..b53c8a6
Binary files /dev/null and b/test/DebugInfo/Inputs/dwarfdump-test.macho-i386.o differ
index 92b2d50f393bb7a10311712ffb9e61f1f612abb9..4c10bede6f83e0949c998659ef716637b2168bb4 100644 (file)
@@ -1,6 +1,9 @@
 ; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.elf-x86-64 -debug-dump=all | FileCheck %s -check-prefix DUMP_ALL
 ; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.elf-x86-64 -debug-dump=info | FileCheck %s -check-prefix DUMP_INFO
 ; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.elf-x86-64 -debug-dump=ranges | FileCheck %s -check-prefix DUMP_RANGES
 ; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.elf-x86-64 -debug-dump=all | FileCheck %s -check-prefix DUMP_ALL
 ; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.elf-x86-64 -debug-dump=info | FileCheck %s -check-prefix DUMP_INFO
 ; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.elf-x86-64 -debug-dump=ranges | FileCheck %s -check-prefix DUMP_RANGES
+; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.macho-i386.o -debug-dump=all | FileCheck %s -check-prefix DUMP_ALL
+; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.macho-i386.o -debug-dump=info | FileCheck %s -check-prefix DUMP_INFO
+; RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test.macho-i386.o -debug-dump=ranges | FileCheck %s -check-prefix DUMP_RANGES
 
 ; DUMP_ALL: .debug_info
 ; DUMP_ALL: .debug_ranges
 
 ; DUMP_ALL: .debug_info
 ; DUMP_ALL: .debug_ranges