// 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;
}
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()});
}
c.relocations.push_back({expr, type, offset, addend, &sym});
return 1;
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
// 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;
};
extern InStruct in;
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
// 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())
// 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);
}
// Add .got. MIPS' .got is so different 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
// 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);
// 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)
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();
}
sec->finalizeContents();
}
}
+template <typename T> static void finalizeSynthetic(std::unique_ptr<T> &sec) {
+ finalizeSynthetic(sec.get());
+}
// We need to generate and finalize the content that depends on the address of
// InputSections. As the generation of the content may also alter InputSection