[elf2] Pass BSSSec to the relocation handling code differently. Don't store it in the symbol.
llvm-svn: 248393
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index dbdaa1d..e8fa4a6 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -29,7 +29,8 @@
void InputSection<ELFT>::relocate(
uint8_t *Buf, iterator_range<const Elf_Rel_Impl<ELFT, isRela> *> Rels,
const ObjectFile<ELFT> &File, uintX_t BaseAddr,
- const PltSection<ELFT> &PltSec, const GotSection<ELFT> &GotSec) {
+ const OutputSection<ELFT> &BssSec, const PltSection<ELFT> &PltSec,
+ const GotSection<ELFT> &GotSec) {
typedef Elf_Rel_Impl<ELFT, isRela> RelType;
bool IsMips64EL = File.getObj()->isMips64EL();
for (const RelType &RI : Rels) {
@@ -58,7 +59,7 @@
break;
case SymbolBody::DefinedCommonKind: {
auto *DC = cast<DefinedCommon<ELFT>>(Body);
- SymVA = DC->OutputSec->getVA() + DC->OffsetInBSS;
+ SymVA = BssSec.getVA() + DC->OffsetInBSS;
break;
}
case SymbolBody::SharedKind:
@@ -87,7 +88,9 @@
}
template <class ELFT>
-void InputSection<ELFT>::writeTo(uint8_t *Buf, const PltSection<ELFT> &PltSec,
+void InputSection<ELFT>::writeTo(uint8_t *Buf,
+ const OutputSection<ELFT> &BssSec,
+ const PltSection<ELFT> &PltSec,
const GotSection<ELFT> &GotSec) {
if (Header->sh_type == SHT_NOBITS)
return;
@@ -102,9 +105,11 @@
// Iterate over all relocation sections that apply to this section.
for (const Elf_Shdr *RelSec : RelocSections) {
if (RelSec->sh_type == SHT_RELA)
- relocate(Base, EObj->relas(RelSec), *File, BaseAddr, PltSec, GotSec);
+ relocate(Base, EObj->relas(RelSec), *File, BaseAddr, BssSec, PltSec,
+ GotSec);
else
- relocate(Base, EObj->rels(RelSec), *File, BaseAddr, PltSec, GotSec);
+ relocate(Base, EObj->rels(RelSec), *File, BaseAddr, BssSec, PltSec,
+ GotSec);
}
}
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index b8a7b75..f0de99e 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -37,8 +37,8 @@
// Write this section to a mmap'ed file, assuming Buf is pointing to
// beginning of the output section.
- void writeTo(uint8_t *Buf, const PltSection<ELFT> &PltSec,
- const GotSection<ELFT> &GotSec);
+ void writeTo(uint8_t *Buf, const OutputSection<ELFT> &BssSec,
+ const PltSection<ELFT> &PltSec, const GotSection<ELFT> &GotSec);
StringRef getSectionName() const;
const Elf_Shdr *getSectionHdr() const { return Header; }
@@ -65,6 +65,7 @@
llvm::iterator_range<
const llvm::object::Elf_Rel_Impl<ELFT, isRela> *> Rels,
const ObjectFile<ELFT> &File, uintX_t BaseAddr,
+ const OutputSection<ELFT> &BssSec,
const PltSection<ELFT> &PltSec, const GotSection<ELFT> &GotSec);
// The offset from beginning of the output sections this section was assigned
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 7b25338..c152fe3 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -252,7 +252,7 @@
template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) {
for (InputSection<ELFT> *C : Sections)
- C->writeTo(Buf, PltSec, GotSec);
+ C->writeTo(Buf, *BssSec, PltSec, GotSec);
}
template <bool Is64Bits>
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h
index 38706b9..6ece9ad 100644
--- a/lld/ELF/OutputSections.h
+++ b/lld/ELF/OutputSections.h
@@ -242,11 +242,13 @@
void addSection(InputSection<ELFT> *C);
void writeTo(uint8_t *Buf) override;
+ void setBssSec(const OutputSection<ELFT> *BS) { BssSec = BS; }
private:
std::vector<InputSection<ELFT> *> Sections;
const PltSection<ELFT> &PltSec;
const GotSection<ELFT> &GotSec;
+ const OutputSection<ELFT> *BssSec = nullptr;
};
template <bool Is64Bits>
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index d9f8925..f6cd077 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -189,8 +189,6 @@
// The maximum alignment we have seen for this symbol.
uintX_t MaxAlignment;
-
- OutputSection<ELFT> *OutputSec = nullptr;
};
// Regular defined symbols read from object file symbol tables.
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 57180df..58ad5ac 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -365,6 +365,11 @@
}
BSSSec = getSection(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
+
+ // The only type in OutputSections is currently OutputSection.
+ for (OutputSectionBase<ELFT::Is64Bits> *OSB : OutputSections)
+ static_cast<OutputSection<ELFT> *>(OSB)->setBssSec(BSSSec);
+
SymTabSec.setBssSec(BSSSec);
DynSymSec.setBssSec(BSSSec);
@@ -376,7 +381,6 @@
uintX_t Align = C->MaxAlignment;
Off = RoundUpToAlignment(Off, Align);
C->OffsetInBSS = Off;
- C->OutputSec = BSSSec;
Off += Sym.st_size;
}