[llvm] r245807 - [dwarfdump] Do not apply relocations in mach-o files if there is no LoadedObjectInfo.

Frederic Riss via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 21:44:21 PDT 2015


Author: friss
Date: Sat Aug 22 23:44:21 2015
New Revision: 245807

URL: http://llvm.org/viewvc/llvm-project?rev=245807&view=rev
Log:
[dwarfdump] Do not apply relocations in mach-o files if there is no LoadedObjectInfo.

Not only do we not need to do anything to read correct values from the
object files, but the current logic actually wrongly applies twice the
section base address when there is no LoadedObjectInfo passed to the
DWARFContext creation (as the added test shows).

Simply do not apply any relocations on the mach-o debug info if there is
no load offset to apply.

Added:
    llvm/trunk/test/DebugInfo/Inputs/dwarfdump-macho-relocs.macho.x86_64.o
    llvm/trunk/test/DebugInfo/dwarfdump-macho-relocs.test
Modified:
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=245807&r1=245806&r2=245807&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Sat Aug 22 23:44:21 2015
@@ -637,6 +637,14 @@ DWARFContextInMemory::DWARFContextInMemo
     if (L && L->getLoadedSectionContents(*RelocatedSection,RelSecData))
       continue;
 
+    // In Mach-o files, the relocations do not need to be applied if
+    // there is no load offset to apply. The value read at the
+    // relocation point already factors in the section address
+    // (actually applying the relocations will produce wrong results
+    // as the section address will be added twice).
+    if (!L && dyn_cast<MachOObjectFile>(&Obj))
+      continue;
+
     RelSecName = RelSecName.substr(
         RelSecName.find_first_not_of("._")); // Skip . and _ prefixes.
 

Added: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-macho-relocs.macho.x86_64.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-macho-relocs.macho.x86_64.o?rev=245807&view=auto
==============================================================================
Binary files llvm/trunk/test/DebugInfo/Inputs/dwarfdump-macho-relocs.macho.x86_64.o (added) and llvm/trunk/test/DebugInfo/Inputs/dwarfdump-macho-relocs.macho.x86_64.o Sat Aug 22 23:44:21 2015 differ

Added: llvm/trunk/test/DebugInfo/dwarfdump-macho-relocs.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-macho-relocs.test?rev=245807&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/dwarfdump-macho-relocs.test (added)
+++ llvm/trunk/test/DebugInfo/dwarfdump-macho-relocs.test Sat Aug 22 23:44:21 2015
@@ -0,0 +1,27 @@
+// RUN: llvm-dwarfdump -debug-dump=info %p/Inputs/dwarfdump-macho-relocs.macho.x86_64.o | FileCheck %s
+
+// The dumped file has 2 functions in different sections of the __TEXT segment.
+// Check that the addresses are are dumped correctly
+
+// Compiled with: clang -x c -g -c -o dwarfdump-macho-relocs.macho.x86_64.o dwarfdump-macho-relocs.test
+
+__attribute__((section("__TEXT,__blah")))
+int foo() {
+        return 42;
+}
+
+// CHECK:  DW_TAG_subprogram
+// CHECK-NEXT:    DW_AT_low_pc{{.*}}0x0000000000000020
+// CHECK-NEXT:    DW_AT_high_pc{{.*}}0x000000000000002b
+// CHECK-NEXT:    DW_AT_frame_base
+// CHECK-NEXT:    DW_AT_name{{.*}}"foo"
+
+int main() {
+        return foo();
+}
+
+// CHECK:  DW_TAG_subprogram
+// CHECK-NEXT:    DW_AT_low_pc{{.*}}0x0000000000000000
+// CHECK-NEXT:    DW_AT_high_pc{{.*}}0x000000000000001a
+// CHECK-NEXT:    DW_AT_frame_base
+// CHECK-NEXT:    DW_AT_name{{.*}}"main"




More information about the llvm-commits mailing list