Index: ELF/CMakeLists.txt =================================================================== --- ELF/CMakeLists.txt +++ ELF/CMakeLists.txt @@ -10,7 +10,7 @@ InputSection.cpp LinkerScript.cpp MarkLive.cpp - OutputSections.cpp + Segments.cpp SymbolTable.cpp Symbols.cpp Target.cpp Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -43,7 +43,7 @@ llvm::StringRef SoName; llvm::StringRef Sysroot; std::string RPath; - llvm::MapVector> OutputSections; + llvm::MapVector> Segments; std::vector SearchPaths; std::vector Undefined; bool AllowMultipleDefinition; Index: ELF/InputSection.h =================================================================== --- ELF/InputSection.h +++ ELF/InputSection.h @@ -18,8 +18,8 @@ namespace elf2 { template class ObjectFile; -template class OutputSection; -template class OutputSectionBase; +template class Segment; +template class SegmentBase; // This corresponds to a section of an input file. template class InputSectionBase { @@ -40,7 +40,7 @@ InputSectionBase(ObjectFile *File, const Elf_Shdr *Header, Kind SectionKind); - OutputSectionBase *OutSec = nullptr; + SegmentBase *Segm = nullptr; // Used for garbage collection. // Live bit makes sense only when Config->GcSections is true. @@ -156,7 +156,7 @@ // The offset from beginning of the output sections this section was assigned // to. The writer sets a value. - uint64_t OutSecOff = 0; + uint64_t SegmOff = 0; static bool classof(const InputSectionBase *S); }; Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -11,7 +11,7 @@ #include "Config.h" #include "Error.h" #include "InputFiles.h" -#include "OutputSections.h" +#include "Segments.h" #include "Target.h" using namespace llvm; @@ -46,7 +46,7 @@ InputSectionBase::getOffset(uintX_t Offset) { switch (SectionKind) { case Regular: - return cast>(this)->OutSecOff + Offset; + return cast>(this)->SegmOff + Offset; case EHFrame: return cast>(this)->getOffset(Offset); case Merge: @@ -150,7 +150,7 @@ continue; uint8_t *BufLoc = Buf + Offset; - uintX_t AddrLoc = OutSec->getVA() + Offset; + uintX_t AddrLoc = Segm->getVA() + Offset; auto NextRelocs = llvm::make_range(&RI, Rels.end()); if (Target->isTlsLocalDynamicReloc(Type) && @@ -231,10 +231,10 @@ return; // Copy section contents from source object file to output file. ArrayRef Data = this->getSectionData(); - memcpy(Buf + OutSecOff, Data.data(), Data.size()); + memcpy(Buf + SegmOff, Data.data(), Data.size()); ELFFile &EObj = this->File->getObj(); - uint8_t *BufEnd = Buf + OutSecOff + Data.size(); + uint8_t *BufEnd = Buf + SegmOff + Data.size(); // Iterate over all relocation sections that apply to this section. for (const Elf_Shdr *RelSec : this->RelocSections) { if (RelSec->sh_type == SHT_RELA) @@ -323,8 +323,7 @@ ArrayRef D = this->getSectionData(); StringRef Data((const char *)D.data(), D.size()); StringRef Entry = Data.substr(Start, End - Start); - Base = - static_cast *>(this->OutSec)->getOffset(Entry); + Base = static_cast *>(this->Segm)->getOffset(Entry); return Base + Addend; } Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -53,7 +53,7 @@ void readSearchDir(); void readSections(); - void readOutputSectionDescription(); + void readSegmentDescription(); StringSaver Saver; std::vector Tokens; @@ -285,12 +285,12 @@ void LinkerScript::readSections() { expect("{"); while (!skip("}")) - readOutputSectionDescription(); + readSegmentDescription(); } -void LinkerScript::readOutputSectionDescription() { +void LinkerScript::readSegmentDescription() { StringRef Name = next(); - std::vector &InputSections = Config->OutputSections[Name]; + std::vector &InputSections = Config->Segments[Name]; expect(":"); expect("{"); Index: ELF/MarkLive.cpp =================================================================== --- ELF/MarkLive.cpp +++ ELF/MarkLive.cpp @@ -21,7 +21,7 @@ //===----------------------------------------------------------------------===// #include "InputSection.h" -#include "OutputSections.h" +#include "Segments.h" #include "SymbolTable.h" #include "Symbols.h" #include "Writer.h" Index: ELF/Segments.h =================================================================== --- ELF/Segments.h +++ ELF/Segments.h @@ -1,4 +1,4 @@ -//===- OutputSections.h -----------------------------------------*- C++ -*-===// +//===- Segments.h -----------------------------------------*- C++ -*-===// // // The LLVM Linker // @@ -32,7 +32,7 @@ template class InputSectionBase; template class MergeInputSection; template class MipsReginfoInputSection; -template class OutputSection; +template class Segment; template class ObjectFile; template class DefinedRegular; @@ -72,14 +72,14 @@ // This represents a section in an output file. // Different sub classes represent different types of sections. Some contain // input sections, others are created by the linker. -// The writer creates multiple OutputSections and assign them unique, +// The writer creates multiple Segments and assign them unique, // non-overlapping file offsets and VAs. -template class OutputSectionBase { +template class SegmentBase { public: typedef typename llvm::object::ELFFile::uintX_t uintX_t; typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; - OutputSectionBase(StringRef Name, uint32_t sh_type, uintX_t sh_flags); + SegmentBase(StringRef Name, uint32_t sh_type, uintX_t sh_flags); void setVA(uintX_t VA) { Header.sh_addr = VA; } uintX_t getVA() const { return Header.sh_addr; } void setFileOffset(uintX_t Off) { Header.sh_offset = Off; } @@ -110,11 +110,11 @@ protected: StringRef Name; Elf_Shdr Header; - ~OutputSectionBase() = default; + ~SegmentBase() = default; }; -template class GotSection final : public OutputSectionBase { - typedef OutputSectionBase Base; +template class GotSection final : public SegmentBase { + typedef SegmentBase Base; typedef typename Base::uintX_t uintX_t; public: @@ -146,8 +146,7 @@ uint32_t LocalTlsIndexOff = -1; }; -template -class GotPltSection final : public OutputSectionBase { +template class GotPltSection final : public SegmentBase { typedef typename llvm::object::ELFFile::uintX_t uintX_t; public: @@ -162,8 +161,8 @@ std::vector Entries; }; -template class PltSection final : public OutputSectionBase { - typedef OutputSectionBase Base; +template class PltSection final : public SegmentBase { + typedef SegmentBase Base; typedef typename Base::uintX_t uintX_t; public: @@ -185,7 +184,7 @@ }; template -class SymbolTableSection final : public OutputSectionBase { +class SymbolTableSection final : public SegmentBase { public: typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; @@ -216,8 +215,7 @@ unsigned NumLocals = 0; }; -template -class RelocationSection final : public OutputSectionBase { +template class RelocationSection final : public SegmentBase { typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; typedef typename llvm::object::ELFFile::uintX_t uintX_t; @@ -241,15 +239,14 @@ const bool IsRela; }; -template -class OutputSection final : public OutputSectionBase { +template class Segment final : public SegmentBase { public: typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; typedef typename llvm::object::ELFFile::uintX_t uintX_t; - OutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags); + Segment(StringRef Name, uint32_t sh_type, uintX_t sh_flags); void addSection(InputSection *C); void writeTo(uint8_t *Buf) override; @@ -257,14 +254,13 @@ std::vector *> Sections; }; -template -class MergeOutputSection final : public OutputSectionBase { - typedef typename OutputSectionBase::uintX_t uintX_t; +template class MergeSegment final : public SegmentBase { + typedef typename SegmentBase::uintX_t uintX_t; bool shouldTailMerge() const; public: - MergeOutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags); + MergeSegment(StringRef Name, uint32_t sh_type, uintX_t sh_flags); void addSection(MergeInputSection *S); void writeTo(uint8_t *Buf) override; unsigned getOffset(StringRef Val); @@ -288,14 +284,13 @@ std::vector> Fdes; }; -template -class EHOutputSection final : public OutputSectionBase { +template class EHSegment final : public SegmentBase { public: typedef typename llvm::object::ELFFile::uintX_t uintX_t; typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; - EHOutputSection(StringRef Name, uint32_t sh_type, uintX_t sh_flags); + EHSegment(StringRef Name, uint32_t sh_type, uintX_t sh_flags); void writeTo(uint8_t *Buf) override; template @@ -316,15 +311,14 @@ llvm::DenseMap, unsigned> CieMap; }; -template -class InterpSection final : public OutputSectionBase { +template class InterpSection final : public SegmentBase { public: InterpSection(); void writeTo(uint8_t *Buf) override; }; template -class StringTableSection final : public OutputSectionBase { +class StringTableSection final : public SegmentBase { public: typedef typename llvm::object::ELFFile::uintX_t uintX_t; StringTableSection(StringRef Name, bool Dynamic); @@ -345,8 +339,7 @@ llvm::StringTableBuilder StrTabBuilder{llvm::StringTableBuilder::ELF}; }; -template -class HashTableSection final : public OutputSectionBase { +template class HashTableSection final : public SegmentBase { typedef typename llvm::object::ELFFile::Elf_Word Elf_Word; public: @@ -358,7 +351,7 @@ // Outputs GNU Hash section. For detailed explanation see: // https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections template -class GnuHashTableSection final : public OutputSectionBase { +class GnuHashTableSection final : public SegmentBase { typedef typename llvm::object::ELFFile::Elf_Off Elf_Off; typedef typename llvm::object::ELFFile::Elf_Word Elf_Word; typedef typename llvm::object::ELFFile::uintX_t uintX_t; @@ -392,9 +385,8 @@ unsigned Shift2; }; -template -class DynamicSection final : public OutputSectionBase { - typedef OutputSectionBase Base; +template class DynamicSection final : public SegmentBase { + typedef SegmentBase Base; typedef typename llvm::object::ELFFile::Elf_Dyn Elf_Dyn; typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; @@ -406,9 +398,9 @@ void finalize() override; void writeTo(uint8_t *Buf) override; - OutputSectionBase *PreInitArraySec = nullptr; - OutputSectionBase *InitArraySec = nullptr; - OutputSectionBase *FiniArraySec = nullptr; + SegmentBase *PreInitArraySec = nullptr; + SegmentBase *InitArraySec = nullptr; + SegmentBase *FiniArraySec = nullptr; private: SymbolTable &SymTab; @@ -419,11 +411,11 @@ }; template -class MipsReginfoOutputSection final : public OutputSectionBase { +class MipsReginfoSegment final : public SegmentBase { typedef llvm::object::Elf_Mips_RegInfo Elf_Mips_RegInfo; public: - MipsReginfoOutputSection(); + MipsReginfoSegment(); void writeTo(uint8_t *Buf) override; void addSection(MipsReginfoInputSection *S); @@ -444,9 +436,9 @@ static GotSection *Got; static HashTableSection *HashTab; static InterpSection *Interp; - static OutputSection *Bss; - static OutputSection *MipsRldMap; - static OutputSectionBase *Opd; + static Segment *Bss; + static Segment *MipsRldMap; + static SegmentBase *Opd; static uint8_t *OpdBuf; static PltSection *Plt; static RelocationSection *RelaDyn; @@ -465,9 +457,9 @@ template GotSection *Out::Got; template HashTableSection *Out::HashTab; template InterpSection *Out::Interp; -template OutputSection *Out::Bss; -template OutputSection *Out::MipsRldMap; -template OutputSectionBase *Out::Opd; +template Segment *Out::Bss; +template Segment *Out::MipsRldMap; +template SegmentBase *Out::Opd; template uint8_t *Out::OpdBuf; template PltSection *Out::Plt; template RelocationSection *Out::RelaDyn; Index: ELF/Segments.cpp =================================================================== --- ELF/Segments.cpp +++ ELF/Segments.cpp @@ -1,4 +1,4 @@ -//===- OutputSections.cpp -------------------------------------------------===// +//===- Segments.cpp -------------------------------------------------===// // // The LLVM Linker // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "OutputSections.h" +#include "Segments.h" #include "Config.h" #include "SymbolTable.h" #include "Target.h" @@ -24,8 +24,8 @@ bool lld::elf2::HasGotOffRel = false; template -OutputSectionBase::OutputSectionBase(StringRef Name, uint32_t sh_type, - uintX_t sh_flags) +SegmentBase::SegmentBase(StringRef Name, uint32_t sh_type, + uintX_t sh_flags) : Name(Name) { memset(&Header, 0, sizeof(Elf_Shdr)); Header.sh_type = sh_type; @@ -34,8 +34,8 @@ template GotPltSection::GotPltSection() - : OutputSectionBase(".got.plt", llvm::ELF::SHT_PROGBITS, - llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { + : SegmentBase(".got.plt", llvm::ELF::SHT_PROGBITS, + llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { this->Header.sh_addralign = sizeof(uintX_t); } @@ -70,8 +70,8 @@ template GotSection::GotSection() - : OutputSectionBase(".got", llvm::ELF::SHT_PROGBITS, - llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { + : SegmentBase(".got", llvm::ELF::SHT_PROGBITS, + llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE) { if (Config->EMachine == EM_MIPS) this->Header.sh_flags |= llvm::ELF::SHF_MIPS_GPREL; this->Header.sh_addralign = sizeof(uintX_t); @@ -151,8 +151,8 @@ template PltSection::PltSection() - : OutputSectionBase(".plt", llvm::ELF::SHT_PROGBITS, - llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR) { + : SegmentBase(".plt", llvm::ELF::SHT_PROGBITS, + llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR) { this->Header.sh_addralign = 16; } @@ -199,9 +199,8 @@ template RelocationSection::RelocationSection(StringRef Name, bool IsRela) - : OutputSectionBase(Name, - IsRela ? llvm::ELF::SHT_RELA : llvm::ELF::SHT_REL, - llvm::ELF::SHF_ALLOC), + : SegmentBase(Name, IsRela ? llvm::ELF::SHT_RELA : llvm::ELF::SHT_REL, + llvm::ELF::SHF_ALLOC), IsRela(IsRela) { this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; @@ -223,8 +222,8 @@ return false; if (Target->isTlsOptimized(Type, Body)) { - P->setSymbolAndType(Body->DynamicSymbolTableIndex, - Target->getTlsGotReloc(), Config->Mips64EL); + P->setSymbolAndType(Body->DynamicSymbolTableIndex, Target->getTlsGotReloc(), + Config->Mips64EL); P->r_offset = Out::Got->getEntryAddr(*Body); return true; } @@ -292,7 +291,7 @@ P->r_offset = Out::Bss->getVA() + dyn_cast>(Body)->OffsetInBSS; } else { - P->r_offset = C.getOffset(RI.r_offset) + C.OutSec->getVA(); + P->r_offset = C.getOffset(RI.r_offset) + C.Segm->getVA(); } uintX_t OrigAddend = 0; @@ -331,14 +330,13 @@ template InterpSection::InterpSection() - : OutputSectionBase(".interp", llvm::ELF::SHT_PROGBITS, - llvm::ELF::SHF_ALLOC) { + : SegmentBase(".interp", llvm::ELF::SHT_PROGBITS, + llvm::ELF::SHF_ALLOC) { this->Header.sh_size = Config->DynamicLinker.size() + 1; this->Header.sh_addralign = 1; } -template -void OutputSectionBase::writeHeaderTo(Elf_Shdr *SHdr) { +template void SegmentBase::writeHeaderTo(Elf_Shdr *SHdr) { Header.sh_name = Out::ShStrTab->getOffset(Name); *SHdr = Header; } @@ -349,8 +347,7 @@ template HashTableSection::HashTableSection() - : OutputSectionBase(".hash", llvm::ELF::SHT_HASH, - llvm::ELF::SHF_ALLOC) { + : SegmentBase(".hash", llvm::ELF::SHT_HASH, llvm::ELF::SHF_ALLOC) { this->Header.sh_entsize = sizeof(Elf_Word); this->Header.sh_addralign = sizeof(Elf_Word); } @@ -370,7 +367,7 @@ template void HashTableSection::finalize() { this->Header.sh_link = Out::DynSymTab->SectionIndex; - unsigned NumEntries = 2; // nbucket and nchain. + unsigned NumEntries = 2; // nbucket and nchain. NumEntries += Out::DynSymTab->getNumSymbols(); // The chain entries. // Create as many buckets as there are symbols. @@ -407,8 +404,8 @@ template GnuHashTableSection::GnuHashTableSection() - : OutputSectionBase(".gnu.hash", llvm::ELF::SHT_GNU_HASH, - llvm::ELF::SHF_ALLOC) { + : SegmentBase(".gnu.hash", llvm::ELF::SHT_GNU_HASH, + llvm::ELF::SHF_ALLOC) { this->Header.sh_entsize = ELFT::Is64Bits ? 0 : 4; this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; } @@ -548,8 +545,8 @@ template DynamicSection::DynamicSection(SymbolTable &SymTab) - : OutputSectionBase(".dynamic", llvm::ELF::SHT_DYNAMIC, - llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE), + : SegmentBase(".dynamic", llvm::ELF::SHT_DYNAMIC, + llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE), SymTab(SymTab) { Elf_Shdr &Header = this->Header; Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; @@ -717,8 +714,7 @@ if (!Config->SoName.empty()) WriteVal(DT_SONAME, Out::DynStrTab->getOffset(Config->SoName)); - auto WriteArray = [&](int32_t T1, int32_t T2, - const OutputSectionBase *Sec) { + auto WriteArray = [&](int32_t T1, int32_t T2, const SegmentBase *Sec) { if (!Sec) return; WritePtr(T1, Sec->getVA()); @@ -763,21 +759,19 @@ } template -OutputSection::OutputSection(StringRef Name, uint32_t sh_type, - uintX_t sh_flags) - : OutputSectionBase(Name, sh_type, sh_flags) {} +Segment::Segment(StringRef Name, uint32_t sh_type, uintX_t sh_flags) + : SegmentBase(Name, sh_type, sh_flags) {} -template -void OutputSection::addSection(InputSection *C) { +template void Segment::addSection(InputSection *C) { Sections.push_back(C); - C->OutSec = this; + C->Segm = this; uint32_t Align = C->getAlign(); if (Align > this->Header.sh_addralign) this->Header.sh_addralign = Align; uintX_t Off = this->Header.sh_size; Off = RoundUpToAlignment(Off, Align); - C->OutSecOff = Off; + C->SegmOff = Off; Off += C->getSize(); this->Header.sh_size = Off; } @@ -787,7 +781,7 @@ switch (S.kind()) { case SymbolBody::DefinedSyntheticKind: { auto &D = cast>(S); - return D.Section.getVA() + D.Value; + return D.Segm.getVA() + D.Value; } case SymbolBody::DefinedAbsoluteKind: return cast>(S).Sym.st_value; @@ -795,9 +789,9 @@ const auto &DR = cast>(S); InputSectionBase &SC = DR.Section; if (DR.Sym.getType() == STT_TLS) - return SC.OutSec->getVA() + SC.getOffset(DR.Sym) - + return SC.Segm->getVA() + SC.getOffset(DR.Sym) - Out::TlsPhdr->p_vaddr; - return SC.OutSec->getVA() + SC.getOffset(DR.Sym); + return SC.Segm->getVA() + SC.getOffset(DR.Sym); } case SymbolBody::DefinedCommonKind: return Out::Bss->getVA() + cast>(S).OffsetInBSS; @@ -841,7 +835,7 @@ InputSectionBase *Section = File.getSection(*Sym); if (Sym->getType() == STT_TLS) - return (Section->OutSec->getVA() + Section->getOffset(*Sym) + Addend) - + return (Section->Segm->getVA() + Section->getOffset(*Sym) + Addend) - Out::TlsPhdr->p_vaddr; // According to the ELF spec reference to a local symbol from outside @@ -851,7 +845,7 @@ if (Section == &InputSection::Discarded || !Section->isLive()) return Addend; - uintX_t VA = Section->OutSec->getVA(); + uintX_t VA = Section->Segm->getVA(); if (isa>(Section)) return VA + Section->getOffset(*Sym) + Addend; @@ -868,7 +862,7 @@ // with the same name defined in other ELF executable or DSO. bool lld::elf2::canBePreempted(const SymbolBody *Body, bool NeedsGot) { if (!Body) - return false; // Body is a local symbol. + return false; // Body is a local symbol. if (Body->isShared()) return true; @@ -902,15 +896,14 @@ return Body->getVisibility() == STV_DEFAULT; } -template void OutputSection::writeTo(uint8_t *Buf) { +template void Segment::writeTo(uint8_t *Buf) { for (InputSection *C : Sections) C->writeTo(Buf); } template -EHOutputSection::EHOutputSection(StringRef Name, uint32_t sh_type, - uintX_t sh_flags) - : OutputSectionBase(Name, sh_type, sh_flags) {} +EHSegment::EHSegment(StringRef Name, uint32_t sh_type, uintX_t sh_flags) + : SegmentBase(Name, sh_type, sh_flags) {} template EHRegion::EHRegion(EHInputSection *S, unsigned Index) @@ -931,12 +924,12 @@ template template -void EHOutputSection::addSectionAux( +void EHSegment::addSectionAux( EHInputSection *S, iterator_range *> Rels) { const endianness E = ELFT::TargetEndianness; - S->OutSec = this; + S->Segm = this; uint32_t Align = S->getAlign(); if (Align > this->Header.sh_addralign) this->Header.sh_addralign = Align; @@ -1001,8 +994,8 @@ } template -typename EHOutputSection::uintX_t -EHOutputSection::readEntryLength(ArrayRef D) { +typename EHSegment::uintX_t +EHSegment::readEntryLength(ArrayRef D) { const endianness E = ELFT::TargetEndianness; if (D.size() < 4) @@ -1027,7 +1020,7 @@ } template -void EHOutputSection::addSection(EHInputSection *S) { +void EHSegment::addSection(EHInputSection *S) { const Elf_Shdr *RelSec = S->RelocSection; if (!RelSec) return addSectionAux( @@ -1038,7 +1031,7 @@ return addSectionAux(S, Obj.rels(RelSec)); } -template void EHOutputSection::writeTo(uint8_t *Buf) { +template void EHSegment::writeTo(uint8_t *Buf) { const endianness E = ELFT::TargetEndianness; size_t Offset = 0; for (const Cie &C : Cies) { @@ -1073,11 +1066,11 @@ } template -MergeOutputSection::MergeOutputSection(StringRef Name, uint32_t sh_type, - uintX_t sh_flags) - : OutputSectionBase(Name, sh_type, sh_flags) {} +MergeSegment::MergeSegment(StringRef Name, uint32_t sh_type, + uintX_t sh_flags) + : SegmentBase(Name, sh_type, sh_flags) {} -template void MergeOutputSection::writeTo(uint8_t *Buf) { +template void MergeSegment::writeTo(uint8_t *Buf) { if (shouldTailMerge()) { StringRef Data = Builder.data(); memcpy(Buf, Data.data(), Data.size()); @@ -1103,8 +1096,8 @@ } template -void MergeOutputSection::addSection(MergeInputSection *S) { - S->OutSec = this; +void MergeSegment::addSection(MergeInputSection *S) { + S->Segm = this; uint32_t Align = S->getAlign(); if (Align > this->Header.sh_addralign) this->Header.sh_addralign = Align; @@ -1138,16 +1131,15 @@ } } -template -unsigned MergeOutputSection::getOffset(StringRef Val) { +template unsigned MergeSegment::getOffset(StringRef Val) { return Builder.getOffset(Val); } -template bool MergeOutputSection::shouldTailMerge() const { +template bool MergeSegment::shouldTailMerge() const { return Config->Optimize >= 2 && this->Header.sh_flags & SHF_STRINGS; } -template void MergeOutputSection::finalize() { +template void MergeSegment::finalize() { if (shouldTailMerge()) Builder.finalize(); this->Header.sh_size = Builder.getSize(); @@ -1155,8 +1147,8 @@ template StringTableSection::StringTableSection(StringRef Name, bool Dynamic) - : OutputSectionBase(Name, llvm::ELF::SHT_STRTAB, - Dynamic ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), + : SegmentBase(Name, llvm::ELF::SHT_STRTAB, + Dynamic ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), Dynamic(Dynamic) { this->Header.sh_addralign = 1; } @@ -1208,12 +1200,12 @@ template SymbolTableSection::SymbolTableSection( SymbolTable &Table, StringTableSection &StrTabSec) - : OutputSectionBase( + : SegmentBase( StrTabSec.isDynamic() ? ".dynsym" : ".symtab", StrTabSec.isDynamic() ? llvm::ELF::SHT_DYNSYM : llvm::ELF::SHT_SYMTAB, StrTabSec.isDynamic() ? (uintX_t)llvm::ELF::SHF_ALLOC : 0), Table(Table), StrTabSec(StrTabSec) { - typedef OutputSectionBase Base; + typedef SegmentBase Base; typename Base::Elf_Shdr &Header = this->Header; Header.sh_entsize = sizeof(Elf_Sym); @@ -1304,9 +1296,9 @@ InputSectionBase *Section = File->getSection(Sym); if (!Section->isLive()) continue; - const OutputSectionBase *OutSec = Section->OutSec; - ESym->st_shndx = OutSec->SectionIndex; - VA += OutSec->getVA() + Section->getOffset(Sym); + const SegmentBase *Segm = Section->Segm; + ESym->st_shndx = Segm->SectionIndex; + VA += Segm->getVA() + Section->getOffset(Sym); } ESym->st_name = StrTabSec.getOffset(SymName); ESym->st_size = Sym.st_size; @@ -1333,25 +1325,25 @@ // pointed by Buf. auto *ESym = reinterpret_cast(Buf); for (SymbolBody *Body : Symbols) { - const OutputSectionBase *OutSec = nullptr; + const SegmentBase *Segm = nullptr; switch (Body->kind()) { case SymbolBody::DefinedSyntheticKind: - OutSec = &cast>(Body)->Section; + Segm = &cast>(Body)->Segm; break; case SymbolBody::DefinedRegularKind: { auto *Sym = cast>(Body->repl()); if (!Sym->Section.isLive()) continue; - OutSec = Sym->Section.OutSec; + Segm = Sym->Section.Segm; break; } case SymbolBody::DefinedCommonKind: - OutSec = Out::Bss; + Segm = Out::Bss; break; case SymbolBody::SharedKind: { if (cast>(Body)->NeedsCopy) - OutSec = Out::Bss; + Segm = Out::Bss; break; } case SymbolBody::UndefinedElfKind: @@ -1378,8 +1370,8 @@ if (isa>(Body)) ESym->st_shndx = SHN_ABS; - else if (OutSec) - ESym->st_shndx = OutSec->SectionIndex; + else if (Segm) + ESym->st_shndx = Segm->SectionIndex; ++ESym; } @@ -1398,32 +1390,30 @@ } template -MipsReginfoOutputSection::MipsReginfoOutputSection() - : OutputSectionBase(".reginfo", SHT_MIPS_REGINFO, SHF_ALLOC) { +MipsReginfoSegment::MipsReginfoSegment() + : SegmentBase(".reginfo", SHT_MIPS_REGINFO, SHF_ALLOC) { this->Header.sh_addralign = 4; this->Header.sh_entsize = sizeof(Elf_Mips_RegInfo); this->Header.sh_size = sizeof(Elf_Mips_RegInfo); } -template -void MipsReginfoOutputSection::writeTo(uint8_t *Buf) { +template void MipsReginfoSegment::writeTo(uint8_t *Buf) { auto *R = reinterpret_cast(Buf); R->ri_gp_value = getMipsGpAddr(); R->ri_gprmask = GeneralMask; } template -void MipsReginfoOutputSection::addSection( - MipsReginfoInputSection *S) { +void MipsReginfoSegment::addSection(MipsReginfoInputSection *S) { GeneralMask |= S->getGeneralMask(); } namespace lld { namespace elf2 { -template class OutputSectionBase; -template class OutputSectionBase; -template class OutputSectionBase; -template class OutputSectionBase; +template class SegmentBase; +template class SegmentBase; +template class SegmentBase; +template class SegmentBase; template class GotPltSection; template class GotPltSection; @@ -1465,25 +1455,25 @@ template class DynamicSection; template class DynamicSection; -template class OutputSection; -template class OutputSection; -template class OutputSection; -template class OutputSection; - -template class EHOutputSection; -template class EHOutputSection; -template class EHOutputSection; -template class EHOutputSection; - -template class MipsReginfoOutputSection; -template class MipsReginfoOutputSection; -template class MipsReginfoOutputSection; -template class MipsReginfoOutputSection; - -template class MergeOutputSection; -template class MergeOutputSection; -template class MergeOutputSection; -template class MergeOutputSection; +template class Segment; +template class Segment; +template class Segment; +template class Segment; + +template class EHSegment; +template class EHSegment; +template class EHSegment; +template class EHSegment; + +template class MipsReginfoSegment; +template class MipsReginfoSegment; +template class MipsReginfoSegment; +template class MipsReginfoSegment; + +template class MergeSegment; +template class MergeSegment; +template class MergeSegment; +template class MergeSegment; template class StringTableSection; template class StringTableSection; Index: ELF/SymbolTable.h =================================================================== --- ELF/SymbolTable.h +++ ELF/SymbolTable.h @@ -16,7 +16,7 @@ namespace lld { namespace elf2 { class Lazy; -template class OutputSectionBase; +template class SegmentBase; struct Symbol; class Undefined; @@ -52,7 +52,7 @@ SymbolBody *addUndefinedOpt(StringRef Name); void addAbsolute(StringRef Name, typename llvm::object::ELFFile::Elf_Sym &ESym); - void addSynthetic(StringRef Name, OutputSectionBase &Section, + void addSynthetic(StringRef Name, SegmentBase &Segm, typename llvm::object::ELFFile::uintX_t Value); SymbolBody *addIgnored(StringRef Name); bool isUndefined(StringRef Name); Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -99,10 +99,9 @@ } template -void SymbolTable::addSynthetic(StringRef Name, - OutputSectionBase &Section, +void SymbolTable::addSynthetic(StringRef Name, SegmentBase &Segm, typename ELFFile::uintX_t Value) { - auto *Sym = new (Alloc) DefinedSynthetic(Name, Value, Section); + auto *Sym = new (Alloc) DefinedSynthetic(Name, Value, Segm); resolve(Sym); } Index: ELF/Symbols.h =================================================================== --- ELF/Symbols.h +++ ELF/Symbols.h @@ -36,8 +36,8 @@ class InputFile; class SymbolBody; template class ObjectFile; -template class OutputSection; -template class OutputSectionBase; +template class Segment; +template class SegmentBase; template class SharedFile; // Initializes global objects defined in this file. @@ -246,15 +246,14 @@ public: typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; typedef typename llvm::object::ELFFile::uintX_t uintX_t; - DefinedSynthetic(StringRef N, uintX_t Value, - OutputSectionBase &Section); + DefinedSynthetic(StringRef N, uintX_t Value, SegmentBase &Segm); static bool classof(const SymbolBody *S) { return S->kind() == SymbolBody::DefinedSyntheticKind; } uintX_t Value; - const OutputSectionBase &Section; + const SegmentBase &Segm; }; // Undefined symbol. Index: ELF/Symbols.cpp =================================================================== --- ELF/Symbols.cpp +++ ELF/Symbols.cpp @@ -97,9 +97,9 @@ template DefinedSynthetic::DefinedSynthetic(StringRef N, uintX_t Value, - OutputSectionBase &Section) + SegmentBase &Segm) : Defined(SymbolBody::DefinedSyntheticKind, N, false, STV_DEFAULT, false), - Value(Value), Section(Section) {} + Value(Value), Segm(Segm) {} std::unique_ptr Lazy::getMember() { MemoryBufferRef MBRef = File->getMember(&Sym); Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -17,7 +17,7 @@ #include "Target.h" #include "Error.h" -#include "OutputSections.h" +#include "Segments.h" #include "Symbols.h" #include "llvm/ADT/ArrayRef.h" Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -9,7 +9,7 @@ #include "Writer.h" #include "Config.h" -#include "OutputSections.h" +#include "Segments.h" #include "SymbolTable.h" #include "Target.h" @@ -55,7 +55,7 @@ void writeHeader(); void writeSections(); bool isDiscarded(InputSectionBase *IS) const; - StringRef getOutputSectionName(StringRef S) const; + StringRef getSegmentName(StringRef S) const; bool needsInterpSection() const { return !Symtab.getSharedFiles().empty() && !Config->DynamicLinker.empty(); } @@ -65,24 +65,24 @@ uintX_t getEntryAddr() const; int getPhdrsNum() const; - OutputSection *getBSS(); + Segment *getBSS(); void addCommonSymbols(std::vector *> &Syms); void addSharedCopySymbols(std::vector *> &Syms); std::unique_ptr Buffer; - SpecificBumpPtrAllocator> SecAlloc; - SpecificBumpPtrAllocator> MSecAlloc; - SpecificBumpPtrAllocator> EHSecAlloc; - SpecificBumpPtrAllocator> MReginfoSecAlloc; + SpecificBumpPtrAllocator> SegAlloc; + SpecificBumpPtrAllocator> MSegAlloc; + SpecificBumpPtrAllocator> EHSegAlloc; + SpecificBumpPtrAllocator> MReginfoSegAlloc; BumpPtrAllocator Alloc; - std::vector *> OutputSections; - unsigned getNumSections() const { return OutputSections.size() + 1; } + std::vector *> Segments; + unsigned getNumSegments() const { return Segments.size() + 1; } - void addStartStopSymbols(OutputSectionBase *Sec); + void addStartStopSymbols(SegmentBase *Sec); void setPhdr(Elf_Phdr *PH, uint32_t Type, uint32_t Flags, uintX_t FileOff, uintX_t VA, uintX_t Size, uintX_t Align); - void copyPhdr(Elf_Phdr *PH, OutputSectionBase *From); + void copyPhdr(Elf_Phdr *PH, SegmentBase *From); bool HasRelro = false; SymbolTable &Symtab; @@ -91,7 +91,7 @@ uintX_t FileSize; uintX_t SectionHeaderOff; - llvm::StringMap InputToOutputSection; + llvm::StringMap InputToSegment; }; } // anonymous namespace @@ -371,8 +371,8 @@ .Default(1); } -template static bool isRelroSection(OutputSectionBase *Sec) { - typename OutputSectionBase::uintX_t Flags = Sec->getFlags(); +template static bool isRelroSection(SegmentBase *Sec) { + typename SegmentBase::uintX_t Flags = Sec->getFlags(); if (!(Flags & SHF_ALLOC) || !(Flags & SHF_WRITE)) return false; if (Flags & SHF_TLS) @@ -392,8 +392,7 @@ // Output section ordering is determined by this function. template -static bool compareOutputSections(OutputSectionBase *A, - OutputSectionBase *B) { +static bool compareSegments(SegmentBase *A, SegmentBase *B) { typedef typename ELFFile::uintX_t uintX_t; uintX_t AFlags = A->getFlags(); @@ -461,11 +460,11 @@ return false; } -template OutputSection *Writer::getBSS() { +template Segment *Writer::getBSS() { if (!Out::Bss) { - Out::Bss = new (SecAlloc.Allocate()) - OutputSection(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); - OutputSections.push_back(Out::Bss); + Out::Bss = new (SegAlloc.Allocate()) + Segment(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); + Segments.push_back(Out::Bss); } return Out::Bss; } @@ -527,9 +526,9 @@ } template -StringRef Writer::getOutputSectionName(StringRef S) const { - auto It = InputToOutputSection.find(S); - if (It != std::end(InputToOutputSection)) +StringRef Writer::getSegmentName(StringRef S) const { + auto It = InputToSegment.find(S); + if (It != std::end(InputToSegment)) return It->second; if (S.startswith(".text.")) @@ -558,19 +557,18 @@ bool Writer::isDiscarded(InputSectionBase *IS) const { if (!IS || !IS->isLive() || IS == &InputSection::Discarded) return true; - return InputToOutputSection.lookup(IS->getSectionName()) == "/DISCARD/"; + return InputToSegment.lookup(IS->getSectionName()) == "/DISCARD/"; } template -static bool compareSections(OutputSectionBase *A, - OutputSectionBase *B) { - auto ItA = Config->OutputSections.find(A->getName()); - auto ItEnd = std::end(Config->OutputSections); +static bool compareSections(SegmentBase *A, SegmentBase *B) { + auto ItA = Config->Segments.find(A->getName()); + auto ItEnd = std::end(Config->Segments); if (ItA == ItEnd) - return compareOutputSections(A, B); - auto ItB = Config->OutputSections.find(B->getName()); + return compareSegments(A, B); + auto ItB = Config->Segments.find(B->getName()); if (ItB == ItEnd) - return compareOutputSections(A, B); + return compareSegments(A, B); return std::distance(ItA, ItB) > 0; } @@ -608,15 +606,15 @@ return true; } -// Create output section objects and add them to OutputSections. +// Create output section objects and add them to Segments. template void Writer::createSections() { // .interp needs to be on the first page in the output file. if (needsInterpSection()) - OutputSections.push_back(Out::Interp); + Segments.push_back(Out::Interp); - SmallDenseMap, OutputSectionBase *> Map; + SmallDenseMap, SegmentBase *> Map; - std::vector *> RegularSections; + std::vector *> RegularSegments; for (const std::unique_ptr> &F : Symtab.getObjectFiles()) { for (InputSectionBase *C : F->getSections()) { @@ -635,53 +633,52 @@ if (OutType == SHT_PROGBITS && C->getSectionName() == ".eh_frame" && Config->EMachine == EM_X86_64) OutType = SHT_X86_64_UNWIND; - SectionKey Key{getOutputSectionName(C->getSectionName()), + SectionKey Key{getSegmentName(C->getSectionName()), OutType, OutFlags, EntSize}; - OutputSectionBase *&Sec = Map[Key]; + SegmentBase *&Sec = Map[Key]; if (!Sec) { switch (K) { case InputSectionBase::Regular: - Sec = new (SecAlloc.Allocate()) - OutputSection(Key.Name, Key.Type, Key.Flags); + Sec = new (SegAlloc.Allocate()) + Segment(Key.Name, Key.Type, Key.Flags); break; case InputSectionBase::EHFrame: - Sec = new (EHSecAlloc.Allocate()) - EHOutputSection(Key.Name, Key.Type, Key.Flags); + Sec = new (EHSegAlloc.Allocate()) + EHSegment(Key.Name, Key.Type, Key.Flags); break; case InputSectionBase::Merge: - Sec = new (MSecAlloc.Allocate()) - MergeOutputSection(Key.Name, Key.Type, Key.Flags); + Sec = new (MSegAlloc.Allocate()) + MergeSegment(Key.Name, Key.Type, Key.Flags); break; case InputSectionBase::MipsReginfo: - Sec = new (MReginfoSecAlloc.Allocate()) - MipsReginfoOutputSection(); + Sec = new (MReginfoSegAlloc.Allocate()) MipsReginfoSegment(); break; } - OutputSections.push_back(Sec); - RegularSections.push_back(Sec); + Segments.push_back(Sec); + RegularSegments.push_back(Sec); } switch (K) { case InputSectionBase::Regular: - static_cast *>(Sec) - ->addSection(cast>(C)); + static_cast *>(Sec)->addSection( + cast>(C)); break; case InputSectionBase::EHFrame: - static_cast *>(Sec) - ->addSection(cast>(C)); + static_cast *>(Sec)->addSection( + cast>(C)); break; case InputSectionBase::Merge: - static_cast *>(Sec) - ->addSection(cast>(C)); + static_cast *>(Sec)->addSection( + cast>(C)); break; case InputSectionBase::MipsReginfo: - static_cast *>(Sec) - ->addSection(cast>(C)); + static_cast *>(Sec)->addSection( + cast>(C)); break; } } } - Out::Bss = static_cast *>( + Out::Bss = static_cast *>( Map[{".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE, 0}]); Out::Dynamic->PreInitArraySec = Map.lookup( @@ -692,7 +689,7 @@ Map.lookup({".fini_array", SHT_FINI_ARRAY, SHF_WRITE | SHF_ALLOC, 0}); auto AddStartEnd = [&](StringRef Start, StringRef End, - OutputSectionBase *OS) { + SegmentBase *OS) { if (OS) { Symtab.addSynthetic(Start, *OS, 0); Symtab.addSynthetic(End, *OS, OS->getSize()); @@ -709,8 +706,8 @@ AddStartEnd("__fini_array_start", "__fini_array_end", Out::Dynamic->FiniArraySec); - for (OutputSectionBase *Sec : RegularSections) - addStartStopSymbols(Sec); + for (SegmentBase *Seg : RegularSegments) + addStartStopSymbols(Seg); // __tls_get_addr is defined by the dynamic linker for dynamic ELFs. For // static linking the linker is required to optimize away any references to @@ -780,37 +777,37 @@ // This order is not the same as the final output order // because we sort the sections using their attributes below. if (Out::SymTab) - OutputSections.push_back(Out::SymTab); - OutputSections.push_back(Out::ShStrTab); + Segments.push_back(Out::SymTab); + Segments.push_back(Out::ShStrTab); if (Out::StrTab) - OutputSections.push_back(Out::StrTab); + Segments.push_back(Out::StrTab); if (isOutputDynamic()) { - OutputSections.push_back(Out::DynSymTab); + Segments.push_back(Out::DynSymTab); if (Out::GnuHashTab) - OutputSections.push_back(Out::GnuHashTab); + Segments.push_back(Out::GnuHashTab); if (Out::HashTab) - OutputSections.push_back(Out::HashTab); - OutputSections.push_back(Out::Dynamic); - OutputSections.push_back(Out::DynStrTab); + Segments.push_back(Out::HashTab); + Segments.push_back(Out::Dynamic); + Segments.push_back(Out::DynStrTab); if (Out::RelaDyn->hasRelocs()) - OutputSections.push_back(Out::RelaDyn); + Segments.push_back(Out::RelaDyn); // This is a MIPS specific section to hold a space within the data segment // of executable file which is pointed to by the DT_MIPS_RLD_MAP entry. // See "Dynamic section" in Chapter 5 in the following document: // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf if (Config->EMachine == EM_MIPS && !Config->Shared) { - Out::MipsRldMap = new (SecAlloc.Allocate()) - OutputSection(".rld_map", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); + Out::MipsRldMap = new (SegAlloc.Allocate()) + Segment(".rld_map", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); Out::MipsRldMap->setSize(ELFT::Is64Bits ? 8 : 4); Out::MipsRldMap->updateAlign(ELFT::Is64Bits ? 8 : 4); - OutputSections.push_back(Out::MipsRldMap); + Segments.push_back(Out::MipsRldMap); } } // We always need to add rel[a].plt to output if it has entries. // Even during static linking it can contain R_[*]_IRELATIVE relocations. if (Out::RelaPlt && Out::RelaPlt->hasRelocs()) { - OutputSections.push_back(Out::RelaPlt); + Segments.push_back(Out::RelaPlt); Out::RelaPlt->Static = !isOutputDynamic(); } @@ -825,21 +822,20 @@ needsGot = true; if (needsGot) - OutputSections.push_back(Out::Got); + Segments.push_back(Out::Got); if (Out::GotPlt && !Out::GotPlt->empty()) - OutputSections.push_back(Out::GotPlt); + Segments.push_back(Out::GotPlt); if (!Out::Plt->empty()) - OutputSections.push_back(Out::Plt); + Segments.push_back(Out::Plt); - std::stable_sort(OutputSections.begin(), OutputSections.end(), - compareSections); + std::stable_sort(Segments.begin(), Segments.end(), compareSections); - for (unsigned I = 0, N = OutputSections.size(); I < N; ++I) { - OutputSections[I]->SectionIndex = I + 1; - HasRelro |= (Config->ZRelro && isRelroSection(OutputSections[I])); + for (unsigned I = 0, N = Segments.size(); I < N; ++I) { + Segments[I]->SectionIndex = I + 1; + HasRelro |= (Config->ZRelro && isRelroSection(Segments[I])); } - for (OutputSectionBase *Sec : OutputSections) + for (SegmentBase *Sec : Segments) Out::ShStrTab->add(Sec->getName()); // Finalizers fix each section's size. @@ -851,7 +847,7 @@ Out::DynSymTab->finalize(); // Fill other section headers. - for (OutputSectionBase *Sec : OutputSections) + for (SegmentBase *Sec : Segments) Sec->finalize(); // If we have a .opd section (used under PPC64 for function descriptors), @@ -879,7 +875,7 @@ // respectively. This is not requested by the ELF standard, but GNU ld and // gold provide the feature, and used by many programs. template -void Writer::addStartStopSymbols(OutputSectionBase *Sec) { +void Writer::addStartStopSymbols(SegmentBase *Sec) { StringRef S = Sec->getName(); if (!isValidCIdentifier(S)) return; @@ -892,7 +888,7 @@ Symtab.addSynthetic(Stop, *Sec, Sec->getSize()); } -template static bool needsPhdr(OutputSectionBase *Sec) { +template static bool needsPhdr(SegmentBase *Sec) { return Sec->getFlags() & SHF_ALLOC; } @@ -946,7 +942,7 @@ bool RelroAligned = false; uintX_t ThreadBSSOffset = 0; // Create phdrs as we assign VAs and file offsets to all output sections. - for (OutputSectionBase *Sec : OutputSections) { + for (SegmentBase *Sec : Segments) { Elf_Phdr *PH = &Phdrs[PhdrIdx]; if (needsPhdr(Sec)) { uintX_t Flags = toPhdrFlags(Sec->getFlags()); @@ -1035,7 +1031,7 @@ // Add space for section headers. SectionHeaderOff = RoundUpToAlignment(FileOff, ELFT::Is64Bits ? 8 : 4); - FileSize = SectionHeaderOff + getNumSections() * sizeof(Elf_Shdr); + FileSize = SectionHeaderOff + getNumSegments() * sizeof(Elf_Shdr); // Update "_end" and "end" symbols so that they // point to the end of the data segment. @@ -1066,7 +1062,7 @@ if (!Config->ZExecStack) ++I; uintX_t Last = PF_R; - for (OutputSectionBase *Sec : OutputSections) { + for (SegmentBase *Sec : Segments) { if (!needsPhdr(Sec)) continue; if (Sec->getFlags() & SHF_TLS) @@ -1121,7 +1117,7 @@ EHdr->e_phentsize = sizeof(Elf_Phdr); EHdr->e_phnum = Phdrs.size(); EHdr->e_shentsize = sizeof(Elf_Shdr); - EHdr->e_shnum = getNumSections(); + EHdr->e_shnum = getNumSegments(); EHdr->e_shstrndx = Out::ShStrTab->SectionIndex; // Write the program header table. @@ -1129,7 +1125,7 @@ // Write the section header table. Note that the first table entry is null. auto SHdrs = reinterpret_cast(Buf + EHdr->e_shoff); - for (OutputSectionBase *Sec : OutputSections) + for (SegmentBase *Sec : Segments) Sec->writeHeaderTo(++SHdrs); } @@ -1146,12 +1142,12 @@ // PPC64 needs to process relocations in the .opd section before processing // relocations in code-containing sections. - if (OutputSectionBase *Sec = Out::Opd) { + if (SegmentBase *Sec = Out::Opd) { Out::OpdBuf = Buf + Sec->getFileOff(); Sec->writeTo(Buf + Sec->getFileOff()); } - for (OutputSectionBase *Sec : OutputSections) + for (SegmentBase *Sec : Segments) if (Sec != Out::Opd) Sec->writeTo(Buf + Sec->getFileOff()); } @@ -1183,7 +1179,7 @@ } template -void Writer::copyPhdr(Elf_Phdr *PH, OutputSectionBase *From) { +void Writer::copyPhdr(Elf_Phdr *PH, SegmentBase *From) { PH->p_flags = toPhdrFlags(From->getFlags()); PH->p_offset = From->getFileOff(); PH->p_vaddr = From->getVA(); @@ -1194,10 +1190,10 @@ } template void Writer::buildSectionMap() { - for (const std::pair> &OutSec : - Config->OutputSections) - for (StringRef Name : OutSec.second) - InputToOutputSection[Name] = OutSec.first; + for (const std::pair> &Segm : + Config->Segments) + for (StringRef Name : Segm.second) + InputToSegment[Name] = Segm.first; } template void lld::elf2::writeResult(SymbolTable *Symtab);