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.

llvm-svn: 301072
This commit is contained in:
David Blaikie 2017-04-22 07:53:44 +00:00
parent 6cce69020c
commit 85366acf15
5 changed files with 64 additions and 13 deletions

View File

@ -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.

View File

@ -655,20 +655,12 @@ void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
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();
if (const MCSymbol *SectionSym =
Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
return;
}
}
AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
return;
}

View File

@ -1595,3 +1595,11 @@ void DwarfTypeUnit::addGlobalType(const DIType *Ty, const DIE &Die,
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();
}

View File

@ -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 {

View File

@ -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)