diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2016-11-09 01:42:41 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2016-11-09 01:42:41 +0000 |
| commit | 04a2e348bb946b8bf76637f95b65bd1a129808b8 (patch) | |
| tree | 2e97f12f82a01cdbde102592021e21fd7d8186d0 /lld/ELF/OutputSections.cpp | |
| parent | 7576cb0fa7ad0138ff2d5d12bb896aa42569b232 (diff) | |
| download | bcm5719-llvm-04a2e348bb946b8bf76637f95b65bd1a129808b8.tar.gz bcm5719-llvm-04a2e348bb946b8bf76637f95b65bd1a129808b8.zip | |
Split Header into individual fields.
This is similar to what was done for InputSection.
With this the various fields are stored in host order and only
converted to target order when writing.
llvm-svn: 286327
Diffstat (limited to 'lld/ELF/OutputSections.cpp')
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 223 |
1 files changed, 113 insertions, 110 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 9b08ef122f1..c8c622ca495 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -36,14 +36,12 @@ template <class ELFT> OutputSectionBase<ELFT>::OutputSectionBase(StringRef Name, uint32_t Type, uintX_t Flags) : Name(Name) { - memset(&Header, 0, sizeof(Elf_Shdr)); - Header.sh_type = Type; - Header.sh_flags = Flags; - Header.sh_addralign = 1; + this->Type = Type; + this->Flags = Flags; + this->Addralign = 1; } template <class ELFT> uint32_t OutputSectionBase<ELFT>::getPhdrFlags() const { - uintX_t Flags = getFlags(); uint32_t Ret = PF_R; if (Flags & SHF_WRITE) Ret |= PF_W; @@ -54,7 +52,16 @@ template <class ELFT> uint32_t OutputSectionBase<ELFT>::getPhdrFlags() const { template <class ELFT> void OutputSectionBase<ELFT>::writeHeaderTo(Elf_Shdr *Shdr) { - *Shdr = Header; + Shdr->sh_entsize = Entsize; + Shdr->sh_addralign = Addralign; + Shdr->sh_type = Type; + Shdr->sh_offset = Offset; + Shdr->sh_flags = Flags; + Shdr->sh_info = Info; + Shdr->sh_link = Link; + Shdr->sh_addr = Addr; + Shdr->sh_size = Size; + Shdr->sh_name = ShName; } template <class ELFT> @@ -81,7 +88,7 @@ template <class ELFT> void GdbIndexSection<ELFT>::finalize() { // GdbIndex header consist from version fields // and 5 more fields with different kinds of offsets. CuTypesOffset = CuListOffset + CompilationUnits.size() * CompilationUnitSize; - this->Header.sh_size = CuTypesOffset; + this->Size = CuTypesOffset; } template <class ELFT> void GdbIndexSection<ELFT>::writeTo(uint8_t *Buf) { @@ -104,7 +111,7 @@ template <class ELFT> void GdbIndexSection<ELFT>::writeTo(uint8_t *Buf) { template <class ELFT> GotPltSection<ELFT>::GotPltSection() : OutputSectionBase<ELFT>(".got.plt", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE) { - this->Header.sh_addralign = Target->GotPltEntrySize; + this->Addralign = Target->GotPltEntrySize; } template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody &Sym) { @@ -117,8 +124,8 @@ template <class ELFT> bool GotPltSection<ELFT>::empty() const { } template <class ELFT> void GotPltSection<ELFT>::finalize() { - this->Header.sh_size = (Target->GotPltHeaderEntriesNum + Entries.size()) * - Target->GotPltEntrySize; + this->Size = (Target->GotPltHeaderEntriesNum + Entries.size()) * + Target->GotPltEntrySize; } template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) { @@ -134,8 +141,8 @@ template <class ELFT> GotSection<ELFT>::GotSection() : OutputSectionBase<ELFT>(".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE) { if (Config->EMachine == EM_MIPS) - this->Header.sh_flags |= SHF_MIPS_GPREL; - this->Header.sh_addralign = Target->GotEntrySize; + this->Flags |= SHF_MIPS_GPREL; + this->Addralign = Target->GotEntrySize; } template <class ELFT> void GotSection<ELFT>::addEntry(SymbolBody &Sym) { @@ -281,7 +288,7 @@ typename GotSection<ELFT>::uintX_t GotSection<ELFT>::getMipsTlsOffset() const { template <class ELFT> typename GotSection<ELFT>::uintX_t GotSection<ELFT>::getGlobalDynAddr(const SymbolBody &B) const { - return this->getVA() + B.GlobalDynIndex * sizeof(uintX_t); + return this->Addr + B.GlobalDynIndex * sizeof(uintX_t); } template <class ELFT> @@ -312,11 +319,11 @@ template <class ELFT> void GotSection<ELFT>::finalize() { // page of the output section has at least one GOT relocation against it. // Add 0x8000 to the section's size because the page address stored // in the GOT entry is calculated as (value + 0x8000) & ~0xffff. - MipsPageEntries += (OutSec->getSize() + 0x8000 + 0xfffe) / 0xffff; + MipsPageEntries += (OutSec->Size + 0x8000 + 0xfffe) / 0xffff; } EntriesNum += getMipsLocalEntriesNum() + MipsGlobal.size(); } - this->Header.sh_size = EntriesNum * sizeof(uintX_t); + this->Size = EntriesNum * sizeof(uintX_t); } template <class ELFT> @@ -402,7 +409,7 @@ template <class ELFT> void GotSection<ELFT>::writeTo(uint8_t *Buf) { template <class ELFT> PltSection<ELFT>::PltSection() : OutputSectionBase<ELFT>(".plt", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR) { - this->Header.sh_addralign = 16; + this->Addralign = 16; } template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) { @@ -415,7 +422,7 @@ template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) { const SymbolBody *B = I.first; unsigned RelOff = I.second; uint64_t Got = B->getGotPltVA<ELFT>(); - uint64_t Plt = this->getVA() + Off; + uint64_t Plt = this->Addr + Off; Target->writePlt(Buf + Off, Got, Plt, B->PltIndex, RelOff); Off += Target->PltEntrySize; } @@ -428,8 +435,7 @@ template <class ELFT> void PltSection<ELFT>::addEntry(SymbolBody &Sym) { } template <class ELFT> void PltSection<ELFT>::finalize() { - this->Header.sh_size = - Target->PltHeaderSize + Entries.size() * Target->PltEntrySize; + this->Size = Target->PltHeaderSize + Entries.size() * Target->PltEntrySize; } template <class ELFT> @@ -437,8 +443,8 @@ RelocationSection<ELFT>::RelocationSection(StringRef Name, bool Sort) : OutputSectionBase<ELFT>(Name, Config->Rela ? SHT_RELA : SHT_REL, SHF_ALLOC), Sort(Sort) { - this->Header.sh_entsize = Config->Rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); - this->Header.sh_addralign = sizeof(uintX_t); + this->Entsize = Config->Rela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); + this->Addralign = sizeof(uintX_t); } template <class ELFT> @@ -487,25 +493,24 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) { } template <class ELFT> unsigned RelocationSection<ELFT>::getRelocOffset() { - return this->Header.sh_entsize * Relocs.size(); + return this->Entsize * Relocs.size(); } template <class ELFT> void RelocationSection<ELFT>::finalize() { - this->Header.sh_link = Out<ELFT>::DynSymTab - ? Out<ELFT>::DynSymTab->SectionIndex - : Out<ELFT>::SymTab->SectionIndex; - this->Header.sh_size = Relocs.size() * this->Header.sh_entsize; + this->Link = Out<ELFT>::DynSymTab ? Out<ELFT>::DynSymTab->SectionIndex + : Out<ELFT>::SymTab->SectionIndex; + this->Size = Relocs.size() * this->Entsize; } template <class ELFT> HashTableSection<ELFT>::HashTableSection() : OutputSectionBase<ELFT>(".hash", SHT_HASH, SHF_ALLOC) { - this->Header.sh_entsize = sizeof(Elf_Word); - this->Header.sh_addralign = sizeof(Elf_Word); + this->Entsize = sizeof(Elf_Word); + this->Addralign = sizeof(Elf_Word); } template <class ELFT> void HashTableSection<ELFT>::finalize() { - this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; + this->Link = Out<ELFT>::DynSymTab->SectionIndex; unsigned NumEntries = 2; // nbucket and nchain. NumEntries += Out<ELFT>::DynSymTab->getNumSymbols(); // The chain entries. @@ -514,7 +519,7 @@ template <class ELFT> void HashTableSection<ELFT>::finalize() { // FIXME: This is simplistic. We can try to optimize it, but implementing // support for SHT_GNU_HASH is probably even more profitable. NumEntries += Out<ELFT>::DynSymTab->getNumSymbols(); - this->Header.sh_size = NumEntries * sizeof(Elf_Word); + this->Size = NumEntries * sizeof(Elf_Word); } template <class ELFT> void HashTableSection<ELFT>::writeTo(uint8_t *Buf) { @@ -546,8 +551,8 @@ static uint32_t hashGnu(StringRef Name) { template <class ELFT> GnuHashTableSection<ELFT>::GnuHashTableSection() : OutputSectionBase<ELFT>(".gnu.hash", SHT_GNU_HASH, SHF_ALLOC) { - this->Header.sh_entsize = ELFT::Is64Bits ? 0 : 4; - this->Header.sh_addralign = sizeof(uintX_t); + this->Entsize = ELFT::Is64Bits ? 0 : 4; + this->Addralign = sizeof(uintX_t); } template <class ELFT> @@ -591,11 +596,11 @@ template <class ELFT> void GnuHashTableSection<ELFT>::finalize() { // Second hash shift estimation: just predefined values. Shift2 = ELFT::Is64Bits ? 6 : 5; - this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; - this->Header.sh_size = sizeof(Elf_Word) * 4 // Header - + sizeof(Elf_Off) * MaskWords // Bloom Filter - + sizeof(Elf_Word) * NBuckets // Hash Buckets - + sizeof(Elf_Word) * NumHashed; // Hash Values + this->Link = Out<ELFT>::DynSymTab->SectionIndex; + this->Size = sizeof(Elf_Word) * 4 // Header + + sizeof(Elf_Off) * MaskWords // Bloom Filter + + sizeof(Elf_Word) * NBuckets // Hash Buckets + + sizeof(Elf_Word) * NumHashed; // Hash Values } template <class ELFT> void GnuHashTableSection<ELFT>::writeTo(uint8_t *Buf) { @@ -691,15 +696,14 @@ static unsigned getVerDefNum() { return Config->VersionDefinitions.size() + 1; } template <class ELFT> DynamicSection<ELFT>::DynamicSection() : OutputSectionBase<ELFT>(".dynamic", SHT_DYNAMIC, SHF_ALLOC | SHF_WRITE) { - Elf_Shdr &Header = this->Header; - Header.sh_addralign = sizeof(uintX_t); - Header.sh_entsize = ELFT::Is64Bits ? 16 : 8; + this->Addralign = sizeof(uintX_t); + this->Entsize = ELFT::Is64Bits ? 16 : 8; // .dynamic section is not writable on MIPS. // See "Special Section" in Chapter 4 in the following document: // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf if (Config->EMachine == EM_MIPS) - Header.sh_flags = SHF_ALLOC; + this->Flags = SHF_ALLOC; addEntries(); } @@ -747,15 +751,15 @@ template <class ELFT> void DynamicSection<ELFT>::addEntries() { // Add remaining entries to complete .dynamic contents. template <class ELFT> void DynamicSection<ELFT>::finalize() { - if (this->Header.sh_size) + if (this->Size) return; // Already finalized. - this->Header.sh_link = Out<ELFT>::DynStrTab->SectionIndex; + this->Link = Out<ELFT>::DynStrTab->SectionIndex; if (Out<ELFT>::RelaDyn->hasRelocs()) { bool IsRela = Config->Rela; Add({IsRela ? DT_RELA : DT_REL, Out<ELFT>::RelaDyn}); - Add({IsRela ? DT_RELASZ : DT_RELSZ, Out<ELFT>::RelaDyn->getSize()}); + Add({IsRela ? DT_RELASZ : DT_RELSZ, Out<ELFT>::RelaDyn->Size}); Add({IsRela ? DT_RELAENT : DT_RELENT, uintX_t(IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel))}); @@ -770,7 +774,7 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() { } if (Out<ELFT>::RelaPlt && Out<ELFT>::RelaPlt->hasRelocs()) { Add({DT_JMPREL, Out<ELFT>::RelaPlt}); - Add({DT_PLTRELSZ, Out<ELFT>::RelaPlt->getSize()}); + Add({DT_PLTRELSZ, Out<ELFT>::RelaPlt->Size}); Add({Config->EMachine == EM_MIPS ? DT_MIPS_PLTGOT : DT_PLTGOT, Out<ELFT>::GotPlt}); Add({DT_PLTREL, uint64_t(Config->Rela ? DT_RELA : DT_REL)}); @@ -779,7 +783,7 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() { Add({DT_SYMTAB, Out<ELFT>::DynSymTab}); Add({DT_SYMENT, sizeof(Elf_Sym)}); Add({DT_STRTAB, Out<ELFT>::DynStrTab}); - Add({DT_STRSZ, Out<ELFT>::DynStrTab->getSize()}); + Add({DT_STRSZ, Out<ELFT>::DynStrTab->Size}); if (Out<ELFT>::GnuHashTab) Add({DT_GNU_HASH, Out<ELFT>::GnuHashTab}); if (Out<ELFT>::HashTab) @@ -831,7 +835,7 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() { } // +1 for DT_NULL - this->Header.sh_size = (Entries.size() + 1) * this->Header.sh_entsize; + this->Size = (Entries.size() + 1) * this->Entsize; } template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) { @@ -841,10 +845,10 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) { P->d_tag = E.Tag; switch (E.Kind) { case Entry::SecAddr: - P->d_un.d_ptr = E.OutSec->getVA(); + P->d_un.d_ptr = E.OutSec->Addr; break; case Entry::SecSize: - P->d_un.d_val = E.OutSec->getSize(); + P->d_un.d_val = E.OutSec->Size; break; case Entry::SymAddr: P->d_un.d_ptr = E.Sym->template getVA<ELFT>(); @@ -880,11 +884,11 @@ template <class ELFT> void EhFrameHeader<ELFT>::writeTo(uint8_t *Buf) { Buf[1] = DW_EH_PE_pcrel | DW_EH_PE_sdata4; Buf[2] = DW_EH_PE_udata4; Buf[3] = DW_EH_PE_datarel | DW_EH_PE_sdata4; - write32<E>(Buf + 4, Out<ELFT>::EhFrame->getVA() - this->getVA() - 4); + write32<E>(Buf + 4, Out<ELFT>::EhFrame->Addr - this->Addr - 4); write32<E>(Buf + 8, Fdes.size()); Buf += 12; - uintX_t VA = this->getVA(); + uintX_t VA = this->Addr; for (FdeData &Fde : Fdes) { write32<E>(Buf, Fde.Pc - VA); write32<E>(Buf + 4, Fde.FdeVA - VA); @@ -894,7 +898,7 @@ template <class ELFT> void EhFrameHeader<ELFT>::writeTo(uint8_t *Buf) { template <class ELFT> void EhFrameHeader<ELFT>::finalize() { // .eh_frame_hdr has a 12 bytes header followed by an array of FDEs. - this->Header.sh_size = 12 + Out<ELFT>::EhFrame->NumFdes * 8; + this->Size = 12 + Out<ELFT>::EhFrame->NumFdes * 8; } template <class ELFT> @@ -906,17 +910,17 @@ template <class ELFT> OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t Type, uintX_t Flags) : OutputSectionBase<ELFT>(Name, Type, Flags) { if (Type == SHT_RELA) - this->Header.sh_entsize = sizeof(Elf_Rela); + this->Entsize = sizeof(Elf_Rela); else if (Type == SHT_REL) - this->Header.sh_entsize = sizeof(Elf_Rel); + this->Entsize = sizeof(Elf_Rel); } template <class ELFT> void OutputSection<ELFT>::finalize() { - uint32_t Type = this->Header.sh_type; - if (this->Header.sh_flags & SHF_LINK_ORDER) { + uint32_t Type = this->Type; + if (this->Flags & SHF_LINK_ORDER) { if (!Config->Relocatable) { // SHF_LINK_ORDER only has meaning in relocatable objects - this->Header.sh_flags &= ~SHF_LINK_ORDER; + this->Flags &= ~SHF_LINK_ORDER; } else if (!this->Sections.empty()) { // When doing a relocatable link we must preserve the link order @@ -925,16 +929,16 @@ template <class ELFT> void OutputSection<ELFT>::finalize() { // InputSection sh_link to the OutputSection sh_link, all InputSections // in the OutputSection have the same dependency. if (auto *D = this->Sections.front()->getLinkOrderDep()) - this->Header.sh_link = D->OutSec->SectionIndex; + this->Link = D->OutSec->SectionIndex; } } if (Type != SHT_RELA && Type != SHT_REL) return; - this->Header.sh_link = Out<ELFT>::SymTab->SectionIndex; + this->Link = Out<ELFT>::SymTab->SectionIndex; // sh_info for SHT_REL[A] sections should contain the section header index of // the section to which the relocation applies. InputSectionBase<ELFT> *S = Sections[0]->getRelocatedSection(); - this->Header.sh_info = S->OutSec->SectionIndex; + this->Info = S->OutSec->SectionIndex; } template <class ELFT> @@ -947,19 +951,19 @@ void OutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) { // Keep sh_entsize value of the input section to be able to perform merging // later during a final linking using the generated relocatable object. if (Config->Relocatable && (S->Flags & SHF_MERGE)) - this->Header.sh_entsize = S->Entsize; + this->Entsize = S->Entsize; } // This function is called after we sort input sections // and scan relocations to setup sections' offsets. template <class ELFT> void OutputSection<ELFT>::assignOffsets() { - uintX_t Off = this->Header.sh_size; + uintX_t Off = this->Size; for (InputSection<ELFT> *S : Sections) { Off = alignTo(Off, S->Alignment); S->OutSecOff = Off; Off += S->getSize(); } - this->Header.sh_size = Off; + this->Size = Off; } // Sorts input sections by section name suffixes, so that .foo.N comes @@ -1052,7 +1056,7 @@ static void fill(uint8_t *Buf, size_t Size, ArrayRef<uint8_t> A) { template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) { ArrayRef<uint8_t> Filler = Script<ELFT>::X->getFiller(this->Name); if (!Filler.empty()) - fill(Buf, this->getSize(), Filler); + fill(Buf, this->Size, Filler); if (Config->Threads) { parallel_for_each(Sections.begin(), Sections.end(), [=](InputSection<ELFT> *C) { C->writeTo(Buf); }); @@ -1186,7 +1190,7 @@ static void writeCieFde(uint8_t *Buf, ArrayRef<uint8_t> D) { } template <class ELFT> void EhOutputSection<ELFT>::finalize() { - if (this->Header.sh_size) + if (this->Size) return; // Already finalized. size_t Off = 0; @@ -1199,7 +1203,7 @@ template <class ELFT> void EhOutputSection<ELFT>::finalize() { Off += alignTo(Fde->size(), sizeof(uintX_t)); } } - this->Header.sh_size = Off; + this->Size = Off; } template <class ELFT> static uint64_t readFdeAddr(uint8_t *Buf, int Size) { @@ -1231,7 +1235,7 @@ typename ELFT::uint EhOutputSection<ELFT>::getFdePc(uint8_t *Buf, size_t FdeOff, if ((Enc & 0x70) == DW_EH_PE_absptr) return Addr; if ((Enc & 0x70) == DW_EH_PE_pcrel) - return Addr + this->getVA() + Off; + return Addr + this->Addr + Off; fatal("unknown FDE size relative encoding"); } @@ -1262,7 +1266,7 @@ template <class ELFT> void EhOutputSection<ELFT>::writeTo(uint8_t *Buf) { uint8_t Enc = getFdeEncoding<ELFT>(Cie->Piece->data()); for (SectionPiece *Fde : Cie->FdePieces) { uintX_t Pc = getFdePc(Buf, Fde->OutputOff, Enc); - uintX_t FdeVA = this->getVA() + Fde->OutputOff; + uintX_t FdeVA = this->Addr + Fde->OutputOff; Out<ELFT>::EhFrameHdr->addFde(Pc, FdeVA); } } @@ -1284,7 +1288,7 @@ void MergeOutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) { auto *Sec = cast<MergeInputSection<ELFT>>(C); Sec->OutSec = this; this->updateAlignment(Sec->Alignment); - this->Header.sh_entsize = Sec->Entsize; + this->Entsize = Sec->Entsize; Sections.push_back(Sec); auto HashI = Sec->Hashes.begin(); @@ -1308,7 +1312,7 @@ unsigned MergeOutputSection<ELFT>::getOffset(CachedHashStringRef Val) { } template <class ELFT> bool MergeOutputSection<ELFT>::shouldTailMerge() const { - return Config->Optimize >= 2 && this->Header.sh_flags & SHF_STRINGS; + return Config->Optimize >= 2 && this->Flags & SHF_STRINGS; } template <class ELFT> void MergeOutputSection<ELFT>::finalize() { @@ -1316,7 +1320,7 @@ template <class ELFT> void MergeOutputSection<ELFT>::finalize() { Builder.finalize(); else Builder.finalizeInOrder(); - this->Header.sh_size = Builder.getSize(); + this->Size = Builder.getSize(); } template <class ELFT> void MergeOutputSection<ELFT>::finalizePieces() { @@ -1330,7 +1334,7 @@ StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic) Dynamic ? (uintX_t)SHF_ALLOC : 0), Dynamic(Dynamic) { // ELF string tables start with a NUL byte, so 1. - this->setSize(1); + this->Size = 1; } // Adds a string to the string table. If HashIt is true we hash and check for @@ -1340,12 +1344,12 @@ StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic) template <class ELFT> unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) { if (HashIt) { - auto R = StringMap.insert(std::make_pair(S, this->getSize())); + auto R = StringMap.insert(std::make_pair(S, this->Size)); if (!R.second) return R.first->second; } - unsigned Ret = this->getSize(); - this->setSize(this->getSize() + S.size() + 1); + unsigned Ret = this->Size; + this->Size = this->Size + S.size() + 1; Strings.push_back(S); return Ret; } @@ -1362,8 +1366,8 @@ template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) { template <class ELFT> typename ELFT::uint DynamicReloc<ELFT>::getOffset() const { if (OutputSec) - return OutputSec->getVA() + OffsetInSec; - return InputSec->OutSec->getVA() + InputSec->getOffset(OffsetInSec); + return OutputSec->Addr + OffsetInSec; + return InputSec->OutSec->Addr + InputSec->getOffset(OffsetInSec); } template <class ELFT> @@ -1386,8 +1390,8 @@ SymbolTableSection<ELFT>::SymbolTableSection( StrTabSec.isDynamic() ? SHT_DYNSYM : SHT_SYMTAB, StrTabSec.isDynamic() ? (uintX_t)SHF_ALLOC : 0), StrTabSec(StrTabSec) { - this->Header.sh_entsize = sizeof(Elf_Sym); - this->Header.sh_addralign = sizeof(uintX_t); + this->Entsize = sizeof(Elf_Sym); + this->Addralign = sizeof(uintX_t); } // Orders symbols according to their positions in the GOT, @@ -1418,12 +1422,12 @@ static uint8_t getSymbolBinding(SymbolBody *Body) { } template <class ELFT> void SymbolTableSection<ELFT>::finalize() { - if (this->Header.sh_size) + if (this->Size) return; // Already finalized. - this->Header.sh_size = getNumSymbols() * sizeof(Elf_Sym); - this->Header.sh_link = StrTabSec.SectionIndex; - this->Header.sh_info = NumLocals + 1; + this->Size = getNumSymbols() * sizeof(Elf_Sym); + this->Link = StrTabSec.SectionIndex; + this->Info = NumLocals + 1; if (Config->Relocatable) { size_t I = NumLocals; @@ -1485,7 +1489,7 @@ void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) { } else { const OutputSectionBase<ELFT> *OutSec = Section->OutSec; ESym->st_shndx = OutSec->SectionIndex; - ESym->st_value = OutSec->getVA() + Section->getOffset(Body); + ESym->st_value = OutSec->Addr + Section->getOffset(Body); } ESym->st_name = P.second; ESym->st_size = Body.template getSize<ELFT>(); @@ -1564,7 +1568,7 @@ SymbolTableSection<ELFT>::getOutputSection(SymbolBody *Sym) { template <class ELFT> VersionDefinitionSection<ELFT>::VersionDefinitionSection() : OutputSectionBase<ELFT>(".gnu.version_d", SHT_GNU_verdef, SHF_ALLOC) { - this->Header.sh_addralign = sizeof(uint32_t); + this->Addralign = sizeof(uint32_t); } static StringRef getFileDefName() { @@ -1578,14 +1582,13 @@ template <class ELFT> void VersionDefinitionSection<ELFT>::finalize() { for (VersionDefinition &V : Config->VersionDefinitions) V.NameOff = Out<ELFT>::DynStrTab->addString(V.Name); - this->Header.sh_size = - (sizeof(Elf_Verdef) + sizeof(Elf_Verdaux)) * getVerDefNum(); - this->Header.sh_link = Out<ELFT>::DynStrTab->SectionIndex; + this->Size = (sizeof(Elf_Verdef) + sizeof(Elf_Verdaux)) * getVerDefNum(); + this->Link = Out<ELFT>::DynStrTab->SectionIndex; // sh_info should be set to the number of definitions. This fact is missed in // documentation, but confirmed by binutils community: // https://sourceware.org/ml/binutils/2014-11/msg00355.html - this->Header.sh_info = getVerDefNum(); + this->Info = getVerDefNum(); } template <class ELFT> @@ -1622,16 +1625,16 @@ void VersionDefinitionSection<ELFT>::writeTo(uint8_t *Buf) { template <class ELFT> VersionTableSection<ELFT>::VersionTableSection() : OutputSectionBase<ELFT>(".gnu.version", SHT_GNU_versym, SHF_ALLOC) { - this->Header.sh_addralign = sizeof(uint16_t); + this->Addralign = sizeof(uint16_t); } template <class ELFT> void VersionTableSection<ELFT>::finalize() { - this->Header.sh_size = + this->Size = sizeof(Elf_Versym) * (Out<ELFT>::DynSymTab->getSymbols().size() + 1); - this->Header.sh_entsize = sizeof(Elf_Versym); + this->Entsize = sizeof(Elf_Versym); // At the moment of june 2016 GNU docs does not mention that sh_link field // should be set, but Sun docs do. Also readelf relies on this field. - this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex; + this->Link = Out<ELFT>::DynSymTab->SectionIndex; } template <class ELFT> void VersionTableSection<ELFT>::writeTo(uint8_t *Buf) { @@ -1645,7 +1648,7 @@ template <class ELFT> void VersionTableSection<ELFT>::writeTo(uint8_t *Buf) { template <class ELFT> VersionNeedSection<ELFT>::VersionNeedSection() : OutputSectionBase<ELFT>(".gnu.version_r", SHT_GNU_verneed, SHF_ALLOC) { - this->Header.sh_addralign = sizeof(uint32_t); + this->Addralign = sizeof(uint32_t); // Identifiers in verneed section start at 2 because 0 and 1 are reserved // for VER_NDX_LOCAL and VER_NDX_GLOBAL. @@ -1713,20 +1716,20 @@ template <class ELFT> void VersionNeedSection<ELFT>::writeTo(uint8_t *Buf) { } template <class ELFT> void VersionNeedSection<ELFT>::finalize() { - this->Header.sh_link = Out<ELFT>::DynStrTab->SectionIndex; - this->Header.sh_info = Needed.size(); + this->Link = Out<ELFT>::DynStrTab->SectionIndex; + this->Info = Needed.size(); unsigned Size = Needed.size() * sizeof(Elf_Verneed); for (std::pair<SharedFile<ELFT> *, size_t> &P : Needed) Size += P.first->VerdefMap.size() * sizeof(Elf_Vernaux); - this->Header.sh_size = Size; + this->Size = Size; } template <class ELFT> MipsReginfoOutputSection<ELFT>::MipsReginfoOutputSection() : OutputSectionBase<ELFT>(".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); + this->Addralign = 4; + this->Entsize = sizeof(Elf_Mips_RegInfo); + this->Size = sizeof(Elf_Mips_RegInfo); } template <class ELFT> @@ -1735,7 +1738,7 @@ void MipsReginfoOutputSection<ELFT>::writeTo(uint8_t *Buf) { if (Config->Relocatable) R->ri_gp_value = 0; else - R->ri_gp_value = Out<ELFT>::Got->getVA() + MipsGPOffset; + R->ri_gp_value = Out<ELFT>::Got->Addr + MipsGPOffset; R->ri_gprmask = GprMask; } @@ -1751,23 +1754,23 @@ template <class ELFT> MipsOptionsOutputSection<ELFT>::MipsOptionsOutputSection() : OutputSectionBase<ELFT>(".MIPS.options", SHT_MIPS_OPTIONS, SHF_ALLOC | SHF_MIPS_NOSTRIP) { - this->Header.sh_addralign = 8; - this->Header.sh_entsize = 1; - this->Header.sh_size = sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo); + this->Addralign = 8; + this->Entsize = 1; + this->Size = sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo); } template <class ELFT> void MipsOptionsOutputSection<ELFT>::writeTo(uint8_t *Buf) { auto *Opt = reinterpret_cast<Elf_Mips_Options *>(Buf); Opt->kind = ODK_REGINFO; - Opt->size = this->Header.sh_size; + Opt->size = this->Size; Opt->section = 0; Opt->info = 0; auto *Reg = reinterpret_cast<Elf_Mips_RegInfo *>(Buf + sizeof(*Opt)); if (Config->Relocatable) Reg->ri_gp_value = 0; else - Reg->ri_gp_value = Out<ELFT>::Got->getVA() + MipsGPOffset; + Reg->ri_gp_value = Out<ELFT>::Got->Addr + MipsGPOffset; Reg->ri_gprmask = GprMask; } @@ -1782,9 +1785,9 @@ void MipsOptionsOutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) { template <class ELFT> MipsAbiFlagsOutputSection<ELFT>::MipsAbiFlagsOutputSection() : OutputSectionBase<ELFT>(".MIPS.abiflags", SHT_MIPS_ABIFLAGS, SHF_ALLOC) { - this->Header.sh_addralign = 8; - this->Header.sh_entsize = sizeof(Elf_Mips_ABIFlags); - this->Header.sh_size = sizeof(Elf_Mips_ABIFlags); + this->Addralign = 8; + this->Entsize = sizeof(Elf_Mips_ABIFlags); + this->Size = sizeof(Elf_Mips_ABIFlags); memset(&Flags, 0, sizeof(Flags)); } @@ -1859,7 +1862,7 @@ OutputSectionFactory<ELFT>::create(const SectionKey<ELFT::Is64Bits> &Key, uintX_t Flags = getOutFlags(C); OutputSectionBase<ELFT> *&Sec = Map[Key]; if (Sec) { - Sec->updateFlags(Flags); + Sec->Flags |= Flags; return {Sec, false}; } |

