<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sat, May 27, 2017 at 11:10 AM George Rimar via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: grimar<br>
Date: Sat May 27 13:10:23 2017<br>
New Revision: 304078<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=304078&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=304078&view=rev</a><br>
Log:<br>
Recommit "[DWARF] - Make collectAddressRanges() return section index in addition to Low/High PC"<br>
<br>
With fix of uninitialized variable.<br></blockquote><div><br>Which variable/where was it uninitialized? Do you know if this was failing reliably with msan?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Original commit message:<br>
<br>
This change is intended to use for LLD in D33183.<br>
Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to.<br>
<br>
Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo<br>
interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's.<br>
That not only was slow, but also complicated implementation and was the reason of incorrect behavior when<br>
sections share the same offsets, like D33176 shows.<br>
<br>
This patch makes DWARF parsers to return section index as well. That solves problem mentioned above.<br>
<br>
Differential revision: <a href="https://reviews.llvm.org/D33184" rel="noreferrer" target="_blank">https://reviews.llvm.org/D33184</a><br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h<br>
    llvm/trunk/include/llvm/Object/COFF.h<br>
    llvm/trunk/include/llvm/Object/ELFObjectFile.h<br>
    llvm/trunk/include/llvm/Object/MachO.h<br>
    llvm/trunk/include/llvm/Object/ObjectFile.h<br>
    llvm/trunk/include/llvm/Object/Wasm.h<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp<br>
    llvm/trunk/lib/Object/COFFObjectFile.cpp<br>
    llvm/trunk/lib/Object/MachOObjectFile.cpp<br>
    llvm/trunk/lib/Object/WasmObjectFile.cpp<br>
    llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h Sat May 27 13:10:23 2017<br>
@@ -46,7 +46,8 @@ class raw_ostream;<br>
 /// Reads a value from data extractor and applies a relocation to the result if<br>
 /// one exists for the given offset.<br>
 uint64_t getRelocatedValue(const DataExtractor &Data, uint32_t Size,<br>
-                           uint32_t *Off, const RelocAddrMap *Relocs);<br>
+                           uint32_t *Off, const RelocAddrMap *Relocs,<br>
+                           uint64_t *SecNdx = nullptr);<br>
<br>
 /// DWARFContext<br>
 /// This data structure is the top level entity that deals with dwarf debug<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h Sat May 27 13:10:23 2017<br>
@@ -25,6 +25,7 @@ class raw_ostream;<br>
 struct DWARFAddressRange {<br>
   uint64_t LowPC;<br>
   uint64_t HighPC;<br>
+  uint64_t SectionIndex;<br>
 };<br>
<br>
 /// DWARFAddressRangesVector - represents a set of absolute address ranges.<br>
@@ -44,6 +45,8 @@ public:<br>
     /// address past the end of the address range. The ending address must<br>
     /// be greater than or equal to the beginning address.<br>
     uint64_t EndAddress;<br>
+    /// A section index this range belongs to.<br>
+    uint64_t SectionIndex;<br>
<br>
     /// The end of any given range list is marked by an end of list entry,<br>
     /// which consists of a 0 for the beginning address offset<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDie.h Sat May 27 13:10:23 2017<br>
@@ -195,7 +195,8 @@ public:<br>
<br>
   /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.<br>
   /// Returns true if both attributes are present.<br>
-  bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC) const;<br>
+  bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC,<br>
+                       uint64_t &SectionIndex) const;<br>
<br>
   /// Get the address ranges for this DIE.<br>
   ///<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h Sat May 27 13:10:23 2017<br>
@@ -47,6 +47,7 @@ private:<br>
       const char *cstr;<br>
     };<br>
     const uint8_t *data = nullptr;<br>
+    uint64_t SectionIndex;      /// Section index for reference forms.<br>
   };<br>
<br>
   dwarf::Form Form;             /// Form for this value.<br>
@@ -58,6 +59,7 @@ public:<br>
<br>
   dwarf::Form getForm() const { return Form; }<br>
   uint64_t getRawUValue() const { return Value.uval; }<br>
+  uint64_t getSectionIndex() const { return Value.SectionIndex; }<br>
   void setForm(dwarf::Form F) { Form = F; }<br>
   void setUValue(uint64_t V) { Value.uval = V; }<br>
   void setSValue(int64_t V) { Value.sval = V; }<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFRelocMap.h Sat May 27 13:10:23 2017<br>
@@ -16,7 +16,10 @@<br>
<br>
 namespace llvm {<br>
<br>
+/// RelocAddrEntry contains relocated value and section index.<br>
+/// Section index is -1LL if relocation points to absolute symbol.<br>
 struct RelocAddrEntry {<br>
+  uint64_t SectionIndex;<br>
   uint64_t Value;<br>
 };<br>
<br>
<br>
Modified: llvm/trunk/include/llvm/Object/COFF.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Object/COFF.h (original)<br>
+++ llvm/trunk/include/llvm/Object/COFF.h Sat May 27 13:10:23 2017<br>
@@ -782,6 +782,7 @@ protected:<br>
   std::error_code getSectionName(DataRefImpl Sec,<br>
                                  StringRef &Res) const override;<br>
   uint64_t getSectionAddress(DataRefImpl Sec) const override;<br>
+  uint64_t getSectionIndex(DataRefImpl Sec) const override;<br>
   uint64_t getSectionSize(DataRefImpl Sec) const override;<br>
   std::error_code getSectionContents(DataRefImpl Sec,<br>
                                      StringRef &Res) const override;<br>
<br>
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)<br>
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Sat May 27 13:10:23 2017<br>
@@ -235,6 +235,7 @@ protected:<br>
   std::error_code getSectionName(DataRefImpl Sec,<br>
                                  StringRef &Res) const override;<br>
   uint64_t getSectionAddress(DataRefImpl Sec) const override;<br>
+  uint64_t getSectionIndex(DataRefImpl Sec) const override;<br>
   uint64_t getSectionSize(DataRefImpl Sec) const override;<br>
   std::error_code getSectionContents(DataRefImpl Sec,<br>
                                      StringRef &Res) const override;<br>
@@ -646,6 +647,17 @@ uint64_t ELFObjectFile<ELFT>::getSection<br>
 }<br>
<br>
 template <class ELFT><br>
+uint64_t ELFObjectFile<ELFT>::getSectionIndex(DataRefImpl Sec) const {<br>
+  auto SectionsOrErr = EF.sections();<br>
+  handleAllErrors(std::move(SectionsOrErr.takeError()),<br>
+                  [](const ErrorInfoBase &) {<br>
+                    llvm_unreachable("unable to get section index");<br>
+                  });<br>
+  const Elf_Shdr *First = SectionsOrErr->begin();<br>
+  return getSection(Sec) - First;<br>
+}<br>
+<br>
+template <class ELFT><br>
 uint64_t ELFObjectFile<ELFT>::getSectionSize(DataRefImpl Sec) const {<br>
   return getSection(Sec)->sh_size;<br>
 }<br>
<br>
Modified: llvm/trunk/include/llvm/Object/MachO.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Object/MachO.h (original)<br>
+++ llvm/trunk/include/llvm/Object/MachO.h Sat May 27 13:10:23 2017<br>
@@ -290,6 +290,7 @@ public:<br>
   std::error_code getSectionName(DataRefImpl Sec,<br>
                                  StringRef &Res) const override;<br>
   uint64_t getSectionAddress(DataRefImpl Sec) const override;<br>
+  uint64_t getSectionIndex(DataRefImpl Sec) const override;<br>
   uint64_t getSectionSize(DataRefImpl Sec) const override;<br>
   std::error_code getSectionContents(DataRefImpl Sec,<br>
                                      StringRef &Res) const override;<br>
<br>
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)<br>
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Sat May 27 13:10:23 2017<br>
@@ -95,6 +95,7 @@ public:<br>
<br>
   std::error_code getName(StringRef &Result) const;<br>
   uint64_t getAddress() const;<br>
+  uint64_t getIndex() const;<br>
   uint64_t getSize() const;<br>
   std::error_code getContents(StringRef &Result) const;<br>
<br>
@@ -222,6 +223,7 @@ protected:<br>
   virtual std::error_code getSectionName(DataRefImpl Sec,<br>
                                          StringRef &Res) const = 0;<br>
   virtual uint64_t getSectionAddress(DataRefImpl Sec) const = 0;<br>
+  virtual uint64_t getSectionIndex(DataRefImpl Sec) const = 0;<br>
   virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;<br>
   virtual std::error_code getSectionContents(DataRefImpl Sec,<br>
                                              StringRef &Res) const = 0;<br>
@@ -393,6 +395,10 @@ inline uint64_t SectionRef::getAddress()<br>
   return OwningObject->getSectionAddress(SectionPimpl);<br>
 }<br>
<br>
+inline uint64_t SectionRef::getIndex() const {<br>
+  return OwningObject->getSectionIndex(SectionPimpl);<br>
+}<br>
+<br>
 inline uint64_t SectionRef::getSize() const {<br>
   return OwningObject->getSectionSize(SectionPimpl);<br>
 }<br>
<br>
Modified: llvm/trunk/include/llvm/Object/Wasm.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Wasm.h?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Wasm.h?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Object/Wasm.h (original)<br>
+++ llvm/trunk/include/llvm/Object/Wasm.h Sat May 27 13:10:23 2017<br>
@@ -119,6 +119,7 @@ public:<br>
   std::error_code getSectionName(DataRefImpl Sec,<br>
                                  StringRef &Res) const override;<br>
   uint64_t getSectionAddress(DataRefImpl Sec) const override;<br>
+  uint64_t getSectionIndex(DataRefImpl Sec) const override;<br>
   uint64_t getSectionSize(DataRefImpl Sec) const override;<br>
   std::error_code getSectionContents(DataRefImpl Sec,<br>
                                      StringRef &Res) const override;<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Sat May 27 13:10:23 2017<br>
@@ -60,12 +60,15 @@ typedef DILineInfoSpecifier::FileLineInf<br>
 typedef DILineInfoSpecifier::FunctionNameKind FunctionNameKind;<br>
<br>
 uint64_t llvm::getRelocatedValue(const DataExtractor &Data, uint32_t Size,<br>
-                                 uint32_t *Off, const RelocAddrMap *Relocs) {<br>
+                                 uint32_t *Off, const RelocAddrMap *Relocs,<br>
+                                 uint64_t *SectionIndex) {<br>
   if (!Relocs)<br>
     return Data.getUnsigned(Off, Size);<br>
   RelocAddrMap::const_iterator AI = Relocs->find(*Off);<br>
   if (AI == Relocs->end())<br>
     return Data.getUnsigned(Off, Size);<br>
+  if (SectionIndex)<br>
+    *SectionIndex = AI->second.SectionIndex;<br>
   return Data.getUnsigned(Off, Size) + AI->second.Value;<br>
 }<br>
<br>
@@ -958,23 +961,29 @@ static Error createError(const Twine &Re<br>
                                  inconvertibleErrorCode());<br>
 }<br>
<br>
-/// Returns the address of symbol relocation used against. Used for futher<br>
-/// relocations computation. Symbol's section load address is taken in account if<br>
-/// LoadedObjectInfo interface is provided.<br>
-static Expected<uint64_t><br>
-getSymbolAddress(const object::ObjectFile &Obj, const RelocationRef &Reloc,<br>
-                 const LoadedObjectInfo *L,<br>
-                 std::map<SymbolRef, uint64_t> &Cache) {<br>
-  uint64_t Ret = 0;<br>
+/// SymInfo contains information about symbol: it's address<br>
+/// and section index which is -1LL for absolute symbols.<br>
+struct SymInfo {<br>
+  uint64_t Address;<br>
+  uint64_t SectionIndex;<br>
+};<br>
+<br>
+/// Returns the address of symbol relocation used against and a section index.<br>
+/// Used for futher relocations computation. Symbol's section load address is<br>
+static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj,<br>
+                                       const RelocationRef &Reloc,<br>
+                                       const LoadedObjectInfo *L,<br>
+                                       std::map<SymbolRef, SymInfo> &Cache) {<br>
+  SymInfo Ret = {0, (uint64_t)-1LL};<br>
   object::section_iterator RSec = Obj.section_end();<br>
   object::symbol_iterator Sym = Reloc.getSymbol();<br>
<br>
-  std::map<SymbolRef, uint64_t>::iterator CacheIt = Cache.end();<br>
+  std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end();<br>
   // First calculate the address of the symbol or section as it appears<br>
   // in the object file<br>
   if (Sym != Obj.symbol_end()) {<br>
     bool New;<br>
-    std::tie(CacheIt, New) = Cache.insert({*Sym, 0});<br>
+    std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}});<br>
     if (!New)<br>
       return CacheIt->second;<br>
<br>
@@ -990,12 +999,15 @@ getSymbolAddress(const object::ObjectFil<br>
                          SectOrErr.takeError());<br>
<br>
     RSec = *SectOrErr;<br>
-    Ret = *SymAddrOrErr;<br>
+    Ret.Address = *SymAddrOrErr;<br>
   } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) {<br>
     RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());<br>
-    Ret = RSec->getAddress();<br>
+    Ret.Address = RSec->getAddress();<br>
   }<br>
<br>
+  if (RSec != Obj.section_end())<br>
+    Ret.SectionIndex = RSec->getIndex();<br>
+<br>
   // If we are given load addresses for the sections, we need to adjust:<br>
   // SymAddr = (Address of Symbol Or Section in File) -<br>
   //           (Address of Section in File) +<br>
@@ -1005,7 +1017,7 @@ getSymbolAddress(const object::ObjectFil<br>
   // we need to perform the same computation.<br>
   if (L && RSec != Obj.section_end())<br>
     if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec))<br>
-      Ret += SectionLoadAddress - RSec->getAddress();<br>
+      Ret.Address += SectionLoadAddress - RSec->getAddress();<br>
<br>
   if (CacheIt != Cache.end())<br>
     CacheIt->second = Ret;<br>
@@ -1064,7 +1076,7 @@ DWARFContextInMemory::DWARFContextInMemo<br>
     // Try to obtain an already relocated version of this section.<br>
     // Else use the unrelocated section from the object file. We'll have to<br>
     // apply relocations ourselves later.<br>
-    if (!L || !L->getLoadedSectionContents(*RelocatedSection,data))<br>
+    if (!L || !L->getLoadedSectionContents(*RelocatedSection, data))<br>
       Section.getContents(data);<br>
<br>
     if (auto Err = maybeDecompress(Section, name, data)) {<br>
@@ -1103,7 +1115,7 @@ DWARFContextInMemory::DWARFContextInMemo<br>
     // If the section we're relocating was relocated already by the JIT,<br>
     // then we used the relocated version above, so we do not need to process<br>
     // relocations for it now.<br>
-    if (L && L->getLoadedSectionContents(*RelocatedSection,RelSecData))<br>
+    if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData))<br>
       continue;<br>
<br>
     // In Mach-o files, the relocations do not need to be applied if<br>
@@ -1147,29 +1159,30 @@ DWARFContextInMemory::DWARFContextInMemo<br>
     if (Section.relocation_begin() == Section.relocation_end())<br>
       continue;<br>
<br>
-    std::map<SymbolRef, uint64_t> AddrCache;<br>
+    // Symbol to [address, section index] cache mapping.<br>
+    std::map<SymbolRef, SymInfo> AddrCache;<br>
     for (const RelocationRef &Reloc : Section.relocations()) {<br>
       // FIXME: it's not clear how to correctly handle scattered<br>
       // relocations.<br>
       if (isRelocScattered(Obj, Reloc))<br>
         continue;<br>
<br>
-      Expected<uint64_t> SymAddrOrErr =<br>
-          getSymbolAddress(Obj, Reloc, L, AddrCache);<br>
-      if (!SymAddrOrErr) {<br>
-        errs() << toString(SymAddrOrErr.takeError()) << '\n';<br>
+      Expected<SymInfo> SymInfoOrErr = getSymbolInfo(Obj, Reloc, L, AddrCache);<br>
+      if (!SymInfoOrErr) {<br>
+        errs() << toString(SymInfoOrErr.takeError()) << '\n';<br>
         continue;<br>
       }<br>
<br>
       object::RelocVisitor V(Obj);<br>
-      uint64_t Val = V.visit(Reloc.getType(), Reloc, *SymAddrOrErr);<br>
+      uint64_t Val = V.visit(Reloc.getType(), Reloc, SymInfoOrErr->Address);<br>
       if (V.error()) {<br>
         SmallString<32> Name;<br>
         Reloc.getTypeName(Name);<br>
         errs() << "error: failed to compute relocation: " << Name << "\n";<br>
         continue;<br>
       }<br>
-      Map->insert({Reloc.getOffset(), {Val}});<br>
+      llvm::RelocAddrEntry Rel = {SymInfoOrErr->SectionIndex, Val};<br>
+      Map->insert({Reloc.getOffset(), Rel});<br>
     }<br>
   }<br>
 }<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp Sat May 27 13:10:23 2017<br>
@@ -35,8 +35,8 @@ bool DWARFDebugRangeList::extract(DataEx<br>
   while (true) {<br>
     RangeListEntry entry;<br>
     uint32_t prev_offset = *offset_ptr;<br>
-    entry.StartAddress =<br>
-        getRelocatedValue(data, AddressSize, offset_ptr, &Relocs);<br>
+    entry.StartAddress = getRelocatedValue(data, AddressSize, offset_ptr,<br>
+                                           &Relocs, &entry.SectionIndex);<br>
     entry.EndAddress =<br>
         getRelocatedValue(data, AddressSize, offset_ptr, &Relocs);<br>
<br>
@@ -69,8 +69,8 @@ DWARFDebugRangeList::getAbsoluteRanges(u<br>
     if (RLE.isBaseAddressSelectionEntry(AddressSize)) {<br>
       BaseAddress = RLE.EndAddress;<br>
     } else {<br>
-      Res.push_back(<br>
-          {BaseAddress + RLE.StartAddress, BaseAddress + RLE.EndAddress});<br>
+      Res.push_back({BaseAddress + RLE.StartAddress,<br>
+                     BaseAddress + RLE.EndAddress, RLE.SectionIndex});<br>
     }<br>
   }<br>
   return Res;<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Sat May 27 13:10:23 2017<br>
@@ -211,13 +211,16 @@ Optional<uint64_t> DWARFDie::getHighPC(u<br>
   return None;<br>
 }<br>
<br>
-bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC) const {<br>
-  auto LowPcAddr = toAddress(find(DW_AT_low_pc));<br>
+bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC,<br>
+                               uint64_t &SectionIndex) const {<br>
+  auto F = find(DW_AT_low_pc);<br>
+  auto LowPcAddr = toAddress(F);<br>
   if (!LowPcAddr)<br>
     return false;<br>
   if (auto HighPcAddr = getHighPC(*LowPcAddr)) {<br>
     LowPC = *LowPcAddr;<br>
     HighPC = *HighPcAddr;<br>
+    SectionIndex = F->getSectionIndex();<br>
     return true;<br>
   }<br>
   return false;<br>
@@ -228,9 +231,9 @@ DWARFDie::getAddressRanges() const {<br>
   if (isNULL())<br>
     return DWARFAddressRangesVector();<br>
   // Single range specified by low/high PC.<br>
-  uint64_t LowPC, HighPC;<br>
-  if (getLowAndHighPC(LowPC, HighPC))<br>
-    return {{LowPC, HighPC}};<br>
+  uint64_t LowPC, HighPC, Index;<br>
+  if (getLowAndHighPC(LowPC, HighPC, Index))<br>
+    return {{LowPC, HighPC, Index}};<br>
<br>
   // Multiple ranges from .debug_ranges section.<br>
   auto RangesOffset = toSectionOffset(find(DW_AT_ranges));<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp Sat May 27 13:10:23 2017<br>
@@ -333,8 +333,8 @@ bool DWARFFormValue::extractValue(const<br>
         return false;<br>
       uint16_t AddrSize = (Form == DW_FORM_addr) ? U->getAddressByteSize()<br>
                                                  : U->getRefAddrByteSize();<br>
-      Value.uval =<br>
-          getRelocatedValue(Data, AddrSize, OffsetPtr, U->getRelocMap());<br>
+      Value.uval = getRelocatedValue(Data, AddrSize, OffsetPtr,<br>
+                                     U->getRelocMap(), &Value.SectionIndex);<br>
       break;<br>
     }<br>
     case DW_FORM_exprloc:<br>
<br>
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Sat May 27 13:10:23 2017<br>
@@ -293,6 +293,10 @@ uint64_t COFFObjectFile::getSectionAddre<br>
   return Result;<br>
 }<br>
<br>
+uint64_t COFFObjectFile::getSectionIndex(DataRefImpl Sec) const {<br>
+  return toSec(Sec) - SectionTable;<br>
+}<br>
+<br>
 uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const {<br>
   return getSectionSize(toSec(Ref));<br>
 }<br>
<br>
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Sat May 27 13:10:23 2017<br>
@@ -1820,6 +1820,10 @@ uint64_t MachOObjectFile::getSectionAddr<br>
   return getSection(Sec).addr;<br>
 }<br>
<br>
+uint64_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {<br>
+  return Sec.d.a;<br>
+}<br>
+<br>
 uint64_t MachOObjectFile::getSectionSize(DataRefImpl Sec) const {<br>
   // In the case if a malformed Mach-O file where the section offset is past<br>
   // the end of the file or some part of the section size is past the end of<br>
<br>
Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Sat May 27 13:10:23 2017<br>
@@ -743,6 +743,10 @@ std::error_code WasmObjectFile::getSecti<br>
<br>
 uint64_t WasmObjectFile::getSectionAddress(DataRefImpl Sec) const { return 0; }<br>
<br>
+uint64_t WasmObjectFile::getSectionIndex(DataRefImpl Sec) const {<br>
+  return Sec.d.a;<br>
+}<br>
+<br>
 uint64_t WasmObjectFile::getSectionSize(DataRefImpl Sec) const {<br>
   const WasmSection &S = Sections[Sec.d.a];<br>
   return S.Content.size();<br>
<br>
Modified: llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp?rev=304078&r1=304077&r2=304078&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp?rev=304078&r1=304077&r2=304078&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp (original)<br>
+++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp Sat May 27 13:10:23 2017<br>
@@ -853,8 +853,8 @@ template <uint16_t Version, class AddrTy<br>
   // Get the compile unit DIE is valid.<br>
   auto DieDG = U->getUnitDIE(false);<br>
   EXPECT_TRUE(DieDG.isValid());<br>
-<br>
-  uint64_t LowPC, HighPC;<br>
+<br>
+  uint64_t LowPC, HighPC, SectionIndex;<br>
   Optional<uint64_t> OptU64;<br>
   // Verify the that our subprogram with no PC value fails appropriately when<br>
   // asked for any PC values.<br>
@@ -865,14 +865,14 @@ template <uint16_t Version, class AddrTy<br>
   EXPECT_FALSE((bool)OptU64);<br>
   OptU64 = toAddress(SubprogramDieNoPC.find(DW_AT_high_pc));<br>
   EXPECT_FALSE((bool)OptU64);<br>
-  EXPECT_FALSE(SubprogramDieNoPC.getLowAndHighPC(LowPC, HighPC));<br>
+  EXPECT_FALSE(SubprogramDieNoPC.getLowAndHighPC(LowPC, HighPC, SectionIndex));<br>
   OptU64 = toAddress(SubprogramDieNoPC.find(DW_AT_high_pc));<br>
   EXPECT_FALSE((bool)OptU64);<br>
   OptU64 = toUnsigned(SubprogramDieNoPC.find(DW_AT_high_pc));<br>
   EXPECT_FALSE((bool)OptU64);<br>
   OptU64 = SubprogramDieNoPC.getHighPC(ActualLowPC);<br>
   EXPECT_FALSE((bool)OptU64);<br>
-  EXPECT_FALSE(SubprogramDieNoPC.getLowAndHighPC(LowPC, HighPC));<br>
+  EXPECT_FALSE(SubprogramDieNoPC.getLowAndHighPC(LowPC, HighPC, SectionIndex));<br>
<br>
   // Verify the that our subprogram with only a low PC value succeeds when<br>
   // we ask for the Low PC, but fails appropriately when asked for the high PC<br>
@@ -889,7 +889,7 @@ template <uint16_t Version, class AddrTy<br>
   EXPECT_FALSE((bool)OptU64);<br>
   OptU64 = SubprogramDieLowPC.getHighPC(ActualLowPC);<br>
   EXPECT_FALSE((bool)OptU64);<br>
-  EXPECT_FALSE(SubprogramDieLowPC.getLowAndHighPC(LowPC, HighPC));<br>
+  EXPECT_FALSE(SubprogramDieLowPC.getLowAndHighPC(LowPC, HighPC, SectionIndex));<br>
<br>
   // Verify the that our subprogram with only a low PC value succeeds when<br>
   // we ask for the Low PC, but fails appropriately when asked for the high PC<br>
@@ -923,7 +923,7 @@ template <uint16_t Version, class AddrTy<br>
   EXPECT_TRUE((bool)OptU64);<br>
   EXPECT_EQ(OptU64.getValue(), ActualHighPC);<br>
<br>
-  EXPECT_TRUE(SubprogramDieLowHighPC.getLowAndHighPC(LowPC, HighPC));<br>
+  EXPECT_TRUE(SubprogramDieLowHighPC.getLowAndHighPC(LowPC, HighPC, SectionIndex));<br>
   EXPECT_EQ(LowPC, ActualLowPC);<br>
   EXPECT_EQ(HighPC, ActualHighPC);<br>
 }<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>