Skip to content

Commit 29a1567

Browse files
authored
[DWARFLinker] Release input DWARF after object has been linked (llvm#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
1 parent 2a1f1b5 commit 29a1567

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

llvm/include/llvm/DWARFLinker/DWARFLinker.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ class DWARFFile {
269269
public:
270270
using UnloadCallbackTy = std::function<void(StringRef FileName)>;
271271
DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
272-
std::unique_ptr<AddressesMap> Addresses, UnloadCallbackTy = nullptr)
272+
std::unique_ptr<AddressesMap> Addresses,
273+
UnloadCallbackTy UnloadFunc = nullptr)
273274
: FileName(Name), Dwarf(std::move(Dwarf)),
274-
Addresses(std::move(Addresses)) {}
275+
Addresses(std::move(Addresses)), UnloadFunc(UnloadFunc) {}
275276

276277
/// The object file name.
277278
StringRef FileName;
@@ -281,6 +282,18 @@ class DWARFFile {
281282

282283
/// Helpful address information(list of valid address ranges, relocations).
283284
std::unique_ptr<AddressesMap> Addresses;
285+
286+
/// Callback to the module keeping object file to unload.
287+
UnloadCallbackTy UnloadFunc;
288+
289+
/// Unloads object file and corresponding AddressesMap and Dwarf Context.
290+
void unload() {
291+
Addresses.reset();
292+
Dwarf.reset();
293+
294+
if (UnloadFunc)
295+
UnloadFunc(FileName);
296+
}
284297
};
285298

286299
typedef std::map<std::string, std::string> swiftInterfacesMap;
@@ -529,7 +542,8 @@ class DWARFLinker {
529542
/// the debug object.
530543
void clear() {
531544
CompileUnits.clear();
532-
File.Addresses->clear();
545+
ModuleUnits.clear();
546+
File.unload();
533547
}
534548
};
535549

0 commit comments

Comments
 (0)