[lld] e4e5206 - [ELF] Make OutputDesc unique_ptr
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 23 17:14:47 PST 2024
Author: Fangrui Song
Date: 2024-11-23T17:14:43-08:00
New Revision: e4e5206050a657170892bc400fd4b870e0576ec6
URL: https://github.com/llvm/llvm-project/commit/e4e5206050a657170892bc400fd4b870e0576ec6
DIFF: https://github.com/llvm/llvm-project/commit/e4e5206050a657170892bc400fd4b870e0576ec6.diff
LOG: [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.
Added:
Modified:
lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h
Removed:
################################################################################
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index d8aa2c46cfa5b3..8ff6e2cd3a9df1 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -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.
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index f5408b4ba3037e..328368fd3b4333 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -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;
More information about the llvm-commits
mailing list