From 53dc4e7600f95ae232bc49b9051f77199e79ec13 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 17 Nov 2024 00:09:06 -0800 Subject: [PATCH] [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. --- lld/ELF/Config.h | 2 ++ lld/ELF/SyntheticSections.cpp | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index ef81867b0e71..1e83104db773 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -524,6 +524,8 @@ struct InStruct { std::unique_ptr riscvAttributes; std::unique_ptr bss; std::unique_ptr bssRelRo; + std::unique_ptr gnuProperty; + std::unique_ptr gnuStack; std::unique_ptr got; std::unique_ptr gotPlt; std::unique_ptr igotPlt; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 3b971119e8aa..00149aa270f1 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -4907,8 +4907,10 @@ template void elf::createSyntheticSections(Ctx &ctx) { ctx.in.iplt = std::make_unique(ctx); add(*ctx.in.iplt); - if (ctx.arg.andFeatures || !ctx.aarch64PauthAbiCoreInfo.empty()) - add(*make(ctx)); + if (ctx.arg.andFeatures || !ctx.aarch64PauthAbiCoreInfo.empty()) { + ctx.in.gnuProperty = std::make_unique(ctx); + add(*ctx.in.gnuProperty); + } if (ctx.arg.debugNames) { ctx.in.debugNames = std::make_unique>(ctx); @@ -4925,8 +4927,10 @@ template 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(ctx)); + if (ctx.arg.relocatable) { + ctx.in.gnuStack = std::make_unique(ctx); + add(*ctx.in.gnuStack); + } if (ctx.in.symTab) add(*ctx.in.symTab);