[ELF] - Make Bss and BssRelRo sections to be synthetic (#2).
In compare with D30458, this makes Bss/BssRelRo to be pure
synthetic sections.
That removes CopyRelSection class completely, making
Bss/BssRelRo to be just regular synthetics.
SharedSymbols involved in creating copy relocations are
converted to DefinedRegular, what also simplifies things.
Differential revision: https://reviews.llvm.org/D30541
llvm-svn: 297008
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 63cc8a2..01a5529 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -479,23 +479,20 @@
// 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<ELFT>(SS);
- OutputSection *OSec = IsReadOnly ? Out::BssRelRo : Out::Bss;
-
- // Create a SyntheticSection in Out to hold the .bss and the Copy Reloc.
- auto *ISec =
- make<CopyRelSection<ELFT>>(IsReadOnly, SS->getAlignment<ELFT>(), SymSize);
- OSec->addSection(ISec);
+ BssRelSection<ELFT> *RelSec = IsReadOnly ? In<ELFT>::BssRelRo : In<ELFT>::Bss;
+ size_t Off = RelSec->addCopyRelocation(SS->getAlignment<ELFT>(), SymSize);
// 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 (SharedSymbol *Sym : getSymbolsAt<ELFT>(SS)) {
- Sym->NeedsCopy = true;
- Sym->Section = ISec;
Sym->symbol()->IsUsedInRegularObj = true;
+ replaceBody<DefinedRegular>(Sym->symbol(), Sym->getName(),
+ /*IsLocal=*/false, Sym->StOther, Sym->Type, Off,
+ Sym->getSize<ELFT>(), RelSec, nullptr);
}
- In<ELFT>::RelaDyn->addReloc({Target->CopyRel, ISec, 0, false, SS, 0});
+ In<ELFT>::RelaDyn->addReloc({Target->CopyRel, RelSec, Off, false, SS, 0});
}
template <class ELFT>
@@ -535,14 +532,12 @@
if (Body.isObject()) {
// Produce a copy relocation.
auto *B = cast<SharedSymbol>(&Body);
- if (!B->NeedsCopy) {
- if (Config->ZNocopyreloc)
- error(S.getLocation<ELFT>(RelOff) + ": unresolvable relocation " +
- toString(Type) + " against symbol '" + toString(*B) +
- "'; recompile with -fPIC or remove '-z nocopyreloc'");
+ if (Config->ZNocopyreloc)
+ error(S.getLocation<ELFT>(RelOff) + ": unresolvable relocation " +
+ toString(Type) + " against symbol '" + toString(*B) +
+ "'; recompile with -fPIC or remove '-z nocopyreloc'");
- addCopyRelSymbol<ELFT>(B);
- }
+ addCopyRelSymbol<ELFT>(B);
return Expr;
}
if (Body.isFunc()) {