[ELF] Make OutputDesc unique_ptr

Store them in LinkerScript::descPool. This removes a SpecificAlloc
instantiation, makes lld smaller, and drops the small memory waste due
to the separate BumpPtrAllocator.
This commit is contained in:
Fangrui Song 2024-11-23 17:14:43 -08:00
parent 042a1cc553
commit e4e5206050
2 changed files with 12 additions and 5 deletions

View File

@ -145,7 +145,9 @@ OutputDesc *LinkerScript::createOutputSection(StringRef name,
// There was a forward reference.
sec = secRef;
} else {
sec = make<OutputDesc>(ctx, name, SHT_PROGBITS, 0);
descPool.emplace_back(
std::make_unique<OutputDesc>(ctx, name, SHT_PROGBITS, 0));
sec = descPool.back().get();
if (!secRef)
secRef = sec;
}
@ -154,10 +156,14 @@ OutputDesc *LinkerScript::createOutputSection(StringRef name,
}
OutputDesc *LinkerScript::getOrCreateOutputSection(StringRef name) {
OutputDesc *&cmdRef = nameToOutputSection[CachedHashStringRef(name)];
if (!cmdRef)
cmdRef = make<OutputDesc>(ctx, name, SHT_PROGBITS, 0);
return cmdRef;
auto &secRef = nameToOutputSection[CachedHashStringRef(name)];
if (!secRef) {
secRef = descPool
.emplace_back(
std::make_unique<OutputDesc>(ctx, name, SHT_PROGBITS, 0))
.get();
}
return secRef;
}
// Expands the memory region by the specified size.

View File

@ -299,6 +299,7 @@ class LinkerScript final {
};
Ctx &ctx;
SmallVector<std::unique_ptr<OutputDesc>, 0> descPool;
llvm::DenseMap<llvm::CachedHashStringRef, OutputDesc *> nameToOutputSection;
StringRef getOutputSectionName(const InputSectionBase *s) const;