From 4ec5a9159bc9e4b98010b3688a0c79a4a8d75402 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 11 Sep 2018 02:04:45 +0000 Subject: [PATCH] llvm-symbolizer: Fix bug related to TUs interfering with symbolizing With the merge of TUs and CUs into a single container, some code that relied on the CU range having an ordered range of contiguous addresses (for locating a CU at a given offset) broke. But the units from debug_info (currently only CUs, but CUs and TUs in DWARFv5) are in a contiguous sub-range of that container - searching only through that subrange is still valid & so do that. llvm-svn: 341889 --- llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h | 10 ++++--- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp | 29 ++++++++++++--------- .../DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64 | Bin 0 -> 3816 bytes llvm/test/DebugInfo/llvm-symbolizer-tu.test | 8 ++++++ 4 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 llvm/test/DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64 create mode 100644 llvm/test/DebugInfo/llvm-symbolizer-tu.test diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h index 0908504..d3be52d 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -110,7 +110,7 @@ class DWARFUnitVector final : public SmallVector, 1> std::function(uint32_t, DWARFSectionKind, const DWARFSection *)> Parser; - unsigned NumInfoUnits = 0; + int NumInfoUnits = -1; public: using UnitVector = SmallVectorImpl>; @@ -135,11 +135,13 @@ public: DWARFSectionKind SectionKind, bool Lazy = false); /// Returns number of all units held by this instance. - unsigned getNumUnits() { return size(); } + unsigned getNumUnits() const { return size(); } /// Returns number of units from all .debug_info[.dwo] sections. - unsigned getNumInfoUnits() { return NumInfoUnits; } + unsigned getNumInfoUnits() const { + return NumInfoUnits == -1 ? size() : NumInfoUnits; + } /// Returns number of units from all .debug_types[.dwo] sections. - unsigned getNumTypesUnits() { return size() - NumInfoUnits; } + unsigned getNumTypesUnits() const { return size() - NumInfoUnits; } /// Indicate that parsing .debug_info[.dwo] is done, and remaining units /// will be from .debug_types[.dwo]. void finishedInfoUnits() { NumInfoUnits = size(); } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index 1b58ef7..b2bc2c8 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -113,12 +113,13 @@ void DWARFUnitVector::addUnitsImpl( } DWARFUnit *DWARFUnitVector::getUnitForOffset(uint32_t Offset) const { - auto *CU = std::upper_bound( - this->begin(), this->end(), Offset, - [](uint32_t LHS, const std::unique_ptr &RHS) { - return LHS < RHS->getNextUnitOffset(); - }); - if (CU != this->end() && (*CU)->getOffset() <= Offset) + auto end = begin() + getNumInfoUnits(); + auto *CU = + std::upper_bound(begin(), end, Offset, + [](uint32_t LHS, const std::unique_ptr &RHS) { + return LHS < RHS->getNextUnitOffset(); + }); + if (CU != end && (*CU)->getOffset() <= Offset) return CU->get(); return nullptr; } @@ -130,13 +131,14 @@ DWARFUnitVector::getUnitForIndexEntry(const DWARFUnitIndex::Entry &E) { return nullptr; auto Offset = CUOff->Offset; - - auto *CU = std::upper_bound( - this->begin(), this->end(), CUOff->Offset, - [](uint32_t LHS, const std::unique_ptr &RHS) { - return LHS < RHS->getNextUnitOffset(); - }); - if (CU != this->end() && (*CU)->getOffset() <= Offset) + auto end = begin() + getNumInfoUnits(); + + auto *CU = + std::upper_bound(begin(), end, CUOff->Offset, + [](uint32_t LHS, const std::unique_ptr &RHS) { + return LHS < RHS->getNextUnitOffset(); + }); + if (CU != end && (*CU)->getOffset() <= Offset) return CU->get(); if (!Parser) @@ -148,6 +150,7 @@ DWARFUnitVector::getUnitForIndexEntry(const DWARFUnitIndex::Entry &E) { auto *NewCU = U.get(); this->insert(CU, std::move(U)); + ++NumInfoUnits; return NewCU; } diff --git a/llvm/test/DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64 b/llvm/test/DebugInfo/Inputs/llvm-symbolizer-tu.elf-x86-64 new file mode 100644 index 0000000000000000000000000000000000000000..93a46c099e38b2a35010021bbe310e968d7e5095 GIT binary patch literal 3816 zcmbtW&2L*p5TEy6>?C#LCUI#UTEK`_qynDpJUej!wGIf9NNp96Qb9!(Jv%Rs72D7F zBT7LCPAGu`a6=pr2mXKvE)@ra)E+r-;DpKr34}Nx5SL0Im6?6B_GbN}iZar^nfcAk z?(FXD?tA-%i!Yjn0g?xbwu`{XZPOID4N;$b~!Ew%|rfaqBdb*G0vgg1R=mcvwt$*3 zVVsR8B369- z0>F<+f`iR4M=g?xgb*2m*HPwB0UZn#uK2;}u@@`G6=^c8i22cuVZDL?N=?JsAXD@j zeun=k|8V-JZ@Pu(7HPXzzRi67m-!G{$pz^MHg&|K0uAs9l;>HW)bJ+jClq{`WnvF1 zIQ2vM6Fm|zF)rcTtUtk=Ru5OUM>&=#Px2>Dv=Fdf{!g;LsNib;mo%JJcuB!2|HoNh zRdDJ@=Km_=l&9EM*2R*etm7TF%lzMDeMiHk4)=Rh;4$oR2ykn`FpR(BW5g&MYz7}B z8nb}yP`BWGlN*foW_LW2Jo1%kVt)uzqZ%2*b_N?)t}L^M5i$bIjG#IQ#v3n#u`_O*IyyY^AtrSi zacV@ORuYp;9h|i(?-U=j zS)!s2Vx(E(#tFlFm-qpr1+BHanM}$z`3{e0HV)xy)?AnVp}{=I7=L&dgjsR{(e5U*Nzl+@C_{ zikiG9WG_V)di%pV-9IW(UDNLCm2sJ!A9KJ1XrS9go|GgzK8IZIlT7=( zp!(gY`_es1n7)2ra6CPGD#>`sucA@Ps^4!MUsk~oUwZ$oi+6ow?_lfEC4HmWqK`%Y z3G|<#(+bDS8;#bFZavwp