diff options
| author | Michael J. Spencer <bigcheesegs@gmail.com> | 2015-09-23 16:57:31 +0000 |
|---|---|---|
| committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2015-09-23 16:57:31 +0000 |
| commit | 2812aa82d0cd9d626e4da81b5cf90dd3068aa3cc (patch) | |
| tree | 1894c4f13e86982e104f395a326f1fde32eb3ce9 | |
| parent | 54bbae5c0f5d9543ddf976080325306d7dcec2a1 (diff) | |
| download | bcm5719-llvm-2812aa82d0cd9d626e4da81b5cf90dd3068aa3cc.tar.gz bcm5719-llvm-2812aa82d0cd9d626e4da81b5cf90dd3068aa3cc.zip | |
[elf2] Pass BSSSec to the relocation handling code differently. Don't store it in the symbol.
llvm-svn: 248393
| -rw-r--r-- | lld/ELF/InputSection.cpp | 15 | ||||
| -rw-r--r-- | lld/ELF/InputSection.h | 5 | ||||
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/OutputSections.h | 2 | ||||
| -rw-r--r-- | lld/ELF/Symbols.h | 2 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 6 |
6 files changed, 21 insertions, 11 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index dbdaa1d425a..e8fa4a68356 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -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); } } diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index b8a7b7531a7..f0de99ec084 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -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 diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 7b2533846e2..c152fe3d985 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -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> diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 38706b9361f..6ece9adf4d2 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -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> diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index d9f89255d37..f6cd077751c 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -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. diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 57180df8993..58ad5ac81ee 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -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; } |

