diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 4427a12008680..550659464a440 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2872,7 +2872,8 @@ createSymbols( } // Returns a newly-created .gdb_index section. -template GdbIndexSection *GdbIndexSection::create() { +template +std::unique_ptr GdbIndexSection::create() { llvm::TimeTraceScope timeScope("Create gdb index"); // Collect InputFiles with .debug_info. See the comment in @@ -2918,7 +2919,7 @@ template GdbIndexSection *GdbIndexSection::create() { nameAttrs[i] = readPubNamesAndTypes(dobj, chunks[i].compilationUnits); }); - auto *ret = make(); + auto ret = std::make_unique(); ret->chunks = std::move(chunks); std::tie(ret->symbols, ret->size) = createSymbols(nameAttrs, ret->chunks); @@ -3860,6 +3861,7 @@ void InStruct::reset() { ppc32Got2.reset(); ibtPlt.reset(); relaPlt.reset(); + gdbIndex.reset(); shStrTab.reset(); strTab.reset(); symTab.reset(); @@ -3986,10 +3988,10 @@ InStruct elf::in; std::vector elf::partitions; Partition *elf::mainPart; -template GdbIndexSection *GdbIndexSection::create(); -template GdbIndexSection *GdbIndexSection::create(); -template GdbIndexSection *GdbIndexSection::create(); -template GdbIndexSection *GdbIndexSection::create(); +template std::unique_ptr GdbIndexSection::create(); +template std::unique_ptr GdbIndexSection::create(); +template std::unique_ptr GdbIndexSection::create(); +template std::unique_ptr GdbIndexSection::create(); template void elf::splitSections(); template void elf::splitSections(); diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 7490fb61fb6f1..68b4cdb1dde04 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -822,7 +822,7 @@ class GdbIndexSection final : public SyntheticSection { }; GdbIndexSection(); - template static GdbIndexSection *create(); + template static std::unique_ptr create(); void writeTo(uint8_t *buf) override; size_t getSize() const override { return size; } bool isNeeded() const override; @@ -1359,6 +1359,8 @@ struct InStruct { std::unique_ptr ppc32Got2; std::unique_ptr ibtPlt; std::unique_ptr relaPlt; + // Non-SHF_ALLOC sections + std::unique_ptr gdbIndex; std::unique_ptr shStrTab; std::unique_ptr strTab; std::unique_ptr symTab; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index fc9084f40044d..021b9bb0d5e22 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -541,9 +541,6 @@ template void elf::createSyntheticSections() { in.got->hasGotOffRel = true; } - if (config->gdbIndex) - add(*GdbIndexSection::create()); - // We always need to add rel[a].plt to output if it has entries. // Even for static linking it can contain R_[*]_IRELATIVE relocations. in.relaPlt = std::make_unique>( @@ -568,6 +565,11 @@ template void elf::createSyntheticSections() { if (config->andFeatures || !ctx.aarch64PauthAbiCoreInfo.empty()) add(*make()); + if (config->gdbIndex) { + in.gdbIndex = GdbIndexSection::create(); + add(*in.gdbIndex); + } + // .note.GNU-stack is always added when we are creating a re-linkable // object file. Other linkers are using the presence of this marker // section to control the executable-ness of the stack area, but that