mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-19 03:36:47 +00:00
[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:
parent
042a1cc553
commit
e4e5206050
@ -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.
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user