Revert r297008: [ELF] - Make Bss and BssRelRo sections to be synthetic (#2).
This reverts commit r297008 because it's reported that that
change broke AArch64 bots.
llvm-svn: 297297
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 82724bb..c1631c6 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -479,20 +479,23 @@
// 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);
- BssRelSection<ELFT> *RelSec = IsReadOnly ? In<ELFT>::BssRelRo : In<ELFT>::Bss;
- uintX_t Off = RelSec->addCopyRelocation(SS->getAlignment<ELFT>(), SymSize);
+ 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);
// 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, RelSec, Off, false, SS, 0});
+ In<ELFT>::RelaDyn->addReloc({Target->CopyRel, ISec, 0, false, SS, 0});
}
template <class ELFT>
@@ -532,12 +535,14 @@
if (Body.isObject()) {
// Produce a copy relocation.
auto *B = cast<SharedSymbol>(&Body);
- if (Config->ZNocopyreloc)
- error(S.getLocation<ELFT>(RelOff) + ": unresolvable relocation " +
- toString(Type) + " against symbol '" + toString(*B) +
- "'; recompile with -fPIC or remove '-z nocopyreloc'");
+ 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'");
- addCopyRelSymbol<ELFT>(B);
+ addCopyRelSymbol<ELFT>(B);
+ }
return Expr;
}
if (Body.isFunc()) {