[lld] r222310 - [ELF] Rename MergedSection to OutputSection.

Shankar Easwaran shankare at codeaurora.org
Tue Nov 18 19:51:43 PST 2014


Author: shankare
Date: Tue Nov 18 21:51:43 2014
New Revision: 222310

URL: http://llvm.org/viewvc/llvm-project?rev=222310&view=rev
Log:
[ELF] Rename MergedSection to OutputSection.

No change in functionality.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
    lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
    lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
    lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h

Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=222310&r1=222309&r2=222310&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Tue Nov 18 21:51:43 2014
@@ -146,12 +146,11 @@ public:
     }
   };
 
-
-  // Merged Sections contain the map of Sectionnames to a vector of sections,
+  // Output Sections contain the map of Sectionnames to a vector of sections,
   // that have been merged to form a single section
-  typedef std::map<StringRef, MergedSections<ELFT> *> MergedSectionMapT;
-  typedef typename std::vector<MergedSections<ELFT> *>::iterator
-  MergedSectionIter;
+  typedef std::map<StringRef, OutputSection<ELFT> *> OutputSectionMapT;
+  typedef
+      typename std::vector<OutputSection<ELFT> *>::iterator OutputSectionIter;
 
   typedef std::unordered_map<SectionKey, AtomSection<ELFT> *, SectionKeyHash,
                              SectionKeyEq> SectionMapT;
@@ -196,9 +195,9 @@ public:
   ErrorOr<const lld::AtomLayout &> addAtom(const Atom *atom) override;
 
   /// \brief Find an output Section given a section name.
-  MergedSections<ELFT> *findOutputSection(StringRef name) {
-    auto iter = _mergedSectionMap.find(name);
-    if (iter == _mergedSectionMap.end())
+  OutputSection<ELFT> *findOutputSection(StringRef name) {
+    auto iter = _outputSectionMap.find(name);
+    if (iter == _outputSectionMap.end())
       return nullptr;
     return iter->second;
   }
@@ -209,8 +208,8 @@ public:
                         FindByName(name));
   }
 
-  // Merge sections with the same name into a MergedSections
-  void mergeSimilarSections();
+  // Output sections with the same name into a OutputSection
+  void createOutputSections();
 
   void assignSectionsToSegments() override;
 
@@ -250,7 +249,7 @@ public:
     _programHeader = p;
   }
 
-  inline range<MergedSectionIter> mergedSections() { return _mergedSections; }
+  inline range<OutputSectionIter> outputSections() { return _outputSections; }
 
   inline range<ChunkIter> sections() { return _sections; }
 
@@ -314,12 +313,12 @@ protected:
 protected:
   llvm::BumpPtrAllocator _allocator;
   SectionMapT _sectionMap;
-  MergedSectionMapT _mergedSectionMap;
+  OutputSectionMapT _outputSectionMap;
   AdditionalSegmentMapT _additionalSegmentMap;
   SegmentMapT _segmentMap;
   std::vector<Chunk<ELFT> *> _sections;
   std::vector<Segment<ELFT> *> _segments;
-  std::vector<MergedSections<ELFT> *> _mergedSections;
+  std::vector<OutputSection<ELFT> *> _outputSections;
   ELFHeader<ELFT> *_elfHeader;
   ProgramHeader<ELFT> *_programHeader;
   LLD_UNIQUE_BUMP_PTR(RelocationTable<ELFT>) _dynamicRelocationTable;
@@ -608,27 +607,24 @@ ErrorOr<const lld::AtomLayout &> Default
   }
 }
 
-/// Merge sections with the same name into a MergedSections
-template<class ELFT>
-void
-DefaultLayout<ELFT>::mergeSimilarSections() {
-  MergedSections<ELFT> *mergedSection;
+/// Output sections with the same name into a OutputSection
+template <class ELFT> void DefaultLayout<ELFT>::createOutputSections() {
+  OutputSection<ELFT> *outputSection;
 
   for (auto &si : _sections) {
-    const std::pair<StringRef, MergedSections<ELFT> *>
-      currentMergedSections(si->name(), nullptr);
-    std::pair<typename MergedSectionMapT::iterator, bool>
-                            mergedSectionInsert
-                            (_mergedSectionMap.insert(currentMergedSections));
-    if (!mergedSectionInsert.second) {
-      mergedSection = mergedSectionInsert.first->second;
+    const std::pair<StringRef, OutputSection<ELFT> *> currentOutputSection(
+        si->name(), nullptr);
+    std::pair<typename OutputSectionMapT::iterator, bool> outputSectionInsert(
+        _outputSectionMap.insert(currentOutputSection));
+    if (!outputSectionInsert.second) {
+      outputSection = outputSectionInsert.first->second;
     } else {
-      mergedSection = new (_allocator.Allocate<MergedSections<ELFT>>())
-        MergedSections<ELFT>(si->name());
-      _mergedSections.push_back(mergedSection);
-      mergedSectionInsert.first->second = mergedSection;
+      outputSection = new (_allocator.Allocate<OutputSection<ELFT>>())
+          OutputSection<ELFT>(si->name());
+      _outputSections.push_back(outputSection);
+      outputSectionInsert.first->second = outputSection;
     }
-    mergedSection->appendSection(si);
+    outputSection->appendSection(si);
   }
 }
 
@@ -640,33 +636,33 @@ template <class ELFT> void DefaultLayout
                    [](Chunk<ELFT> *A, Chunk<ELFT> *B) {
     return A->order() < B->order();
   });
-  // Merge all sections
-  mergeSimilarSections();
+  // Create output sections.
+  createOutputSections();
   // Set the ordinal after sorting the sections
   int ordinal = 1;
-  for (auto msi : _mergedSections) {
-    msi->setOrdinal(ordinal);
-    for (auto ai : msi->sections()) {
+  for (auto osi : _outputSections) {
+    osi->setOrdinal(ordinal);
+    for (auto ai : osi->sections()) {
       ai->setOrdinal(ordinal);
     }
     ++ordinal;
   }
-  for (auto msi : _mergedSections) {
-    for (auto ai : msi->sections()) {
+  for (auto osi : _outputSections) {
+    for (auto ai : osi->sections()) {
       if (auto section = dyn_cast<Section<ELFT> >(ai)) {
         if (!hasOutputSegment(section))
           continue;
 
-        msi->setLoadableSection(section->isLoadableSection());
+        osi->setLoadableSection(section->isLoadableSection());
 
         // Get the segment type for the section
         int64_t segmentType = getSegmentType(section);
 
-        msi->setHasSegment();
+        osi->setHasSegment();
         section->setSegmentType(segmentType);
         StringRef segmentName = section->segmentKindToStr();
 
-        int64_t lookupSectionFlag = msi->flags();
+        int64_t lookupSectionFlag = osi->flags();
         if ((!(lookupSectionFlag & llvm::ELF::SHF_WRITE)) &&
             (_context.mergeRODataToTextSegment()))
           lookupSectionFlag &= ~llvm::ELF::SHF_EXECINSTR;
@@ -804,12 +800,12 @@ DefaultLayout<ELFT>::assignVirtualAddres
       section->assignFileOffsets(section->fileOffset());
   }
   // Set the size of the merged Sections
-  for (auto msi : _mergedSections) {
+  for (auto osi : _outputSections) {
     uint64_t sectionfileoffset = 0;
     uint64_t startFileOffset = 0;
     uint64_t sectionsize = 0;
     bool isFirstSection = true;
-    for (auto si : msi->sections()) {
+    for (auto si : osi->sections()) {
       if (isFirstSection) {
         startFileOffset = si->fileOffset();
         isFirstSection = false;
@@ -818,16 +814,16 @@ DefaultLayout<ELFT>::assignVirtualAddres
       sectionsize = si->fileSize();
     }
     sectionsize = (sectionfileoffset - startFileOffset) + sectionsize;
-    msi->setFileOffset(startFileOffset);
-    msi->setSize(sectionsize);
+    osi->setFileOffset(startFileOffset);
+    osi->setSize(sectionsize);
   }
   // Set the virtual addr of the merged Sections
-  for (auto msi : _mergedSections) {
+  for (auto osi : _outputSections) {
     uint64_t sectionstartaddr = 0;
     uint64_t startaddr = 0;
     uint64_t sectionsize = 0;
     bool isFirstSection = true;
-    for (auto si : msi->sections()) {
+    for (auto si : osi->sections()) {
       if (isFirstSection) {
         startaddr = si->virtualAddr();
         isFirstSection = false;
@@ -836,8 +832,8 @@ DefaultLayout<ELFT>::assignVirtualAddres
       sectionsize = si->memSize();
     }
     sectionsize = (sectionstartaddr - startaddr) + sectionsize;
-    msi->setMemSize(sectionsize);
-    msi->setAddr(startaddr);
+    osi->setMemSize(sectionsize);
+    osi->setAddr(startaddr);
   }
 }
 

Modified: lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h?rev=222310&r1=222309&r2=222310&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h Tue Nov 18 21:51:43 2014
@@ -266,7 +266,7 @@ public:
 
   SectionHeader(const ELFLinkingContext &, int32_t order);
 
-  void appendSection(MergedSections<ELFT> *section);
+  void appendSection(OutputSection<ELFT> *section);
 
   void updateSection(Section<ELFT> *section);
 
@@ -317,9 +317,8 @@ SectionHeader<ELFT>::SectionHeader(const
   this->_fsize += sizeof (Elf_Shdr);
 }
 
-template<class ELFT>
-void
-SectionHeader<ELFT>::appendSection(MergedSections<ELFT> *section) {
+template <class ELFT>
+void SectionHeader<ELFT>::appendSection(OutputSection<ELFT> *section) {
   Elf_Shdr *shdr = new (_sectionAllocate.Allocate<Elf_Shdr>()) Elf_Shdr;
   shdr->sh_name   = _stringSection->addString(section->name());
   shdr->sh_type   = section->type();

Modified: lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h?rev=222310&r1=222309&r2=222310&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h Tue Nov 18 21:51:43 2014
@@ -249,24 +249,24 @@ void OutputELFWriter<ELFT>::buildAtomToA
 template<class ELFT>
 void OutputELFWriter<ELFT>::buildSectionHeaderTable() {
   ScopedTask task(getDefaultDomain(), "buildSectionHeaderTable");
-  for (auto mergedSec : _layout.mergedSections()) {
-    if (mergedSec->kind() != Chunk<ELFT>::Kind::ELFSection &&
-        mergedSec->kind() != Chunk<ELFT>::Kind::AtomSection)
+  for (auto outputSection : _layout.outputSections()) {
+    if (outputSection->kind() != Chunk<ELFT>::Kind::ELFSection &&
+        outputSection->kind() != Chunk<ELFT>::Kind::AtomSection)
       continue;
-    if (mergedSec->hasSegment())
-      _shdrtab->appendSection(mergedSec);
+    if (outputSection->hasSegment())
+      _shdrtab->appendSection(outputSection);
   }
 }
 
 template<class ELFT>
 void OutputELFWriter<ELFT>::assignSectionsWithNoSegments() {
   ScopedTask task(getDefaultDomain(), "assignSectionsWithNoSegments");
-  for (auto mergedSec : _layout.mergedSections()) {
-    if (mergedSec->kind() != Chunk<ELFT>::Kind::ELFSection &&
-        mergedSec->kind() != Chunk<ELFT>::Kind::AtomSection)
+  for (auto outputSection : _layout.outputSections()) {
+    if (outputSection->kind() != Chunk<ELFT>::Kind::ELFSection &&
+        outputSection->kind() != Chunk<ELFT>::Kind::AtomSection)
       continue;
-    if (!mergedSec->hasSegment())
-      _shdrtab->appendSection(mergedSec);
+    if (!outputSection->hasSegment())
+      _shdrtab->appendSection(outputSection);
   }
   _layout.assignFileOffsetsForMiscSections();
   for (auto sec : _layout.sections())

Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=222310&r1=222309&r2=222310&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Tue Nov 18 21:51:43 2014
@@ -31,7 +31,7 @@
 
 namespace lld {
 namespace elf {
-template <class> class MergedSections;
+template <class> class OutputSection;
 using namespace llvm::ELF;
 template <class ELFT> class Segment;
 
@@ -40,9 +40,9 @@ template <class ELFT> class Section : pu
 public:
   Section(const ELFLinkingContext &context, StringRef name,
           typename Chunk<ELFT>::Kind k = Chunk<ELFT>::Kind::ELFSection)
-      : Chunk<ELFT>(name, k, context), _parent(nullptr), _flags(0), _entSize(0),
-        _type(0), _link(0), _info(0), _isFirstSectionInMerge(false),
-        _segmentType(SHT_NULL) {}
+      : Chunk<ELFT>(name, k, context), _outputSection(nullptr), _flags(0),
+        _entSize(0), _type(0), _link(0), _info(0),
+        _isFirstSectionInOutputSection(false), _segmentType(SHT_NULL) {}
 
   /// \brief Modify the section contents before assigning virtual addresses
   //  or assigning file offsets
@@ -95,9 +95,9 @@ public:
 
   virtual bool findAtomAddrByName(StringRef, uint64_t &) { return false; }
 
-  void setMergedSection(MergedSections<ELFT> *ms, bool isFirst = false) {
-    _parent = ms;
-    _isFirstSectionInMerge = isFirst;
+  void setOutputSection(OutputSection<ELFT> *os, bool isFirst = false) {
+    _outputSection = os;
+    _isFirstSectionInOutputSection = isFirst;
   }
 
   static bool classof(const Chunk<ELFT> *c) {
@@ -106,12 +106,13 @@ public:
   }
 
   uint64_t align2() const override {
-    return _isFirstSectionInMerge ? _parent->align2() : this->_align2;
+    return _isFirstSectionInOutputSection ? _outputSection->align2()
+                                          : this->_align2;
   }
 
 protected:
-  /// \brief MergedSections this Section is a member of, or nullptr.
-  MergedSections<ELFT> *_parent;
+  /// \brief OutputSection this Section is a member of, or nullptr.
+  OutputSection<ELFT> *_outputSection;
   /// \brief ELF SHF_* flags.
   uint64_t _flags;
   /// \brief The size of each entity.
@@ -122,8 +123,8 @@ protected:
   uint32_t _link;
   /// \brief the sh_info field.
   uint32_t _info;
-  /// \brief Is this the first section in the merged section list.
-  bool _isFirstSectionInMerge;
+  /// \brief Is this the first section in the output section.
+  bool _isFirstSectionInOutputSection;
   /// \brief the output ELF segment type of this section.
   Layout::SegmentType _segmentType;
 };
@@ -383,22 +384,21 @@ void AtomSection<ELFT>::write(ELFWriter
   });
 }
 
-/// \brief A MergedSections represents a set of sections grouped by the same
+/// \brief A OutputSection represents a set of sections grouped by the same
 /// name. The output file that gets written by the linker has sections grouped
 /// by similar names
-template<class ELFT>
-class MergedSections {
+template <class ELFT> class OutputSection {
 public:
   // Iterators
   typedef typename std::vector<Chunk<ELFT> *>::iterator ChunkIter;
 
-  MergedSections(StringRef name);
+  OutputSection(StringRef name);
 
-  // Appends a section into the list of sections that are part of this Merged
+  // Appends a section into the list of sections that are part of this Output
   // Section
   void appendSection(Chunk<ELFT> *c);
 
-  // Set the MergedSections is associated with a segment
+  // Set the OutputSection is associated with a segment
   inline void setHasSegment() { _hasSegment = true; }
 
   /// Sets the ordinal
@@ -411,13 +411,13 @@ public:
     _memSize = memsz;
   }
 
-  /// Sets the size fo the merged Section
+  /// Sets the size fo the output Section.
   inline void setSize(uint64_t fsiz) {
     _size = fsiz;
   }
 
-  // The offset of the first section contained in the merged section is
-  // contained here
+  // The offset of the first section contained in the output section is
+  // contained here.
   inline void setFileOffset(uint64_t foffset) {
     _fileOffset = foffset;
   }
@@ -445,7 +445,7 @@ public:
 
   inline range<ChunkIter> sections() { return _sections; }
 
-  // The below functions returns the properties of the MergeSection
+  // The below functions returns the properties of the OutputSection.
   inline bool hasSegment() const { return _hasSegment; }
 
   inline StringRef name() const { return _name; }
@@ -493,16 +493,14 @@ private:
   std::vector<Chunk<ELFT> *> _sections;
 };
 
-/// MergedSections
+/// OutputSection
 template <class ELFT>
-MergedSections<ELFT>::MergedSections(StringRef name)
+OutputSection<ELFT>::OutputSection(StringRef name)
     : _name(name), _hasSegment(false), _ordinal(0), _flags(0), _size(0),
       _memSize(0), _fileOffset(0), _virtualAddr(0), _shInfo(0), _entSize(0),
       _link(0), _align2(0), _kind(0), _type(0), _isLoadableSection(false) {}
 
-template<class ELFT>
-void
-MergedSections<ELFT>::appendSection(Chunk<ELFT> *c) {
+template <class ELFT> void OutputSection<ELFT>::appendSection(Chunk<ELFT> *c) {
   if (c->align2() > _align2)
     _align2 = c->align2();
   if (const auto section = dyn_cast<Section<ELFT>>(c)) {
@@ -513,7 +511,7 @@ MergedSections<ELFT>::appendSection(Chun
     _type = section->getType();
     if (_flags < section->getFlags())
       _flags = section->getFlags();
-    section->setMergedSection(this, (_sections.size() == 0));
+    section->setOutputSection(this, (_sections.size() == 0));
   }
   _kind = c->kind();
   _sections.push_back(c);
@@ -841,9 +839,9 @@ template <class ELFT> void SymbolTable<E
   }
   this->_info = shInfo;
   this->_link = _stringSection->ordinal();
-  if (this->_parent) {
-    this->_parent->setInfo(this->_info);
-    this->_parent->setLink(this->_link);
+  if (this->_outputSection) {
+    this->_outputSection->setInfo(this->_info);
+    this->_outputSection->setLink(this->_link);
   }
 }
 
@@ -965,8 +963,8 @@ public:
 
   virtual void finalize() {
     this->_link = _symbolTable ? _symbolTable->ordinal() : 0;
-    if (this->_parent)
-      this->_parent->setLink(this->_link);
+    if (this->_outputSection)
+      this->_outputSection->setLink(this->_link);
   }
 
   virtual void write(ELFWriter *writer, TargetLayout<ELFT> &layout,
@@ -1132,10 +1130,10 @@ public:
     StringTable<ELFT> *dynamicStringTable =
         _dynamicSymbolTable->getStringTable();
     this->_link = dynamicStringTable->ordinal();
-    if (this->_parent) {
-      this->_parent->setType(this->_type);
-      this->_parent->setInfo(this->_info);
-      this->_parent->setLink(this->_link);
+    if (this->_outputSection) {
+      this->_outputSection->setType(this->_type);
+      this->_outputSection->setInfo(this->_info);
+      this->_outputSection->setLink(this->_link);
     }
   }
 
@@ -1327,8 +1325,8 @@ public:
 
   virtual void finalize() {
     this->_link = _symbolTable ? _symbolTable->ordinal() : 0;
-    if (this->_parent)
-      this->_parent->setLink(this->_link);
+    if (this->_outputSection)
+      this->_outputSection->setLink(this->_link);
   }
 
   virtual void write(ELFWriter *writer, TargetLayout<ELFT> &layout,
@@ -1381,7 +1379,7 @@ public:
   }
 
   void finalize() override {
-    MergedSections<ELFT> *s = _layout.findOutputSection(".eh_frame");
+    OutputSection<ELFT> *s = _layout.findOutputSection(".eh_frame");
     _ehFrameAddr = s ? s->virtualAddr() : 0;
   }
 





More information about the llvm-commits mailing list