[lld] cb203f3 - [ELF] Change InStruct/Partition pointers to unique_ptr
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 27 18:15:30 PST 2021
Author: Fangrui Song
Date: 2021-12-27T18:15:23-08:00
New Revision: cb203f3f92e13000712c2ee8d8b0576102804fb1
URL: https://github.com/llvm/llvm-project/commit/cb203f3f92e13000712c2ee8d8b0576102804fb1
DIFF: https://github.com/llvm/llvm-project/commit/cb203f3f92e13000712c2ee8d8b0576102804fb1.diff
LOG: [ELF] Change InStruct/Partition pointers to unique_ptr
and remove associated make<XXX> calls.
gnuHash and sysvHash are unchanged, otherwise LinkerScript::discard would
destroy the objects which may be referenced by input section descriptions.
My x86-64 lld executable is 121+KiB smaller.
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/LinkerScript.cpp
lld/ELF/Relocations.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 66bf7d0f3848..dab6a537a2ee 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -97,9 +97,10 @@ bool elf::link(ArrayRef<const char *> args, bool canExitEarly,
whyExtract.clear();
tar = nullptr;
- memset(&in, 0, sizeof(in));
+ in.reset();
- partitions = {Partition()};
+ partitions.clear();
+ partitions.emplace_back();
SharedFile::vernauxNum = 0;
};
@@ -116,7 +117,8 @@ bool elf::link(ArrayRef<const char *> args, bool canExitEarly,
script = std::make_unique<LinkerScript>();
symtab = std::make_unique<SymbolTable>();
- partitions = {Partition()};
+ partitions.clear();
+ partitions.emplace_back();
config->progName = args[0];
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index e321b0d82920..f1e29547de12 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -879,8 +879,8 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
// to work. In a full implementation we would merge all attribute
// sections.
if (in.attributes == nullptr) {
- in.attributes = make<InputSection>(*this, sec, name);
- return in.attributes;
+ in.attributes = std::make_unique<InputSection>(*this, sec, name);
+ return in.attributes.get();
}
return &InputSection::discarded;
}
@@ -901,8 +901,8 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
// standard extensions to enable. In a full implementation we would merge
// all attribute sections.
if (in.attributes == nullptr) {
- in.attributes = make<InputSection>(*this, sec, name);
- return in.attributes;
+ in.attributes = std::make_unique<InputSection>(*this, sec, name);
+ return in.attributes.get();
}
return &InputSection::discarded;
}
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index db20dd36241c..22c3a5c0c91e 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -561,7 +561,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd,
}
void LinkerScript::discard(InputSectionBase &s) {
- if (&s == in.shStrTab || &s == mainPart->relrDyn)
+ if (&s == in.shStrTab.get() || &s == mainPart->relrDyn.get())
error("discarding " + s.name + " section is not allowed");
// You can discard .hash and .gnu.hash sections by linker scripts. Since
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index d7eef68800c5..bd5043274f9f 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -870,7 +870,7 @@ static void addGotEntry(Symbol &sym) {
// If preemptible, emit a GLOB_DAT relocation.
if (sym.isPreemptible) {
- mainPart->relaDyn->addReloc({target->gotRel, in.got, off,
+ mainPart->relaDyn->addReloc({target->gotRel, in.got.get(), off,
DynamicReloc::AgainstSymbol, sym, 0, R_ABS});
return;
}
@@ -1551,7 +1551,7 @@ static bool handleNonPreemptibleIfunc(Symbol &sym) {
if (sym.hasDirectReloc) {
// Change the value to the IPLT and redirect all references to it.
auto &d = cast<Defined>(sym);
- d.section = in.iplt;
+ d.section = in.iplt.get();
d.value = sym.pltIndex * target->ipltEntrySize;
d.size = 0;
// It's important to set the symbol type here so that dynamic loaders
@@ -1641,8 +1641,8 @@ void elf::postScanRelocations() {
in.got->relocations.push_back(
{R_ADDEND, target->symbolicRel, in.got->getTlsIndexOff(), 1, &sym});
else
- mainPart->relaDyn->addReloc(
- {target->tlsModuleIndexRel, in.got, in.got->getTlsIndexOff()});
+ mainPart->relaDyn->addReloc({target->tlsModuleIndexRel, in.got.get(),
+ in.got->getTlsIndexOff()});
}
if (sym.needsGotDtprel) {
in.got->addEntry(sym);
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 797f38188e99..f93c09b95d75 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1627,7 +1627,7 @@ void RelocationBaseSection::addReloc(const DynamicReloc &reloc) {
}
void RelocationBaseSection::finalizeContents() {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab;
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
// When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
// relocations due to IFUNC (e.g. strcpy). sh_link will be set to 0 in that
@@ -1637,11 +1637,11 @@ void RelocationBaseSection::finalizeContents() {
else
getParent()->link = 0;
- if (in.relaPlt == this && in.gotPlt->getParent()) {
+ if (in.relaPlt.get() == this && in.gotPlt->getParent()) {
getParent()->flags |= ELF::SHF_INFO_LINK;
getParent()->info = in.gotPlt->getParent()->sectionIndex;
}
- if (in.relaIplt == this && in.igotPlt->getParent()) {
+ if (in.relaIplt.get() == this && in.igotPlt->getParent()) {
getParent()->flags |= ELF::SHF_INFO_LINK;
getParent()->info = in.igotPlt->getParent()->sectionIndex;
}
@@ -1678,7 +1678,7 @@ RelocationSection<ELFT>::RelocationSection(StringRef name, bool sort)
}
template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *buf) {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab;
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
parallelForEach(relocs,
[symTab](DynamicReloc &rel) { rel.computeRaw(symTab); });
@@ -1773,8 +1773,8 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize() {
for (const DynamicReloc &rel : relocs) {
Elf_Rela r;
r.r_offset = rel.getOffset();
- r.setSymbolAndType(rel.getSymIndex(getPartition().dynSymTab), rel.type,
- false);
+ r.setSymbolAndType(rel.getSymIndex(getPartition().dynSymTab.get()),
+ rel.type, false);
if (config->isRela)
r.r_addend = rel.computeAddend();
@@ -2100,7 +2100,7 @@ void SymbolTableBaseSection::finalizeContents() {
// Only the main partition's dynsym indexes are stored in the symbols
// themselves. All other partitions use a lookup table.
- if (this == mainPart->dynSymTab) {
+ if (this == mainPart->dynSymTab.get()) {
size_t i = 0;
for (const SymbolTableEntry &s : symbols)
s.sym->dynsymIndex = ++i;
@@ -2146,7 +2146,7 @@ void SymbolTableBaseSection::addSymbol(Symbol *b) {
}
size_t SymbolTableBaseSection::getSymbolIndex(Symbol *sym) {
- if (this == mainPart->dynSymTab)
+ if (this == mainPart->dynSymTab.get())
return sym->dynsymIndex;
// Initializes symbol lookup tables lazily. This is used only for -r,
@@ -2474,7 +2474,7 @@ HashTableSection::HashTableSection()
}
void HashTableSection::finalizeContents() {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab;
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
if (OutputSection *sec = symTab->getParent())
getParent()->link = sec->sectionIndex;
@@ -2488,7 +2488,7 @@ void HashTableSection::finalizeContents() {
}
void HashTableSection::writeTo(uint8_t *buf) {
- SymbolTableBaseSection *symTab = getPartition().dynSymTab;
+ SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
// See comment in GnuHashTableSection::writeTo.
memset(buf, 0, size);
@@ -3792,8 +3792,9 @@ void PartitionIndexSection::writeTo(uint8_t *buf) {
write32(buf, mainPart->dynStrTab->getVA() + partitions[i].nameStrTab - va);
write32(buf + 4, partitions[i].elfHeader->getVA() - (va + 4));
- SyntheticSection *next =
- i == partitions.size() - 1 ? in.partEnd : partitions[i + 1].elfHeader;
+ SyntheticSection *next = i == partitions.size() - 1
+ ? in.partEnd.get()
+ : partitions[i + 1].elfHeader.get();
write32(buf + 8, next->getVA() - partitions[i].elfHeader->getVA());
va += 12;
@@ -3801,6 +3802,30 @@ void PartitionIndexSection::writeTo(uint8_t *buf) {
}
}
+void InStruct::reset() {
+ attributes.reset();
+ bss.reset();
+ bssRelRo.reset();
+ got.reset();
+ gotPlt.reset();
+ igotPlt.reset();
+ ppc64LongBranchTarget.reset();
+ mipsGot.reset();
+ mipsRldMap.reset();
+ partEnd.reset();
+ partIndex.reset();
+ plt.reset();
+ iplt.reset();
+ ppc32Got2.reset();
+ ibtPlt.reset();
+ relaPlt.reset();
+ relaIplt.reset();
+ shStrTab.reset();
+ strTab.reset();
+ symTab.reset();
+ symTabShndx.reset();
+}
+
InStruct elf::in;
std::vector<Partition> elf::partitions;
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 547fa5f4056d..7f4562a92017 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -1202,24 +1202,24 @@ struct Partition {
StringRef name;
uint64_t nameStrTab;
- SyntheticSection *elfHeader;
- SyntheticSection *programHeaders;
+ std::unique_ptr<SyntheticSection> elfHeader;
+ std::unique_ptr<SyntheticSection> programHeaders;
SmallVector<PhdrEntry *, 0> phdrs;
- ARMExidxSyntheticSection *armExidx;
- BuildIdSection *buildId;
- SyntheticSection *dynamic;
- StringTableSection *dynStrTab;
- SymbolTableBaseSection *dynSymTab;
- EhFrameHeader *ehFrameHdr;
- EhFrameSection *ehFrame;
+ std::unique_ptr<ARMExidxSyntheticSection> armExidx;
+ std::unique_ptr<BuildIdSection> buildId;
+ std::unique_ptr<SyntheticSection> dynamic;
+ std::unique_ptr<StringTableSection> dynStrTab;
+ std::unique_ptr<SymbolTableBaseSection> dynSymTab;
+ std::unique_ptr<EhFrameHeader> ehFrameHdr;
+ std::unique_ptr<EhFrameSection> ehFrame;
GnuHashTableSection *gnuHashTab;
HashTableSection *hashTab;
- RelocationBaseSection *relaDyn;
- RelrBaseSection *relrDyn;
- VersionDefinitionSection *verDef;
- SyntheticSection *verNeed;
- VersionTableSection *verSym;
+ std::unique_ptr<RelocationBaseSection> relaDyn;
+ std::unique_ptr<RelrBaseSection> relrDyn;
+ std::unique_ptr<VersionDefinitionSection> verDef;
+ std::unique_ptr<SyntheticSection> verNeed;
+ std::unique_ptr<VersionTableSection> verSym;
unsigned getNumber() const { return this - &partitions[0] + 1; }
};
@@ -1234,27 +1234,29 @@ inline Partition &SectionBase::getPartition() const {
// Linker generated sections which can be used as inputs and are not specific to
// a partition.
struct InStruct {
- InputSection *attributes;
- BssSection *bss;
- BssSection *bssRelRo;
- GotSection *got;
- GotPltSection *gotPlt;
- IgotPltSection *igotPlt;
- PPC64LongBranchTargetSection *ppc64LongBranchTarget;
- MipsGotSection *mipsGot;
- MipsRldMapSection *mipsRldMap;
- SyntheticSection *partEnd;
- SyntheticSection *partIndex;
- PltSection *plt;
- IpltSection *iplt;
- PPC32Got2Section *ppc32Got2;
- IBTPltSection *ibtPlt;
- RelocationBaseSection *relaPlt;
- RelocationBaseSection *relaIplt;
- StringTableSection *shStrTab;
- StringTableSection *strTab;
- SymbolTableBaseSection *symTab;
- SymtabShndxSection *symTabShndx;
+ std::unique_ptr<InputSection> attributes;
+ std::unique_ptr<BssSection> bss;
+ std::unique_ptr<BssSection> bssRelRo;
+ std::unique_ptr<GotSection> got;
+ std::unique_ptr<GotPltSection> gotPlt;
+ std::unique_ptr<IgotPltSection> igotPlt;
+ std::unique_ptr<PPC64LongBranchTargetSection> ppc64LongBranchTarget;
+ std::unique_ptr<MipsGotSection> mipsGot;
+ std::unique_ptr<MipsRldMapSection> mipsRldMap;
+ std::unique_ptr<SyntheticSection> partEnd;
+ std::unique_ptr<SyntheticSection> partIndex;
+ std::unique_ptr<PltSection> plt;
+ std::unique_ptr<IpltSection> iplt;
+ std::unique_ptr<PPC32Got2Section> ppc32Got2;
+ std::unique_ptr<IBTPltSection> ibtPlt;
+ std::unique_ptr<RelocationBaseSection> relaPlt;
+ std::unique_ptr<RelocationBaseSection> relaIplt;
+ std::unique_ptr<StringTableSection> shStrTab;
+ std::unique_ptr<StringTableSection> strTab;
+ std::unique_ptr<SymbolTableBaseSection> symTab;
+ std::unique_ptr<SymtabShndxSection> symTabShndx;
+
+ void reset();
};
extern InStruct in;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 4b33563e8a79..f62f6bf68ed7 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -299,18 +299,18 @@ template <class ELFT> void elf::createSyntheticSections() {
auto add = [](SyntheticSection &sec) { inputSections.push_back(&sec); };
- in.shStrTab = make<StringTableSection>(".shstrtab", false);
+ in.shStrTab = std::make_unique<StringTableSection>(".shstrtab", false);
Out::programHeaders = make<OutputSection>("", 0, SHF_ALLOC);
Out::programHeaders->alignment = config->wordsize;
if (config->strip != StripPolicy::All) {
- in.strTab = make<StringTableSection>(".strtab", false);
- in.symTab = make<SymbolTableSection<ELFT>>(*in.strTab);
- in.symTabShndx = make<SymtabShndxSection>();
+ in.strTab = std::make_unique<StringTableSection>(".strtab", false);
+ in.symTab = std::make_unique<SymbolTableSection<ELFT>>(*in.strTab);
+ in.symTabShndx = std::make_unique<SymtabShndxSection>();
}
- in.bss = make<BssSection>(".bss", 0, 1);
+ in.bss = std::make_unique<BssSection>(".bss", 0, 1);
add(*in.bss);
// If there is a SECTIONS command and a .data.rel.ro section name use name
@@ -318,14 +318,14 @@ template <class ELFT> void elf::createSyntheticSections() {
// This makes sure our relro is contiguous.
bool hasDataRelRo =
script->hasSectionsCommand && findSection(".data.rel.ro", 0);
- in.bssRelRo =
- make<BssSection>(hasDataRelRo ? ".data.rel.ro.bss" : ".bss.rel.ro", 0, 1);
+ in.bssRelRo = std::make_unique<BssSection>(
+ hasDataRelRo ? ".data.rel.ro.bss" : ".bss.rel.ro", 0, 1);
add(*in.bssRelRo);
// Add MIPS-specific sections.
if (config->emachine == EM_MIPS) {
if (!config->shared && config->hasDynSymTab) {
- in.mipsRldMap = make<MipsRldMapSection>();
+ in.mipsRldMap = std::make_unique<MipsRldMapSection>();
add(*in.mipsRldMap);
}
if (auto *sec = MipsAbiFlagsSection<ELFT>::create())
@@ -345,40 +345,43 @@ template <class ELFT> void elf::createSyntheticSections() {
};
if (!part.name.empty()) {
- part.elfHeader = make<PartitionElfHeaderSection<ELFT>>();
+ part.elfHeader = std::make_unique<PartitionElfHeaderSection<ELFT>>();
part.elfHeader->name = part.name;
add(*part.elfHeader);
- part.programHeaders = make<PartitionProgramHeadersSection<ELFT>>();
+ part.programHeaders =
+ std::make_unique<PartitionProgramHeadersSection<ELFT>>();
add(*part.programHeaders);
}
if (config->buildId != BuildIdKind::None) {
- part.buildId = make<BuildIdSection>();
+ part.buildId = std::make_unique<BuildIdSection>();
add(*part.buildId);
}
- part.dynStrTab = make<StringTableSection>(".dynstr", true);
- part.dynSymTab = make<SymbolTableSection<ELFT>>(*part.dynStrTab);
- part.dynamic = make<DynamicSection<ELFT>>();
+ part.dynStrTab = std::make_unique<StringTableSection>(".dynstr", true);
+ part.dynSymTab =
+ std::make_unique<SymbolTableSection<ELFT>>(*part.dynStrTab);
+ part.dynamic = std::make_unique<DynamicSection<ELFT>>();
if (config->androidPackDynRelocs)
- part.relaDyn = make<AndroidPackedRelocationSection<ELFT>>(relaDynName);
- else
part.relaDyn =
- make<RelocationSection<ELFT>>(relaDynName, config->zCombreloc);
+ std::make_unique<AndroidPackedRelocationSection<ELFT>>(relaDynName);
+ else
+ part.relaDyn = std::make_unique<RelocationSection<ELFT>>(
+ relaDynName, config->zCombreloc);
if (config->hasDynSymTab) {
add(*part.dynSymTab);
- part.verSym = make<VersionTableSection>();
+ part.verSym = std::make_unique<VersionTableSection>();
add(*part.verSym);
if (!namedVersionDefs().empty()) {
- part.verDef = make<VersionDefinitionSection>();
+ part.verDef = std::make_unique<VersionDefinitionSection>();
add(*part.verDef);
}
- part.verNeed = make<VersionNeedSection<ELFT>>();
+ part.verNeed = std::make_unique<VersionNeedSection<ELFT>>();
add(*part.verNeed);
if (config->gnuHash) {
@@ -397,23 +400,23 @@ template <class ELFT> void elf::createSyntheticSections() {
}
if (config->relrPackDynRelocs) {
- part.relrDyn = make<RelrSection<ELFT>>();
+ part.relrDyn = std::make_unique<RelrSection<ELFT>>();
add(*part.relrDyn);
}
if (!config->relocatable) {
if (config->ehFrameHdr) {
- part.ehFrameHdr = make<EhFrameHeader>();
+ part.ehFrameHdr = std::make_unique<EhFrameHeader>();
add(*part.ehFrameHdr);
}
- part.ehFrame = make<EhFrameSection>();
+ part.ehFrame = std::make_unique<EhFrameSection>();
add(*part.ehFrame);
}
if (config->emachine == EM_ARM && !config->relocatable) {
// The ARMExidxsyntheticsection replaces all the individual .ARM.exidx
// InputSections.
- part.armExidx = make<ARMExidxSyntheticSection>();
+ part.armExidx = std::make_unique<ARMExidxSyntheticSection>();
add(*part.armExidx);
}
}
@@ -422,13 +425,14 @@ template <class ELFT> void elf::createSyntheticSections() {
// Create the partition end marker. This needs to be in partition number 255
// so that it is sorted after all other partitions. It also has other
// special handling (see createPhdrs() and combineEhSections()).
- in.partEnd = make<BssSection>(".part.end", config->maxPageSize, 1);
+ in.partEnd =
+ std::make_unique<BssSection>(".part.end", config->maxPageSize, 1);
in.partEnd->partition = 255;
add(*in.partEnd);
- in.partIndex = make<PartitionIndexSection>();
- addOptionalRegular("__part_index_begin", in.partIndex, 0);
- addOptionalRegular("__part_index_end", in.partIndex,
+ in.partIndex = std::make_unique<PartitionIndexSection>();
+ addOptionalRegular("__part_index_begin", in.partIndex.get(), 0);
+ addOptionalRegular("__part_index_end", in.partIndex.get(),
in.partIndex->getSize());
add(*in.partIndex);
}
@@ -436,26 +440,26 @@ template <class ELFT> void elf::createSyntheticSections() {
// Add .got. MIPS' .got is so
diff erent from the other archs,
// it has its own class.
if (config->emachine == EM_MIPS) {
- in.mipsGot = make<MipsGotSection>();
+ in.mipsGot = std::make_unique<MipsGotSection>();
add(*in.mipsGot);
} else {
- in.got = make<GotSection>();
+ in.got = std::make_unique<GotSection>();
add(*in.got);
}
if (config->emachine == EM_PPC) {
- in.ppc32Got2 = make<PPC32Got2Section>();
+ in.ppc32Got2 = std::make_unique<PPC32Got2Section>();
add(*in.ppc32Got2);
}
if (config->emachine == EM_PPC64) {
- in.ppc64LongBranchTarget = make<PPC64LongBranchTargetSection>();
+ in.ppc64LongBranchTarget = std::make_unique<PPC64LongBranchTargetSection>();
add(*in.ppc64LongBranchTarget);
}
- in.gotPlt = make<GotPltSection>();
+ in.gotPlt = std::make_unique<GotPltSection>();
add(*in.gotPlt);
- in.igotPlt = make<IgotPltSection>();
+ in.igotPlt = std::make_unique<IgotPltSection>();
add(*in.igotPlt);
// _GLOBAL_OFFSET_TABLE_ is defined relative to either .got.plt or .got. Treat
@@ -472,7 +476,7 @@ template <class ELFT> void elf::createSyntheticSections() {
// 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 = make<RelocationSection<ELFT>>(
+ in.relaPlt = std::make_unique<RelocationSection<ELFT>>(
config->isRela ? ".rela.plt" : ".rel.plt", /*sort=*/false);
add(*in.relaPlt);
@@ -482,21 +486,23 @@ template <class ELFT> void elf::createSyntheticSections() {
// that would cause a section type mismatch. However, because the Android
// dynamic loader reads .rel.plt after .rel.dyn, we can get the desired
// behaviour by placing the iplt section in .rel.plt.
- in.relaIplt = make<RelocationSection<ELFT>>(
+ in.relaIplt = std::make_unique<RelocationSection<ELFT>>(
config->androidPackDynRelocs ? in.relaPlt->name : relaDynName,
/*sort=*/false);
add(*in.relaIplt);
if ((config->emachine == EM_386 || config->emachine == EM_X86_64) &&
(config->andFeatures & GNU_PROPERTY_X86_FEATURE_1_IBT)) {
- in.ibtPlt = make<IBTPltSection>();
+ in.ibtPlt = std::make_unique<IBTPltSection>();
add(*in.ibtPlt);
}
- in.plt = config->emachine == EM_PPC ? make<PPC32GlinkSection>()
- : make<PltSection>();
+ if (config->emachine == EM_PPC)
+ in.plt = std::make_unique<PPC32GlinkSection>();
+ else
+ in.plt = std::make_unique<PltSection>();
add(*in.plt);
- in.iplt = make<IpltSection>();
+ in.iplt = std::make_unique<IpltSection>();
add(*in.iplt);
if (config->andFeatures)
@@ -1056,17 +1062,17 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
if (ElfSym::globalOffsetTable) {
// The _GLOBAL_OFFSET_TABLE_ symbol is defined by target convention usually
// to the start of the .got or .got.plt section.
- InputSection *gotSection = in.gotPlt;
+ InputSection *sec = in.gotPlt.get();
if (!target->gotBaseSymInGotPlt)
- gotSection = in.mipsGot ? cast<InputSection>(in.mipsGot)
- : cast<InputSection>(in.got);
- ElfSym::globalOffsetTable->section = gotSection;
+ sec = in.mipsGot.get() ? cast<InputSection>(in.mipsGot.get())
+ : cast<InputSection>(in.got.get());
+ ElfSym::globalOffsetTable->section = sec;
}
// .rela_iplt_{start,end} mark the start and the end of in.relaIplt.
if (ElfSym::relaIpltStart && in.relaIplt->isNeeded()) {
- ElfSym::relaIpltStart->section = in.relaIplt;
- ElfSym::relaIpltEnd->section = in.relaIplt;
+ ElfSym::relaIpltStart->section = in.relaIplt.get();
+ ElfSym::relaIpltEnd->section = in.relaIplt.get();
ElfSym::relaIpltEnd->value = in.relaIplt->getSize();
}
@@ -1643,7 +1649,7 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
// can assign Virtual Addresses to OutputSections that are not monotonically
// increasing.
for (Partition &part : partitions)
- finalizeSynthetic(part.armExidx);
+ finalizeSynthetic(part.armExidx.get());
resolveShfLinkOrder();
// Converts call x at GDPLT to call __tls_get_addr
@@ -1864,9 +1870,9 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Even the author of gold doesn't remember why gold behaves that way.
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
if (mainPart->dynamic->parent)
- symtab->addSymbol(Defined{/*file=*/nullptr, "_DYNAMIC", STB_WEAK,
- STV_HIDDEN, STT_NOTYPE,
- /*value=*/0, /*size=*/0, mainPart->dynamic});
+ symtab->addSymbol(
+ Defined{/*file=*/nullptr, "_DYNAMIC", STB_WEAK, STV_HIDDEN, STT_NOTYPE,
+ /*value=*/0, /*size=*/0, mainPart->dynamic.get()});
// Define __rel[a]_iplt_{start,end} symbols if needed.
addRelIpltSymbols();
@@ -1909,7 +1915,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// pieces. The relocation scan uses those pieces, so this has to be
// earlier.
for (Partition &part : partitions)
- finalizeSynthetic(part.ehFrame);
+ finalizeSynthetic(part.ehFrame.get());
}
for (Symbol *sym : symtab->symbols())
@@ -2075,35 +2081,35 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
{
llvm::TimeTraceScope timeScope("Finalize synthetic sections");
- finalizeSynthetic(in.bss);
- finalizeSynthetic(in.bssRelRo);
- finalizeSynthetic(in.symTabShndx);
- finalizeSynthetic(in.shStrTab);
- finalizeSynthetic(in.strTab);
- finalizeSynthetic(in.got);
- finalizeSynthetic(in.mipsGot);
- finalizeSynthetic(in.igotPlt);
- finalizeSynthetic(in.gotPlt);
- finalizeSynthetic(in.relaIplt);
- finalizeSynthetic(in.relaPlt);
- finalizeSynthetic(in.plt);
- finalizeSynthetic(in.iplt);
- finalizeSynthetic(in.ppc32Got2);
- finalizeSynthetic(in.partIndex);
+ finalizeSynthetic(in.bss.get());
+ finalizeSynthetic(in.bssRelRo.get());
+ finalizeSynthetic(in.symTabShndx.get());
+ finalizeSynthetic(in.shStrTab.get());
+ finalizeSynthetic(in.strTab.get());
+ finalizeSynthetic(in.got.get());
+ finalizeSynthetic(in.mipsGot.get());
+ finalizeSynthetic(in.igotPlt.get());
+ finalizeSynthetic(in.gotPlt.get());
+ finalizeSynthetic(in.relaIplt.get());
+ finalizeSynthetic(in.relaPlt.get());
+ finalizeSynthetic(in.plt.get());
+ finalizeSynthetic(in.iplt.get());
+ finalizeSynthetic(in.ppc32Got2.get());
+ finalizeSynthetic(in.partIndex.get());
// Dynamic section must be the last one in this list and dynamic
// symbol table section (dynSymTab) must be the first one.
for (Partition &part : partitions) {
- finalizeSynthetic(part.dynSymTab);
+ finalizeSynthetic(part.dynSymTab.get());
finalizeSynthetic(part.gnuHashTab);
finalizeSynthetic(part.hashTab);
- finalizeSynthetic(part.verDef);
- finalizeSynthetic(part.relaDyn);
- finalizeSynthetic(part.relrDyn);
- finalizeSynthetic(part.ehFrameHdr);
- finalizeSynthetic(part.verSym);
- finalizeSynthetic(part.verNeed);
- finalizeSynthetic(part.dynamic);
+ finalizeSynthetic(part.verDef.get());
+ finalizeSynthetic(part.relaDyn.get());
+ finalizeSynthetic(part.relrDyn.get());
+ finalizeSynthetic(part.ehFrameHdr.get());
+ finalizeSynthetic(part.verSym.get());
+ finalizeSynthetic(part.verNeed.get());
+ finalizeSynthetic(part.dynamic.get());
}
}
@@ -2139,8 +2145,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
llvm::TimeTraceScope timeScope("Finalize synthetic sections");
// finalizeAddressDependentContent may have added local symbols to the
// static symbol table.
- finalizeSynthetic(in.symTab);
- finalizeSynthetic(in.ppc64LongBranchTarget);
+ finalizeSynthetic(in.symTab.get());
+ finalizeSynthetic(in.ppc64LongBranchTarget.get());
}
// Relaxation to delete inter-basic block jumps created by basic block
More information about the llvm-commits
mailing list