[llvm] r301072 - Avoid using relocations for ref_addr in .dwo files

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 22 00:53:44 PDT 2017


Author: dblaikie
Date: Sat Apr 22 02:53:44 2017
New Revision: 301072

URL: http://llvm.org/viewvc/llvm-project?rev=301072&view=rev
Log:
Avoid using relocations for ref_addr in .dwo files

In dwo files the fixed offset can be used - if the dwos are linked into
a dwp, the dwo consumer must use the dwp tables to find out where the
original range of the debug_info was and resolve the "section relative"
value relative to that original range - effectively
avoiding/reimplementing the relocation handling.

Added:
    llvm/trunk/test/DebugInfo/X86/split-dwarf-cross-unit-reference.ll
Modified:
    llvm/trunk/include/llvm/CodeGen/DIE.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h

Modified: llvm/trunk/include/llvm/CodeGen/DIE.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DIE.h?rev=301072&r1=301071&r2=301072&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/DIE.h (original)
+++ llvm/trunk/include/llvm/CodeGen/DIE.h Sat Apr 22 02:53:44 2017
@@ -811,6 +811,10 @@ public:
     this->Section = Section;
   }
 
+  virtual const MCSymbol *getCrossSectionRelativeBaseAddress() const {
+    return nullptr;
+  }
+
   /// Return the section that this DIEUnit will be emitted into.
   ///
   /// \returns Section pointer which can be NULL.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=301072&r1=301071&r2=301072&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Sat Apr 22 02:53:44 2017
@@ -655,20 +655,12 @@ void DIEEntry::EmitValue(const AsmPrinte
   case dwarf::DW_FORM_ref_addr: {
     // Get the absolute offset for this DIE within the debug info/types section.
     unsigned Addr = Entry->getDebugSectionOffset();
-    if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
-      const DwarfDebug *DD = AP->getDwarfDebug();
-      if (DD)
-        assert(!DD->useSplitDwarf() &&
-               "TODO: dwo files can't have relocations.");
-      const DIEUnit *Unit = Entry->getUnit();
-      assert(Unit && "CUDie should belong to a CU.");
-      MCSection *Section = Unit->getSection();
-      if (Section) {
-        const MCSymbol *SectionSym = Section->getBeginSymbol();
-        AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
-        return;
-      }
+    if (const MCSymbol *SectionSym =
+            Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
+      AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
+      return;
     }
+
     AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
     return;
   }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=301072&r1=301071&r2=301072&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Sat Apr 22 02:53:44 2017
@@ -1595,3 +1595,11 @@ void DwarfTypeUnit::addGlobalType(const
                                   const DIScope *Context) {
   getCU().addGlobalTypeUnitType(Ty, Context);
 }
+
+const MCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress() const {
+  if (!Asm->MAI->doesDwarfUseRelocationsAcrossSections())
+    return nullptr;
+  if (isDwoUnit())
+    return nullptr;
+  return getSection()->getBeginSymbol();
+}

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=301072&r1=301071&r2=301072&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Sat Apr 22 02:53:44 2017
@@ -335,6 +335,7 @@ private:
   void setIndexTyDie(DIE *D) { IndexTyDie = D; }
 
   virtual bool isDwoUnit() const = 0;
+  const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
 };
 
 class DwarfTypeUnit final : public DwarfUnit {

Added: llvm/trunk/test/DebugInfo/X86/split-dwarf-cross-unit-reference.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/split-dwarf-cross-unit-reference.ll?rev=301072&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/split-dwarf-cross-unit-reference.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/split-dwarf-cross-unit-reference.ll Sat Apr 22 02:53:44 2017
@@ -0,0 +1,46 @@
+; RUN: llc -split-dwarf-file=foo.dwo -filetype=obj -o - < %s | llvm-objdump -r - | FileCheck %s
+
+; CHECK-NOT: .rela.debug_info.dwo
+; CHECK: RELOCATION RECORDS FOR [.rela.debug_info]:
+; CHECK-NOT: RELOCATION RECORDS
+; Expect one relocation in debug_info, between f3 and f1.
+; CHECK: R_X86_64_32 .debug_info
+; CHECK-NOT: .debug_info
+; CHECK: RELOCATION RECORDS
+; CHECK-NOT: .rela.debug_info.dwo
+
+
+; Function Attrs: noinline nounwind optnone uwtable
+define void @_Z2f1v() !dbg !7 {
+entry:
+  ret void, !dbg !10
+}
+
+; Function Attrs: noinline uwtable
+define void @_Z2f3v() !dbg !13 {
+entry:
+  call void @_Z2f1v(), !dbg !14
+  ret void, !dbg !16
+}
+
+!llvm.dbg.cu = !{!0, !3}
+!llvm.ident = !{!5, !5}
+!llvm.module.flags = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 301051) (llvm/trunk 301062)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "a.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
+!2 = !{}
+!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, producer: "clang version 5.0.0 (trunk 301051) (llvm/trunk 301062)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!4 = !DIFile(filename: "b.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
+!5 = !{!"clang version 5.0.0 (trunk 301051) (llvm/trunk 301062)"}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !DILocation(line: 1, scope: !7)
+!11 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!12 = !DILocation(line: 1, scope: !11)
+!13 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !4, file: !4, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !3, variables: !2)
+!14 = !DILocation(line: 1, scope: !11, inlinedAt: !15)
+!15 = distinct !DILocation(line: 1, scope: !13)
+!16 = !DILocation(line: 1, scope: !13)




More information about the llvm-commits mailing list