Skip to content

Commit e4e5206

Browse files
committed
[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.
1 parent 042a1cc commit e4e5206

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lld/ELF/LinkerScript.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ OutputDesc *LinkerScript::createOutputSection(StringRef name,
145145
// There was a forward reference.
146146
sec = secRef;
147147
} else {
148-
sec = make<OutputDesc>(ctx, name, SHT_PROGBITS, 0);
148+
descPool.emplace_back(
149+
std::make_unique<OutputDesc>(ctx, name, SHT_PROGBITS, 0));
150+
sec = descPool.back().get();
149151
if (!secRef)
150152
secRef = sec;
151153
}
@@ -154,10 +156,14 @@ OutputDesc *LinkerScript::createOutputSection(StringRef name,
154156
}
155157

156158
OutputDesc *LinkerScript::getOrCreateOutputSection(StringRef name) {
157-
OutputDesc *&cmdRef = nameToOutputSection[CachedHashStringRef(name)];
158-
if (!cmdRef)
159-
cmdRef = make<OutputDesc>(ctx, name, SHT_PROGBITS, 0);
160-
return cmdRef;
159+
auto &secRef = nameToOutputSection[CachedHashStringRef(name)];
160+
if (!secRef) {
161+
secRef = descPool
162+
.emplace_back(
163+
std::make_unique<OutputDesc>(ctx, name, SHT_PROGBITS, 0))
164+
.get();
165+
}
166+
return secRef;
161167
}
162168

163169
// Expands the memory region by the specified size.

lld/ELF/LinkerScript.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ class LinkerScript final {
299299
};
300300

301301
Ctx &ctx;
302+
SmallVector<std::unique_ptr<OutputDesc>, 0> descPool;
302303
llvm::DenseMap<llvm::CachedHashStringRef, OutputDesc *> nameToOutputSection;
303304

304305
StringRef getOutputSectionName(const InputSectionBase *s) const;

0 commit comments

Comments
 (0)