forked from OSchip/llvm-project
Add CopyRelSection instances to BSS in the regular way.
Previously, space in a BSS section for copy relocations are reserved in a special way. We directly manipulated size of the BSS section. r294577 changed the way of doing it. Now, we create an instance of CopyRelSection (which is a synthetic input section) for each copy relocation. This patch removes the remains of the old way and add CopyRelSections to BSS sections using `addSections` function, which is the usual way to add an input section to an output section. llvm-svn: 295278
This commit is contained in:
parent
86a1b135f0
commit
da5cc84661
|
@ -426,37 +426,28 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol<ELFT> *SS) {
|
|||
// See if this symbol is in a read-only segment. If so, preserve the symbol's
|
||||
// memory protection by reserving space in the .bss.rel.ro section.
|
||||
bool IsReadOnly = isReadOnly(SS);
|
||||
OutputSection<ELFT> *CopySec =
|
||||
IsReadOnly ? Out<ELFT>::BssRelRo : Out<ELFT>::Bss;
|
||||
OutputSection<ELFT> *OSec = IsReadOnly ? Out<ELFT>::BssRelRo : Out<ELFT>::Bss;
|
||||
|
||||
uintX_t Alignment = getAlignment(SS);
|
||||
uintX_t Off = alignTo(CopySec->Size, Alignment);
|
||||
CopySec->Size = Off + SymSize;
|
||||
CopySec->updateAlignment(Alignment);
|
||||
uintX_t Shndx = SS->Sym.st_shndx;
|
||||
uintX_t Value = SS->Sym.st_value;
|
||||
|
||||
// Create a SyntheticSection in CopySec to hold the .bss and the Copy Reloc
|
||||
auto *CopyISec = make<CopyRelSection<ELFT>>(IsReadOnly, Alignment, SymSize);
|
||||
CopyISec->OutSecOff = Off;
|
||||
CopyISec->OutSec = CopySec;
|
||||
CopySec->Sections.push_back(CopyISec);
|
||||
// Create a SyntheticSection in Out to hold the .bss and the Copy Reloc.
|
||||
auto *ISec =
|
||||
make<CopyRelSection<ELFT>>(IsReadOnly, getAlignment(SS), SymSize);
|
||||
OSec->addSection(ISec);
|
||||
|
||||
// Look through the DSO's dynamic symbol table for aliases and create a
|
||||
// dynamic symbol for each one. This causes the copy relocation to correctly
|
||||
// interpose any aliases.
|
||||
for (const Elf_Sym &S : SS->file()->getGlobalSymbols()) {
|
||||
if (S.st_shndx != Shndx || S.st_value != Value)
|
||||
if (S.st_shndx != SS->Sym.st_shndx || S.st_value != SS->Sym.st_value)
|
||||
continue;
|
||||
auto *Alias = dyn_cast_or_null<SharedSymbol<ELFT>>(
|
||||
Symtab<ELFT>::X->find(check(S.getName(SS->file()->getStringTable()))));
|
||||
if (!Alias)
|
||||
continue;
|
||||
Alias->CopySection = CopyISec;
|
||||
Alias->CopySection = ISec;
|
||||
Alias->NeedsCopyOrPltAddr = true;
|
||||
Alias->symbol()->IsUsedInRegularObj = true;
|
||||
}
|
||||
In<ELFT>::RelaDyn->addReloc({Target->CopyRel, CopyISec, 0, false, SS, 0});
|
||||
In<ELFT>::RelaDyn->addReloc({Target->CopyRel, ISec, 0, false, SS, 0});
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
|
|
|
@ -107,7 +107,8 @@ private:
|
|||
uint8_t *HashBuf;
|
||||
};
|
||||
|
||||
// SHT_NOBITS section created for a copyReloc
|
||||
// For each copy relocation, we create an instance of this class to
|
||||
// reserve space in .bss or .bss.rel.ro.
|
||||
template <class ELFT>
|
||||
class CopyRelSection final : public SyntheticSection<ELFT> {
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
|
|
|
@ -1184,12 +1184,16 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
|
|||
}
|
||||
|
||||
template <class ELFT> void Writer<ELFT>::addPredefinedSections() {
|
||||
if (Out<ELFT>::Bss->Size > 0)
|
||||
OutputSections.push_back(Out<ELFT>::Bss);
|
||||
if (Out<ELFT>::BssRelRo->Size > 0)
|
||||
OutputSections.push_back(Out<ELFT>::BssRelRo);
|
||||
auto Add = [=](OutputSection<ELFT> *Sec) {
|
||||
if (!Sec->Sections.empty()) {
|
||||
Sec->assignOffsets();
|
||||
OutputSections.push_back(Sec);
|
||||
}
|
||||
};
|
||||
Add(Out<ELFT>::Bss);
|
||||
Add(Out<ELFT>::BssRelRo);
|
||||
|
||||
auto OS = dyn_cast_or_null<OutputSection<ELFT>>(findSection(".ARM.exidx"));
|
||||
auto *OS = dyn_cast_or_null<OutputSection<ELFT>>(findSection(".ARM.exidx"));
|
||||
if (OS && !OS->Sections.empty() && !Config->Relocatable)
|
||||
OS->addSection(make<ARMExidxSentinelSection<ELFT>>());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue