Skip to content

Commit dbfb00c

Browse files
resolve review comments
1 parent b169ccb commit dbfb00c

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
17451745
uint8_t visibility = mapVisibility(objSym.getVisibility());
17461746

17471747
if (!sym)
1748-
sym = symtab.insert(saver().save(objSym.getName()));
1748+
sym = symtab.insert(unique_saver().save(objSym.getName()));
17491749

17501750
int c = objSym.getComdatIndex();
17511751
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
@@ -1797,9 +1797,14 @@ void BitcodeFile::parseLazy() {
17971797
symbols = std::make_unique<Symbol *[]>(numSymbols);
17981798
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
17991799
if (!irSym.isUndefined()) {
1800-
auto *sym = symtab.insert(saver().save(irSym.getName()));
1800+
auto *sym = symtab.insert(unique_saver().save(irSym.getName()));
18011801
sym->resolve(LazySymbol{*this});
18021802
symbols[i] = sym;
1803+
} else {
1804+
// Keep copies of per-module undefined symbols for LTO::GlobalResolutions
1805+
// usage.
1806+
[[maybe_unused]] StringRef SymbolRef =
1807+
unique_saver().save(irSym.getName());
18031808
}
18041809
}
18051810

lld/include/lld/Common/CommonLinkerContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CommonLinkerContext {
3838

3939
llvm::BumpPtrAllocator bAlloc;
4040
llvm::StringSaver saver{bAlloc};
41+
llvm::UniqueStringSaver unique_saver{bAlloc};
4142
llvm::DenseMap<void *, SpecificAllocBase *> instances;
4243

4344
ErrorHandler e;
@@ -55,6 +56,9 @@ template <typename T = CommonLinkerContext> T &context() {
5556
bool hasContext();
5657

5758
inline llvm::StringSaver &saver() { return context().saver; }
59+
inline llvm::UniqueStringSaver &unique_saver() {
60+
return context().unique_saver;
61+
}
5862
inline llvm::BumpPtrAllocator &bAlloc() { return context().bAlloc; }
5963
} // namespace lld
6064

llvm/include/llvm/LTO/LTO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ class LTO {
420420
std::unique_ptr<llvm::DenseMap<StringRef, GlobalResolution>>
421421
GlobalResolutions;
422422

423+
void releaseGlobalResolutionsMemory();
424+
423425
void addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
424426
ArrayRef<SymbolResolution> Res, unsigned Partition,
425427
bool InSummary);

llvm/lib/LTO/LTO.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,14 @@ void LTO::addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
695695
}
696696
}
697697

698+
void LTO::releaseGlobalResolutionsMemory() {
699+
// Release GlobalResolutions dense-map itself.
700+
GlobalResolutions.reset();
701+
// Release the string saver memory.
702+
GlobalResolutionSymbolSaver.reset();
703+
Alloc.reset();
704+
}
705+
698706
static void writeToResolutionFile(raw_ostream &OS, InputFile *Input,
699707
ArrayRef<SymbolResolution> Res) {
700708
StringRef Path = Input->getName();
@@ -1811,10 +1819,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
18111819
// are no further accesses. We specifically want to do this before computing
18121820
// cross module importing, which adds to peak memory via the computed import
18131821
// and export lists.
1814-
GlobalResolutions.reset();
1815-
// Release the string saver memory.
1816-
GlobalResolutionSymbolSaver.reset();
1817-
Alloc.reset();
1822+
releaseGlobalResolutionsMemory();
18181823

18191824
if (Conf.OptLevel > 0)
18201825
ComputeCrossModuleImport(ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,

0 commit comments

Comments
 (0)