[lld] 0bb362c - [ELF] --gdb-index: fix memory usage regression after D74773

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 12 16:55:37 PDT 2020


Author: Fangrui Song
Date: 2020-03-12T16:55:30-07:00
New Revision: 0bb362c1649912d3a328dd01c700626d0a9f5a2c

URL: https://github.com/llvm/llvm-project/commit/0bb362c1649912d3a328dd01c700626d0a9f5a2c
DIFF: https://github.com/llvm/llvm-project/commit/0bb362c1649912d3a328dd01c700626d0a9f5a2c.diff

LOG: [ELF] --gdb-index: fix memory usage regression after D74773

On an internal target,

* Before D74773: time -f '%M' => 18275680
* After D74773:  time -f '%M' => 22088964

This patch restores to the status before D74773.

Added: 
    

Modified: 
    lld/ELF/SyntheticSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index c69becb1aee6..ed2cdb70a2d5 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2822,14 +2822,16 @@ template <class ELFT> GdbIndexSection *GdbIndexSection::create() {
   std::vector<std::vector<NameAttrEntry>> nameAttrs(sections.size());
 
   parallelForEachN(0, sections.size(), [&](size_t i) {
-    DWARFContext *dwarf =
-        sections[i]->getFile<ELFT>()->getDwarf()->getContext();
+    // To keep memory usage low, we don't want to keep cached DWARFContext, so
+    // avoid getDwarf() here.
+    ObjFile<ELFT> *file = sections[i]->getFile<ELFT>();
+    DWARFContext dwarf(std::make_unique<LLDDwarfObj<ELFT>>(file));
 
     chunks[i].sec = sections[i];
-    chunks[i].compilationUnits = readCuList(*dwarf);
-    chunks[i].addressAreas = readAddressAreas(*dwarf, sections[i]);
+    chunks[i].compilationUnits = readCuList(dwarf);
+    chunks[i].addressAreas = readAddressAreas(dwarf, sections[i]);
     nameAttrs[i] = readPubNamesAndTypes<ELFT>(
-        static_cast<const LLDDwarfObj<ELFT> &>(dwarf->getDWARFObj()),
+        static_cast<const LLDDwarfObj<ELFT> &>(dwarf.getDWARFObj()),
         chunks[i].compilationUnits);
   });
 


        


More information about the llvm-commits mailing list