Skip to content

Commit

Permalink
[ELF] Avoid make<GdbIndexSection>. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Apr 10, 2024
1 parent b0662a7 commit ee284d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
14 changes: 8 additions & 6 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,8 @@ createSymbols(
}

// Returns a newly-created .gdb_index section.
template <class ELFT> GdbIndexSection *GdbIndexSection::create() {
template <class ELFT>
std::unique_ptr<GdbIndexSection> GdbIndexSection::create() {
llvm::TimeTraceScope timeScope("Create gdb index");

// Collect InputFiles with .debug_info. See the comment in
Expand Down Expand Up @@ -2918,7 +2919,7 @@ template <class ELFT> GdbIndexSection *GdbIndexSection::create() {
nameAttrs[i] = readPubNamesAndTypes<ELFT>(dobj, chunks[i].compilationUnits);
});

auto *ret = make<GdbIndexSection>();
auto ret = std::make_unique<GdbIndexSection>();
ret->chunks = std::move(chunks);
std::tie(ret->symbols, ret->size) = createSymbols(nameAttrs, ret->chunks);

Expand Down Expand Up @@ -3860,6 +3861,7 @@ void InStruct::reset() {
ppc32Got2.reset();
ibtPlt.reset();
relaPlt.reset();
gdbIndex.reset();
shStrTab.reset();
strTab.reset();
symTab.reset();
Expand Down Expand Up @@ -3986,10 +3988,10 @@ InStruct elf::in;
std::vector<Partition> elf::partitions;
Partition *elf::mainPart;

template GdbIndexSection *GdbIndexSection::create<ELF32LE>();
template GdbIndexSection *GdbIndexSection::create<ELF32BE>();
template GdbIndexSection *GdbIndexSection::create<ELF64LE>();
template GdbIndexSection *GdbIndexSection::create<ELF64BE>();
template std::unique_ptr<GdbIndexSection> GdbIndexSection::create<ELF32LE>();
template std::unique_ptr<GdbIndexSection> GdbIndexSection::create<ELF32BE>();
template std::unique_ptr<GdbIndexSection> GdbIndexSection::create<ELF64LE>();
template std::unique_ptr<GdbIndexSection> GdbIndexSection::create<ELF64BE>();

template void elf::splitSections<ELF32LE>();
template void elf::splitSections<ELF32BE>();
Expand Down
4 changes: 3 additions & 1 deletion lld/ELF/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ class GdbIndexSection final : public SyntheticSection {
};

GdbIndexSection();
template <typename ELFT> static GdbIndexSection *create();
template <typename ELFT> static std::unique_ptr<GdbIndexSection> create();
void writeTo(uint8_t *buf) override;
size_t getSize() const override { return size; }
bool isNeeded() const override;
Expand Down Expand Up @@ -1359,6 +1359,8 @@ struct InStruct {
std::unique_ptr<PPC32Got2Section> ppc32Got2;
std::unique_ptr<IBTPltSection> ibtPlt;
std::unique_ptr<RelocationBaseSection> relaPlt;
// Non-SHF_ALLOC sections
std::unique_ptr<GdbIndexSection> gdbIndex;
std::unique_ptr<StringTableSection> shStrTab;
std::unique_ptr<StringTableSection> strTab;
std::unique_ptr<SymbolTableBaseSection> symTab;
Expand Down
8 changes: 5 additions & 3 deletions lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,6 @@ template <class ELFT> void elf::createSyntheticSections() {
in.got->hasGotOffRel = true;
}

if (config->gdbIndex)
add(*GdbIndexSection::create<ELFT>());

// 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<RelocationSection<ELFT>>(
Expand All @@ -568,6 +565,11 @@ template <class ELFT> void elf::createSyntheticSections() {
if (config->andFeatures || !ctx.aarch64PauthAbiCoreInfo.empty())
add(*make<GnuPropertySection>());

if (config->gdbIndex) {
in.gdbIndex = GdbIndexSection::create<ELFT>();
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
Expand Down

0 comments on commit ee284d2

Please sign in to comment.