From ab5871e47236d3b82a31ed9ac68f0425cf62be5e Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 6 Oct 2023 08:00:48 -0700 Subject: [PATCH] [DWARFLinker] Release input DWARF after object has been linked (#68376) dsymutil is using an excessive amount of memory because it's holding on to the DWARF Context, even after it's done processing the corresponding object file. This patch releases the input DWARF after cloning, at which point it is no longer needed. This has always been the intended behavior, though I didn't bisect to figure out when this regressed. When linking swift, this reduces peak (dirty) memory usage from 25 to 15 gigabytes. rdar://111525100 (cherry picked from commit 29a1567435ed56a56410fce76d0dedc89683dc81) --- llvm/include/llvm/DWARFLinker/DWARFLinker.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/DWARFLinker.h index 9543546935eef..e573419e59db4 100644 --- a/llvm/include/llvm/DWARFLinker/DWARFLinker.h +++ b/llvm/include/llvm/DWARFLinker/DWARFLinker.h @@ -276,6 +276,12 @@ class DWARFFile { /// Helpful address information(list of valid address ranges, relocations). std::unique_ptr Addresses; + + /// Unloads object file and corresponding AddressesMap and Dwarf Context. + void unload() { + Addresses.reset(); + Dwarf.reset(); + } }; typedef std::map swiftInterfacesMap; @@ -524,7 +530,8 @@ class DWARFLinker { /// the debug object. void clear() { CompileUnits.clear(); - File.Addresses->clear(); + ModuleUnits.clear(); + File.unload(); } };