[lld] 53dc4e7 - [ELF] createSyntheticSections: replace some make<> with unique_ptr
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 17 00:09:11 PST 2024
Author: Fangrui Song
Date: 2024-11-17T00:09:06-08:00
New Revision: 53dc4e7600f95ae232bc49b9051f77199e79ec13
URL: https://github.com/llvm/llvm-project/commit/53dc4e7600f95ae232bc49b9051f77199e79ec13
DIFF: https://github.com/llvm/llvm-project/commit/53dc4e7600f95ae232bc49b9051f77199e79ec13.diff
LOG: [ELF] createSyntheticSections: replace some make<> with unique_ptr
This removes some SpecificAlloc instantiations and makes lld smaller.
This drops the small memory waste due to the separate BumpPtrAllocator.
Added:
Modified:
lld/ELF/Config.h
lld/ELF/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index ef81867b0e7181..1e83104db773c7 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -524,6 +524,8 @@ struct InStruct {
std::unique_ptr<SyntheticSection> riscvAttributes;
std::unique_ptr<BssSection> bss;
std::unique_ptr<BssSection> bssRelRo;
+ std::unique_ptr<SyntheticSection> gnuProperty;
+ std::unique_ptr<SyntheticSection> gnuStack;
std::unique_ptr<GotSection> got;
std::unique_ptr<GotPltSection> gotPlt;
std::unique_ptr<IgotPltSection> igotPlt;
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 3b971119e8aa3c..00149aa270f19a 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -4907,8 +4907,10 @@ template <class ELFT> void elf::createSyntheticSections(Ctx &ctx) {
ctx.in.iplt = std::make_unique<IpltSection>(ctx);
add(*ctx.in.iplt);
- if (ctx.arg.andFeatures || !ctx.aarch64PauthAbiCoreInfo.empty())
- add(*make<GnuPropertySection>(ctx));
+ if (ctx.arg.andFeatures || !ctx.aarch64PauthAbiCoreInfo.empty()) {
+ ctx.in.gnuProperty = std::make_unique<GnuPropertySection>(ctx);
+ add(*ctx.in.gnuProperty);
+ }
if (ctx.arg.debugNames) {
ctx.in.debugNames = std::make_unique<DebugNamesSection<ELFT>>(ctx);
@@ -4925,8 +4927,10 @@ template <class ELFT> void elf::createSyntheticSections(Ctx &ctx) {
// section to control the executable-ness of the stack area, but that
// is irrelevant these days. Stack area should always be non-executable
// by default. So we emit this section unconditionally.
- if (ctx.arg.relocatable)
- add(*make<GnuStackSection>(ctx));
+ if (ctx.arg.relocatable) {
+ ctx.in.gnuStack = std::make_unique<GnuStackSection>(ctx);
+ add(*ctx.in.gnuStack);
+ }
if (ctx.in.symTab)
add(*ctx.in.symTab);
More information about the llvm-commits
mailing list