From: Shankar Easwaran Date: Sun, 30 Nov 2014 03:18:08 +0000 (+0000) Subject: [ELF] Rename MergedSection to OutputSection. X-Git-Tag: llvmorg-3.6.0-rc1~2721 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d382c6943d782641b0aa1ac81bbb65dc08713eb;p=platform%2Fupstream%2Fllvm.git [ELF] Rename MergedSection to OutputSection. No change in functionality. llvm-svn: 222972 --- diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h index 383706eed004..94907f48e6ef 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -144,12 +144,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 *> MergedSectionMapT; - typedef typename std::vector *>::iterator - MergedSectionIter; + typedef std::map *> OutputSectionMapT; + typedef + typename std::vector *>::iterator OutputSectionIter; typedef std::unordered_map *, SectionKeyHash, SectionKeyEq> SectionMapT; @@ -193,9 +192,9 @@ public: ErrorOr addAtom(const Atom *atom) override; /// \brief Find an output Section given a section name. - MergedSections *findOutputSection(StringRef name) { - auto iter = _mergedSectionMap.find(name); - if (iter == _mergedSectionMap.end()) + OutputSection *findOutputSection(StringRef name) { + auto iter = _outputSectionMap.find(name); + if (iter == _outputSectionMap.end()) return nullptr; return iter->second; } @@ -206,8 +205,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; @@ -247,7 +246,7 @@ public: _programHeader = p; } - inline range mergedSections() { return _mergedSections; } + inline range outputSections() { return _outputSections; } inline range sections() { return _sections; } @@ -311,12 +310,12 @@ protected: protected: llvm::BumpPtrAllocator _allocator; SectionMapT _sectionMap; - MergedSectionMapT _mergedSectionMap; + OutputSectionMapT _outputSectionMap; AdditionalSegmentMapT _additionalSegmentMap; SegmentMapT _segmentMap; std::vector *> _sections; std::vector *> _segments; - std::vector *> _mergedSections; + std::vector *> _outputSections; ELFHeader *_elfHeader; ProgramHeader *_programHeader; LLD_UNIQUE_BUMP_PTR(RelocationTable) _dynamicRelocationTable; @@ -604,27 +603,24 @@ ErrorOr DefaultLayout::addAtom(const Atom *atom) } } -/// Merge sections with the same name into a MergedSections -template -void -DefaultLayout::mergeSimilarSections() { - MergedSections *mergedSection; +/// Output sections with the same name into a OutputSection +template void DefaultLayout::createOutputSections() { + OutputSection *outputSection; for (auto &si : _sections) { - const std::pair *> - currentMergedSections(si->name(), nullptr); - std::pair - mergedSectionInsert - (_mergedSectionMap.insert(currentMergedSections)); - if (!mergedSectionInsert.second) { - mergedSection = mergedSectionInsert.first->second; + const std::pair *> currentOutputSection( + si->name(), nullptr); + std::pair outputSectionInsert( + _outputSectionMap.insert(currentOutputSection)); + if (!outputSectionInsert.second) { + outputSection = outputSectionInsert.first->second; } else { - mergedSection = new (_allocator.Allocate>()) - MergedSections(si->name()); - _mergedSections.push_back(mergedSection); - mergedSectionInsert.first->second = mergedSection; + outputSection = new (_allocator.Allocate>()) + OutputSection(si->name()); + _outputSections.push_back(outputSection); + outputSectionInsert.first->second = outputSection; } - mergedSection->appendSection(si); + outputSection->appendSection(si); } } @@ -636,33 +632,33 @@ template void DefaultLayout::assignSectionsToSegments() { [](Chunk *A, Chunk *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 >(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; @@ -800,12 +796,12 @@ DefaultLayout::assignVirtualAddress() { 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; @@ -814,16 +810,16 @@ DefaultLayout::assignVirtualAddress() { 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; @@ -832,8 +828,8 @@ DefaultLayout::assignVirtualAddress() { sectionsize = si->memSize(); } sectionsize = (sectionstartaddr - startaddr) + sectionsize; - msi->setMemSize(sectionsize); - msi->setAddr(startaddr); + osi->setMemSize(sectionsize); + osi->setAddr(startaddr); } } diff --git a/lld/lib/ReaderWriter/ELF/HeaderChunks.h b/lld/lib/ReaderWriter/ELF/HeaderChunks.h index 62a4374d0155..d21aee377a96 100644 --- a/lld/lib/ReaderWriter/ELF/HeaderChunks.h +++ b/lld/lib/ReaderWriter/ELF/HeaderChunks.h @@ -266,7 +266,7 @@ public: SectionHeader(const ELFLinkingContext &, int32_t order); - void appendSection(MergedSections *section); + void appendSection(OutputSection *section); void updateSection(Section *section); @@ -317,9 +317,8 @@ SectionHeader::SectionHeader(const ELFLinkingContext &context, this->_fsize += sizeof (Elf_Shdr); } -template -void -SectionHeader::appendSection(MergedSections *section) { +template +void SectionHeader::appendSection(OutputSection *section) { Elf_Shdr *shdr = new (_sectionAllocate.Allocate()) Elf_Shdr; shdr->sh_name = _stringSection->addString(section->name()); shdr->sh_type = section->type(); diff --git a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h index 2cb8ded4f1fd..440187e0a7ed 100644 --- a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h +++ b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h @@ -249,24 +249,24 @@ void OutputELFWriter::buildAtomToAddressMap(const File &file) { template void OutputELFWriter::buildSectionHeaderTable() { ScopedTask task(getDefaultDomain(), "buildSectionHeaderTable"); - for (auto mergedSec : _layout.mergedSections()) { - if (mergedSec->kind() != Chunk::Kind::ELFSection && - mergedSec->kind() != Chunk::Kind::AtomSection) + for (auto outputSection : _layout.outputSections()) { + if (outputSection->kind() != Chunk::Kind::ELFSection && + outputSection->kind() != Chunk::Kind::AtomSection) continue; - if (mergedSec->hasSegment()) - _shdrtab->appendSection(mergedSec); + if (outputSection->hasSegment()) + _shdrtab->appendSection(outputSection); } } template void OutputELFWriter::assignSectionsWithNoSegments() { ScopedTask task(getDefaultDomain(), "assignSectionsWithNoSegments"); - for (auto mergedSec : _layout.mergedSections()) { - if (mergedSec->kind() != Chunk::Kind::ELFSection && - mergedSec->kind() != Chunk::Kind::AtomSection) + for (auto outputSection : _layout.outputSections()) { + if (outputSection->kind() != Chunk::Kind::ELFSection && + outputSection->kind() != Chunk::Kind::AtomSection) continue; - if (!mergedSec->hasSegment()) - _shdrtab->appendSection(mergedSec); + if (!outputSection->hasSegment()) + _shdrtab->appendSection(outputSection); } _layout.assignFileOffsetsForMiscSections(); for (auto sec : _layout.sections()) diff --git a/lld/lib/ReaderWriter/ELF/SectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h index fd15f9651026..8b9e8199dce2 100644 --- a/lld/lib/ReaderWriter/ELF/SectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h @@ -31,7 +31,7 @@ namespace lld { namespace elf { -template class MergedSections; +template class OutputSection; using namespace llvm::ELF; template class Segment; @@ -40,9 +40,9 @@ template class Section : public Chunk { public: Section(const ELFLinkingContext &context, StringRef name, typename Chunk::Kind k = Chunk::Kind::ELFSection) - : Chunk(name, k, context), _parent(nullptr), _flags(0), _entSize(0), - _type(0), _link(0), _info(0), _isFirstSectionInMerge(false), - _segmentType(SHT_NULL) {} + : Chunk(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 *ms, bool isFirst = false) { - _parent = ms; - _isFirstSectionInMerge = isFirst; + void setOutputSection(OutputSection *os, bool isFirst = false) { + _outputSection = os; + _isFirstSectionInOutputSection = isFirst; } static bool classof(const Chunk *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 *_parent; + /// \brief OutputSection this Section is a member of, or nullptr. + OutputSection *_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::write(ELFWriter *writer, TargetLayout &layout, }); } -/// \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 MergedSections { +template class OutputSection { public: // Iterators typedef typename std::vector *>::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 *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 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 *> _sections; }; -/// MergedSections +/// OutputSection template -MergedSections::MergedSections(StringRef name) +OutputSection::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 -void -MergedSections::appendSection(Chunk *c) { +template void OutputSection::appendSection(Chunk *c) { if (c->align2() > _align2) _align2 = c->align2(); if (const auto section = dyn_cast>(c)) { @@ -513,7 +511,7 @@ MergedSections::appendSection(Chunk *c) { _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 void SymbolTable::finalize(bool sort) { } 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 &layout, @@ -1132,10 +1130,10 @@ public: StringTable *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 &layout, @@ -1381,7 +1379,7 @@ public: } void finalize() override { - MergedSections *s = _layout.findOutputSection(".eh_frame"); + OutputSection *s = _layout.findOutputSection(".eh_frame"); _ehFrameAddr = s ? s->virtualAddr() : 0; }