From 9031fd9199085fed309a68507bc74637fe6b7695 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 22 May 2017 07:02:47 +0000 Subject: [PATCH] libDebugInfo/DWARF: Apply relocations for debug_addr addresses in object files llvm-symbolizer would fail to symbolize addresses in unlinked object files when handling .dwo file data because the addresses would not be relocated in the same way as the ranges in the skeleton CU in the object file. Fix that so object files can be symbolized the same as executables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303532 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/DebugInfo/DWARF/DWARFCompileUnit.h | 5 ++-- include/llvm/DebugInfo/DWARF/DWARFContext.h | 8 ++--- include/llvm/DebugInfo/DWARF/DWARFTypeUnit.h | 5 ++-- include/llvm/DebugInfo/DWARF/DWARFUnit.h | 14 ++++----- lib/DebugInfo/DWARF/DWARFContext.cpp | 28 ++++++++++-------- lib/DebugInfo/DWARF/DWARFUnit.cpp | 14 ++++----- .../split-dwarf-addr-object-relocation.dwo | Bin 0 -> 1056 bytes .../split-dwarf-addr-object-relocation.o | Bin 0 -> 2968 bytes test/DebugInfo/llvm-symbolizer.test | 7 +++++ 9 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 test/DebugInfo/Inputs/split-dwarf-addr-object-relocation.dwo create mode 100644 test/DebugInfo/Inputs/split-dwarf-addr-object-relocation.o diff --git a/include/llvm/DebugInfo/DWARF/DWARFCompileUnit.h b/include/llvm/DebugInfo/DWARF/DWARFCompileUnit.h index a46d46a5bff..46c0b7f4ce6 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFCompileUnit.h +++ b/include/llvm/DebugInfo/DWARF/DWARFCompileUnit.h @@ -19,8 +19,9 @@ class DWARFCompileUnit : public DWARFUnit { public: DWARFCompileUnit(DWARFContext &Context, const DWARFSection &Section, const DWARFDebugAbbrev *DA, const DWARFSection *RS, - StringRef SS, StringRef SOS, StringRef AOS, StringRef LS, - bool LE, bool IsDWO, const DWARFUnitSectionBase &UnitSection, + StringRef SS, StringRef SOS, const DWARFSection *AOS, + StringRef LS, bool LE, bool IsDWO, + const DWARFUnitSectionBase &UnitSection, const DWARFUnitIndex::Entry *Entry) : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LS, LE, IsDWO, UnitSection, Entry) {} diff --git a/include/llvm/DebugInfo/DWARF/DWARFContext.h b/include/llvm/DebugInfo/DWARF/DWARFContext.h index ca82a68ead3..d3a63edf10f 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -235,7 +235,7 @@ public: virtual StringRef getStringDWOSection() = 0; virtual StringRef getStringOffsetDWOSection() = 0; virtual const DWARFSection &getRangeDWOSection() = 0; - virtual StringRef getAddrSection() = 0; + virtual const DWARFSection &getAddrSection() = 0; virtual const DWARFSection& getAppleNamesSection() = 0; virtual const DWARFSection& getAppleTypesSection() = 0; virtual const DWARFSection& getAppleNamespacesSection() = 0; @@ -290,7 +290,7 @@ class DWARFContextInMemory : public DWARFContext { StringRef StringDWOSection; StringRef StringOffsetDWOSection; DWARFSection RangeDWOSection; - StringRef AddrSection; + DWARFSection AddrSection; DWARFSection AppleNamesSection; DWARFSection AppleTypesSection; DWARFSection AppleNamespacesSection; @@ -356,9 +356,7 @@ public: const DWARFSection &getRangeDWOSection() override { return RangeDWOSection; } - StringRef getAddrSection() override { - return AddrSection; - } + const DWARFSection &getAddrSection() override { return AddrSection; } StringRef getCUIndexSection() override { return CUIndexSection; } StringRef getGdbIndexSection() override { return GdbIndexSection; } diff --git a/include/llvm/DebugInfo/DWARF/DWARFTypeUnit.h b/include/llvm/DebugInfo/DWARF/DWARFTypeUnit.h index c9da2c9a3e1..c77d946c070 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFTypeUnit.h +++ b/include/llvm/DebugInfo/DWARF/DWARFTypeUnit.h @@ -31,8 +31,9 @@ private: public: DWARFTypeUnit(DWARFContext &Context, const DWARFSection &Section, const DWARFDebugAbbrev *DA, const DWARFSection *RS, - StringRef SS, StringRef SOS, StringRef AOS, StringRef LS, - bool LE, bool IsDWO, const DWARFUnitSectionBase &UnitSection, + StringRef SS, StringRef SOS, const DWARFSection *AOS, + StringRef LS, bool LE, bool IsDWO, + const DWARFUnitSectionBase &UnitSection, const DWARFUnitIndex::Entry *Entry) : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LS, LE, IsDWO, UnitSection, Entry) {} diff --git a/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/include/llvm/DebugInfo/DWARF/DWARFUnit.h index 9d69f60e4c1..ae7fd24ce5b 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -57,7 +57,7 @@ protected: virtual void parseImpl(DWARFContext &Context, const DWARFSection &Section, const DWARFDebugAbbrev *DA, const DWARFSection *RS, - StringRef SS, StringRef SOS, StringRef AOS, + StringRef SS, StringRef SOS, const DWARFSection *AOS, StringRef LS, bool isLittleEndian, bool isDWO) = 0; }; @@ -89,8 +89,8 @@ public: private: void parseImpl(DWARFContext &Context, const DWARFSection &Section, const DWARFDebugAbbrev *DA, const DWARFSection *RS, - StringRef SS, StringRef SOS, StringRef AOS, StringRef LS, - bool LE, bool IsDWO) override { + StringRef SS, StringRef SOS, const DWARFSection *AOS, + StringRef LS, bool LE, bool IsDWO) override { if (Parsed) return; const auto &Index = getDWARFUnitIndex(Context, UnitType::Section); @@ -120,7 +120,7 @@ class DWARFUnit { StringRef LineSection; StringRef StringSection; StringRef StringOffsetSection; - StringRef AddrOffsetSection; + const DWARFSection *AddrOffsetSection; uint32_t AddrOffsetSectionBase; bool isLittleEndian; bool isDWO; @@ -172,8 +172,8 @@ protected: public: DWARFUnit(DWARFContext &Context, const DWARFSection &Section, const DWARFDebugAbbrev *DA, const DWARFSection *RS, StringRef SS, - StringRef SOS, StringRef AOS, StringRef LS, bool LE, bool IsDWO, - const DWARFUnitSectionBase &UnitSection, + StringRef SOS, const DWARFSection *AOS, StringRef LS, bool LE, + bool IsDWO, const DWARFUnitSectionBase &UnitSection, const DWARFUnitIndex::Entry *IndexEntry = nullptr); virtual ~DWARFUnit(); @@ -184,7 +184,7 @@ public: StringRef getStringSection() const { return StringSection; } StringRef getStringOffsetSection() const { return StringOffsetSection; } - void setAddrOffsetSection(StringRef AOS, uint32_t Base) { + void setAddrOffsetSection(const DWARFSection *AOS, uint32_t Base) { AddrOffsetSection = AOS; AddrOffsetSectionBase = Base; } diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 7365c92056a..8e7c6c43d1a 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -1063,18 +1063,20 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, // TODO: Add support for relocations in other sections as needed. // Record relocations for the debug_info and debug_line sections. - RelocAddrMap *Map = StringSwitch(RelSecName) - .Case("debug_info", &InfoSection.Relocs) - .Case("debug_loc", &LocSection.Relocs) - .Case("debug_info.dwo", &InfoDWOSection.Relocs) - .Case("debug_line", &LineSection.Relocs) - .Case("debug_ranges", &RangeSection.Relocs) - .Case("apple_names", &AppleNamesSection.Relocs) - .Case("apple_types", &AppleTypesSection.Relocs) - .Case("apple_namespaces", &AppleNamespacesSection.Relocs) - .Case("apple_namespac", &AppleNamespacesSection.Relocs) - .Case("apple_objc", &AppleObjCSection.Relocs) - .Default(nullptr); + RelocAddrMap *Map = + StringSwitch(RelSecName) + .Case("debug_info", &InfoSection.Relocs) + .Case("debug_loc", &LocSection.Relocs) + .Case("debug_info.dwo", &InfoDWOSection.Relocs) + .Case("debug_line", &LineSection.Relocs) + .Case("debug_ranges", &RangeSection.Relocs) + .Case("debug_addr", &AddrSection.Relocs) + .Case("apple_names", &AppleNamesSection.Relocs) + .Case("apple_types", &AppleTypesSection.Relocs) + .Case("apple_namespaces", &AppleNamespacesSection.Relocs) + .Case("apple_namespac", &AppleNamespacesSection.Relocs) + .Case("apple_objc", &AppleObjCSection.Relocs) + .Default(nullptr); if (!Map) { // Find debug_types relocs by section rather than name as there are // multiple, comdat grouped, debug_types sections. @@ -1148,7 +1150,7 @@ StringRef *DWARFContextInMemory::MapSectionToMember(StringRef Name) { .Case("debug_line.dwo", &LineDWOSection.Data) .Case("debug_str.dwo", &StringDWOSection) .Case("debug_str_offsets.dwo", &StringOffsetDWOSection) - .Case("debug_addr", &AddrSection) + .Case("debug_addr", &AddrSection.Data) .Case("apple_names", &AppleNamesSection.Data) .Case("apple_types", &AppleTypesSection.Data) .Case("apple_namespaces", &AppleNamespacesSection.Data) diff --git a/lib/DebugInfo/DWARF/DWARFUnit.cpp b/lib/DebugInfo/DWARF/DWARFUnit.cpp index a784968e269..c268afc222c 100644 --- a/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -33,7 +33,7 @@ using namespace dwarf; void DWARFUnitSectionBase::parse(DWARFContext &C, const DWARFSection &Section) { parseImpl(C, Section, C.getDebugAbbrev(), &C.getRangeSection(), - C.getStringSection(), StringRef(), C.getAddrSection(), + C.getStringSection(), StringRef(), &C.getAddrSection(), C.getLineSection().Data, C.isLittleEndian(), false); } @@ -42,14 +42,14 @@ void DWARFUnitSectionBase::parseDWO(DWARFContext &C, DWARFUnitIndex *Index) { parseImpl(C, DWOSection, C.getDebugAbbrevDWO(), &C.getRangeDWOSection(), C.getStringDWOSection(), C.getStringOffsetDWOSection(), - C.getAddrSection(), C.getLineDWOSection().Data, C.isLittleEndian(), + &C.getAddrSection(), C.getLineDWOSection().Data, C.isLittleEndian(), true); } DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section, const DWARFDebugAbbrev *DA, const DWARFSection *RS, - StringRef SS, StringRef SOS, StringRef AOS, StringRef LS, - bool LE, bool IsDWO, + StringRef SS, StringRef SOS, const DWARFSection *AOS, + StringRef LS, bool LE, bool IsDWO, const DWARFUnitSectionBase &UnitSection, const DWARFUnitIndex::Entry *IndexEntry) : Context(DC), InfoSection(Section), Abbrev(DA), RangeSection(RS), @@ -69,10 +69,10 @@ DWARFUnit::~DWARFUnit() = default; bool DWARFUnit::getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const { uint32_t Offset = AddrOffsetSectionBase + Index * AddrSize; - if (AddrOffsetSection.size() < Offset + AddrSize) + if (AddrOffsetSection->Data.size() < Offset + AddrSize) return false; - DataExtractor DA(AddrOffsetSection, isLittleEndian, AddrSize); - Result = DA.getAddress(&Offset); + DataExtractor DA(AddrOffsetSection->Data, isLittleEndian, AddrSize); + Result = getRelocatedValue(DA, AddrSize, &Offset, &AddrOffsetSection->Relocs); return true; } diff --git a/test/DebugInfo/Inputs/split-dwarf-addr-object-relocation.dwo b/test/DebugInfo/Inputs/split-dwarf-addr-object-relocation.dwo new file mode 100644 index 0000000000000000000000000000000000000000..2a3bc57caa6de0845e445c1b9d072d8671989023 GIT binary patch literal 1056 zcmbu7ze~eF6vyACNi7tG+QATO6A;v4SH6|sA?WS086WpZ! z32wUhzxYQui8#3UE+#e{83YgB-Fu(!_wI$uUA1<$IYJ;A1XLJT2?Y?jajr$F1_hXa zpyzbMnmN#YyQZ6_U-OJps}t6I%kesT*!5h=9C*-iboW^7TYi8_H~L^VqD;X|i9T@&=Oc_8j9ZL5jC+hN3?2iZ zK!EVTy}Vz(eXfmWI4B|{dlj5>Ii7HYCqG2U6G5Pu6R0DPQ6f*xp;{TLWg$0IpPLgX zN>I91r}Nruy^JSF;0{&P){7g(%{dWI;w2Ir(h7jE2=#KL>=zGc$4S}>?-%=!uPORR zq~Ih7{ZKbRGA-lcxQ!Pa-ECZ=$dql*wgW2+(zxr|Ub@x|!?*fr;&fdrsYNI}(&=>)Nh9kcDBN<2 zUdDB*jiT*U8g;95r$Oi2UbF3yF+%CF7jvoc)XTYnS94<{#wbee<7W->Q*u>XuYcVC z_Vd8fm~T>SJUr0#Z4AVGFw1-=KjmrK3z73tDpu|K4YT98E$+%nGI=|{0+Lzo+E z2Z1r^Hixko9cFGAzfwcY{g=cU4f=}%-zN|Z-Da;Ff*`4>fT^(J*&oDw?ZkK;7h2OsH!5A?y4eQcIfS zDb)ub?!hM*N%x>clZ=gq)=fG%pm2#1{9j-8!sY4mREHp@1Ci^XysRv?0lNRa63}KC znRHw}^L1so z5GlCyA+=Cf)&zM?FecOt*FEH;U0m{>R=DI>Ln5nnx8~UemYy5Po1*c7XIq}L=#f=& z3hf&UY!KBh6kMl6mhTf-EA?_i%r2ivPD@5LyBHWl-Z)uTg*V%Ux?Mw1u~Dlzb*@@( zc#d`I+OB6t^|TCB}Kp&ByuXG`v%1xE4k|8iSRuhfgyAmj7jfH z>IPP#qpU>DKMj!SNgxRG$9~r5e}OSQCqh1eMUd`$oqco+VG^&~^s(C~{v(nw$$JV$ zy|rp=h?@VhntxseV*a=#^!YzzOz#OHU%{A6pLdz=d!J2F^}ne4(m(3stk&y4Wehp9 z{Df&x6_R^jY*Jt3Gd74WK9I9fV1)0>0BeTNG{omsJoZPJq<_Jlvl2CbIXq=vm_Kem ziI;VG%UD#aOA4&8Jxsdq8#YGO&#J>)>YzUU4e0fePoFzOlvJSff%^gXq8^Vu6~51S b=+m+S@y{$wdjIGtDn76Je;*EJU620*7qQ!q literal 0 HcmV?d00001 diff --git a/test/DebugInfo/llvm-symbolizer.test b/test/DebugInfo/llvm-symbolizer.test index 542a10fcbe9..f0db8f4b921 100644 --- a/test/DebugInfo/llvm-symbolizer.test +++ b/test/DebugInfo/llvm-symbolizer.test @@ -25,6 +25,8 @@ RUN: echo "%p/Inputs/split-dwarf-test 0x4005c4" >> %t.input RUN: echo "%p/Inputs/cross-cu-inlining.x86_64-macho.o 0x17" >> %t.input RUN: cp %p/Inputs/split-dwarf-multiple-cu.dwo %T RUN: echo "%p/Inputs/split-dwarf-multiple-cu.o 0x4" >> %t.input +RUN: cp %p/Inputs/split-dwarf-addr-object-relocation.dwo %T +RUN: echo "%p/Inputs/split-dwarf-addr-object-relocation.o 0x14" >> %t.input RUN: llvm-symbolizer --functions=linkage --inlining --demangle=false \ RUN: --default-arch=i386 < %t.input | FileCheck --check-prefix=CHECK --check-prefix=SPLIT --check-prefix=DWO %s @@ -140,6 +142,11 @@ CHECK-NEXT: b.cpp:3:3 CHECK-NEXT: f3 CHECK-NEXT: b.cpp:6:0 +CHECK: f2 +CHECK-NEXT: split-dwarf-addr-object-relocation.cpp:3:3 +CHECK-NEXT: f3 +CHECK-NEXT: split-dwarf-addr-object-relocation.cpp:6:0 + RUN: echo "unexisting-file 0x1234" > %t.input2 RUN: llvm-symbolizer < %t.input2 2>&1 | FileCheck %s --check-prefix=MISSING-FILE -- 2.50.1