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

Michael J. Spencer via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 09:57:32 PDT 2015


Author: mspencer
Date: Wed Sep 23 11:57:31 2015
New Revision: 248393

URL: http://llvm.org/viewvc/llvm-project?rev=248393&view=rev
Log:
[elf2] Pass BSSSec to the relocation handling code differently. Don't store it in the symbol.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=248393&r1=248392&r2=248393&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Sep 23 11:57:31 2015
@@ -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
   // 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);
   }
 }
 

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=248393&r1=248392&r2=248393&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Sep 23 11:57:31 2015
@@ -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

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=248393&r1=248392&r2=248393&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Sep 23 11:57:31 2015
@@ -252,7 +252,7 @@ lld::elf2::getLocalSymVA(const typename
 
 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>

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=248393&r1=248392&r2=248393&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Wed Sep 23 11:57:31 2015
@@ -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>

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=248393&r1=248392&r2=248393&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Sep 23 11:57:31 2015
@@ -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.

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=248393&r1=248392&r2=248393&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Sep 23 11:57:31 2015
@@ -365,6 +365,11 @@ template <class ELFT> void Writer<ELFT>:
   }
 
   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>:
     uintX_t Align = C->MaxAlignment;
     Off = RoundUpToAlignment(Off, Align);
     C->OffsetInBSS = Off;
-    C->OutputSec = BSSSec;
     Off += Sym.st_size;
   }
 




More information about the llvm-commits mailing list