No change in functionality.
llvm-svn: 222972
}
};
-
- // 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;
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;
}
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;
_programHeader = p;
}
- inline range<MergedSectionIter> mergedSections() { return _mergedSections; }
+ inline range<OutputSectionIter> outputSections() { return _outputSections; }
inline range<ChunkIter> sections() { return _sections; }
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;
}
}
-/// 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);
}
}
[](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;
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;
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;
sectionsize = si->memSize();
}
sectionsize = (sectionstartaddr - startaddr) + sectionsize;
- msi->setMemSize(sectionsize);
- msi->setAddr(startaddr);
+ osi->setMemSize(sectionsize);
+ osi->setAddr(startaddr);
}
}
SectionHeader(const ELFLinkingContext &, int32_t order);
- void appendSection(MergedSections<ELFT> *section);
+ void appendSection(OutputSection<ELFT> *section);
void updateSection(Section<ELFT> *section);
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();
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())
namespace lld {
namespace elf {
-template <class> class MergedSections;
+template <class> class OutputSection;
using namespace llvm::ELF;
template <class ELFT> class Segment;
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
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) {
}
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.
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;
};
});
}
-/// \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
_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;
}
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; }
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)) {
_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);
}
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);
}
}
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,
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);
}
}
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,
}
void finalize() override {
- MergedSections<ELFT> *s = _layout.findOutputSection(".eh_frame");
+ OutputSection<ELFT> *s = _layout.findOutputSection(".eh_frame");
_ehFrameAddr = s ? s->virtualAddr() : 0;
}