<div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div class="gmail_quote">On Mon, 9 Nov 2020 at 15:37, Alexey Lapshin <<a href="mailto:avl.lapshin@gmail.com">avl.lapshin@gmail.com</a>> wrote: </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><p>I mean the run-time memory usage of DebugInfoDWARF library.<br>
      Currently, when Object file is loaded and DWARFContext class is
      created<br>
      the DWARFContext references section data from object::ObjectFile:<br>
      <br>
      DWARFContext(std::unique_ptr<const DWARFObject> DObj,..)<br>
      <br>
      DWARFObjInMemory(const object::ObjectFile &Obj, ...)<br>
      <br>
      class DWARFObjInMemory {<br>
        const DWARFSection &getLocSection() const;<br>
        const DWARFSection &getLoclistsSection() const;<br>
        StringRef getArangesSection() const;<br>
        const DWARFSection &getFrameSection() const;<br>
        const DWARFSection &getEHFrameSection() const;<br>
        const DWARFSection &getLineSection() const;<br>
        StringRef getLineStrSection() const;<br>
      }<br>
      <br>
      class DWARFUnit {<br>
        DWARFContext &Context;<br>
        /// Section containing this DWARFUnit.<br>
        const DWARFSection &InfoSection;<br>
      }<br>
      <br>
      struct DWARFSection {<br>
        StringRef Data;<br>
      };<br>
      <br>
      DWARFSection references data that are loaded by Object file.<br>
      DWARFSection is assumed to be a monolithic piece of data. <br>
      There is a code using these data assuming random access:<br>
      <br>
      StringRef LineData =
      OrigDwarf.getDWARFObj().getLineSection().Data;<br>
      LineData.slice(*StmtList + 4, PrologueEnd)<br>
      ...<br>
      StringRef FrameData =
      OrigDwarf.getDWARFObj().getFrameSection().Data;<br>
      FrameData.substr(EntryOffset, InitialLength + 4)<br>
      ...<br>
      InputSec = Dwarf.getDWARFObj().getLocSection();<br>
      InputSec.Data.substr(Offset, Length);<br>
      ...<br>
      DWARFDataExtractor RangesData(Context.getDWARFObj(),
      *RangeSection,<br>
                                    isLittleEndian,
      getAddressByteSize());<br>
      uint64_t ActualRangeListOffset = RangeSectionBase +
      RangeListOffset;<br>
      RangeList.extract(RangesData, &ActualRangeListOffset);<br>
      <br>
      <br>
      i.e. It is possible to access random piece of DWARFSection.<br>
      <br>
      If object::ObjectFile would contain fragmented sections then <br>
      we need a solution of how that could work. <br>
      <br>
      One possibility is to create a glued copy of fragmented data and
      pass it to the DWARFObj.<br>
      But that would require to load all original debug info sections
      twice<br>
      (fragmented sections inside Objectfile and glued sections inside
      DWARFObj).<br>
      <br>
      Another possibility is to rewrite DebugInfoDWARF/DWARFSection to
      avoid random access to the data(if that is possible).</p></div></blockquote><div>The only consumers who would have to do something I haven't measured would be tools like llvm-dwarfdump. I think this is easily solved by modifying DWARFObjInMemory to store a list of sections containing data per section (rather than a single section), and then providing a DWARFDataExtractor constructor overload that takes such a list. The DWARFDataExtractor could then do the jumping transparently. I wouldn't anticipate the memory usage being a real problem - the biggest cost would be the overhead of N DWARFSection instances (i.e. approximately N pointers + N sizes), where N is the number of these fragmented sections. This certainly could be significant, but I suspect that compared to the cost of linking the output it wouldn't be a problem.<br></div></div></div>