[elf2] Pass BSSSec to the relocation handling code differently. Don't store it in the symbol.

llvm-svn: 248393
This commit is contained in:
Michael J. Spencer 2015-09-23 16:57:31 +00:00
parent 54bbae5c0f
commit 2812aa82d0
6 changed files with 21 additions and 11 deletions

View File

@ -29,7 +29,8 @@ template <bool isRela>
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 @@ void InputSection<ELFT>::relocate(
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 @@ void InputSection<ELFT>::relocate(
}
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 @@ void InputSection<ELFT>::writeTo(uint8_t *Buf, const PltSection<ELFT> &PltSec,
// 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);
}
}

View File

@ -37,8 +37,8 @@ public:
// 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 @@ private:
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

View File

@ -252,7 +252,7 @@ lld::elf2::getLocalSymVA(const typename ELFFile<ELFT>::Elf_Sym *Sym,
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>

View File

@ -242,11 +242,13 @@ public:
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>

View File

@ -189,8 +189,6 @@ public:
// 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.

View File

@ -365,6 +365,11 @@ template <class ELFT> void Writer<ELFT>::createSections() {
}
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 @@ template <class ELFT> void Writer<ELFT>::createSections() {
uintX_t Align = C->MaxAlignment;
Off = RoundUpToAlignment(Off, Align);
C->OffsetInBSS = Off;
C->OutputSec = BSSSec;
Off += Sym.st_size;
}