Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -113,7 +113,7 @@ if (Offset != 0) fatal(getName(this) + ": unsupported reference to the middle of '" + Name + "' section"); - return this->OutSec->getVA(); + return this->OutSec->Addr; } llvm_unreachable("invalid section kind"); } @@ -267,7 +267,7 @@ case R_TLSDESC_CALL: llvm_unreachable("cannot relocate hint relocs"); case R_TLSLD: - return Out::Got->getTlsIndexOff() + A - Out::Got->getSize(); + return Out::Got->getTlsIndexOff() + A - Out::Got->Size; case R_TLSLD_PC: return Out::Got->getTlsIndexVA() + A - P; case R_THUNK_ABS: @@ -278,8 +278,7 @@ case R_PPC_TOC: return getPPC64TocBase() + A; case R_TLSGD: - return Out::Got->getGlobalDynOffset(Body) + A - - Out::Got->getSize(); + return Out::Got->getGlobalDynOffset(Body) + A - Out::Got->Size; case R_TLSGD_PC: return Out::Got->getGlobalDynAddr(Body) + A - P; case R_TLSDESC: @@ -295,13 +294,12 @@ case R_SIZE: return Body.getSize() + A; case R_GOTREL: - return Body.getVA(A) - Out::Got->getVA(); + return Body.getVA(A) - Out::Got->Addr; case R_GOTREL_FROM_END: - return Body.getVA(A) - Out::Got->getVA() - - Out::Got->getSize(); + return Body.getVA(A) - Out::Got->Addr - Out::Got->Size; case R_RELAX_TLS_GD_TO_IE_END: case R_GOT_FROM_END: - return Body.getGotOffset() + A - Out::Got->getSize(); + return Body.getGotOffset() + A - Out::Got->Size; case R_RELAX_TLS_GD_TO_IE_ABS: case R_GOT: return Body.getGotVA() + A; @@ -312,9 +310,9 @@ case R_GOT_PC: return Body.getGotVA() + A - P; case R_GOTONLY_PC: - return Out::Got->getVA() + A - P; + return Out::Got->Addr + A - P; case R_GOTONLY_PC_FROM_END: - return Out::Got->getVA() + A - P + Out::Got->getSize(); + return Out::Got->Addr + A - P + Out::Got->Size; case R_RELAX_TLS_LD_TO_LE: case R_RELAX_TLS_IE_TO_LE: case R_RELAX_TLS_GD_TO_LE: @@ -366,8 +364,8 @@ if (Out::Opd) { // If this is a local call, and we currently have the address of a // function-descriptor, get the underlying code address instead. - uint64_t OpdStart = Out::Opd->getVA(); - uint64_t OpdEnd = OpdStart + Out::Opd->getSize(); + uint64_t OpdStart = Out::Opd->Addr; + uint64_t OpdEnd = OpdStart + Out::Opd->Size; bool InOpd = OpdStart <= SymVA && SymVA < OpdEnd; if (InOpd) SymVA = read64be(&Out::OpdBuf[SymVA - OpdStart]); @@ -408,7 +406,7 @@ return; } - uintX_t AddrLoc = this->OutSec->getVA() + Offset; + uintX_t AddrLoc = this->OutSec->Addr + Offset; uint64_t SymVA = 0; if (!Sym.isTls() || Out::TlsPhdr) SymVA = SignExtend64( @@ -440,7 +438,7 @@ uint32_t Type = Rel.Type; uintX_t A = Rel.Addend; - uintX_t AddrLoc = OutSec->getVA() + Offset; + uintX_t AddrLoc = OutSec->Addr + Offset; RelExpr Expr = Rel.Expr; uint64_t SymVA = SignExtend64(getSymVA(Type, A, AddrLoc, *Rel.Sym, Expr)); Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -381,7 +381,7 @@ if (auto *Body = dyn_cast>(Cmd->Sym)) { Body->Section = Sec; - Body->Value = Cmd->Expression(Value) - Sec->getVA(); + Body->Value = Cmd->Expression(Value) - Sec->Addr; return; } auto *Body = cast>(Cmd->Sym); @@ -389,7 +389,7 @@ } template static bool isTbss(OutputSectionBase *Sec) { - return (Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS; + return (Sec->Flags & SHF_TLS) && Sec->Type == SHT_NOBITS; } template void LinkerScript::output(InputSection *S) { @@ -399,13 +399,13 @@ uintX_t Pos = IsTbss ? Dot + ThreadBssOffset : Dot; Pos = alignTo(Pos, S->Alignment); - S->OutSecOff = Pos - CurOutSec->getVA(); + S->OutSecOff = Pos - CurOutSec->Addr; Pos += S->getSize(); // Update output section size after adding each section. This is so that // SIZEOF works correctly in the case below: // .foo { *(.aaa) a = SIZEOF(.foo); *(.bbb) } - CurOutSec->setSize(Pos - CurOutSec->getVA()); + CurOutSec->Size = Pos - CurOutSec->Addr; if (IsTbss) ThreadBssOffset = Pos - Dot; @@ -420,7 +420,7 @@ for (InputSection *I : OutSec->Sections) output(I); } else { - Dot += CurOutSec->getSize(); + Dot += CurOutSec->Size; } } @@ -434,8 +434,8 @@ flush(); CurOutSec = Sec; - Dot = alignTo(Dot, CurOutSec->getAlignment()); - CurOutSec->setVA(isTbss(CurOutSec) ? Dot + ThreadBssOffset : Dot); + Dot = alignTo(Dot, CurOutSec->Addralign); + CurOutSec->Addr = isTbss(CurOutSec) ? Dot + ThreadBssOffset : Dot; // If neither AT nor AT> is specified for an allocatable section, the linker // will set the LMA such that the difference between VMA and LMA for the @@ -450,7 +450,7 @@ if (AssignCmd->Name == ".") { // Update to location counter means update to section size. Dot = AssignCmd->Expression(Dot); - CurOutSec->setSize(Dot - CurOutSec->getVA()); + CurOutSec->Size = Dot - CurOutSec->Addr; return; } assignSectionSymbol(AssignCmd, CurOutSec, Dot); @@ -459,9 +459,9 @@ // Handle BYTE(), SHORT(), LONG(), or QUAD(). if (auto *DataCmd = dyn_cast(&Base)) { - DataCmd->Offset = Dot - CurOutSec->getVA(); + DataCmd->Offset = Dot - CurOutSec->Addr; Dot += DataCmd->Size; - CurOutSec->setSize(Dot - CurOutSec->getVA()); + CurOutSec->Size = Dot - CurOutSec->Addr; return; } @@ -552,8 +552,8 @@ std::vector *> Secs = findSections(Cmd->Name, *OutputSections); if (!Secs.empty()) { - Flags = Secs[0]->getFlags(); - Type = Secs[0]->getType(); + Flags = Secs[0]->Flags; + Type = Secs[0]->Type; continue; } @@ -654,10 +654,10 @@ uintX_t MinVA = std::numeric_limits::max(); for (OutputSectionBase *Sec : *OutputSections) { - if (Sec->getFlags() & SHF_ALLOC) - MinVA = std::min(MinVA, Sec->getVA()); + if (Sec->Flags & SHF_ALLOC) + MinVA = std::min(MinVA, Sec->Addr); else - Sec->setVA(0); + Sec->Addr = 0; } uintX_t HeaderSize = getHeaderSize(); @@ -678,8 +678,8 @@ // ELF and Program headers need to be right before the first section in // memory. Set their addresses accordingly. MinVA = alignDown(MinVA - HeaderSize, Target->PageSize); - Out::ElfHeader->setVA(MinVA); - Out::ProgramHeaders->setVA(Out::ElfHeader->getSize() + MinVA); + Out::ElfHeader->Addr = MinVA; + Out::ProgramHeaders->Addr = Out::ElfHeader->Size + MinVA; FirstPTLoad->First = Out::ElfHeader; if (!FirstPTLoad->Last) FirstPTLoad->Last = Out::ProgramHeaders; @@ -692,8 +692,8 @@ // The code below removes empty PT_LOAD segment and updates // program headers size. Phdrs.erase(FirstPTLoad); - Out::ProgramHeaders->setSize(sizeof(typename ELFT::Phdr) * - Phdrs.size()); + Out::ProgramHeaders->Size = + sizeof(typename ELFT::Phdr) * Phdrs.size(); } } @@ -731,7 +731,7 @@ // Add output sections to program headers. for (OutputSectionBase *Sec : *OutputSections) { - if (!(Sec->getFlags() & SHF_ALLOC)) + if (!(Sec->Flags & SHF_ALLOC)) break; std::vector PhdrIds = getPhdrIndices(Sec->getName()); @@ -833,7 +833,7 @@ uint64_t LinkerScript::getOutputSectionAddress(StringRef Name) { for (OutputSectionBase *Sec : *OutputSections) if (Sec->getName() == Name) - return Sec->getVA(); + return Sec->Addr; error("undefined section " + Name); return 0; } @@ -851,7 +851,7 @@ uint64_t LinkerScript::getOutputSectionSize(StringRef Name) { for (OutputSectionBase *Sec : *OutputSections) if (Sec->getName() == Name) - return Sec->getSize(); + return Sec->Size; error("undefined section " + Name); return 0; } @@ -860,7 +860,7 @@ uint64_t LinkerScript::getOutputSectionAlign(StringRef Name) { for (OutputSectionBase *Sec : *OutputSections) if (Sec->getName() == Name) - return Sec->getAlignment(); + return Sec->Addralign; error("undefined section " + Name); return 0; } Index: ELF/OutputSections.h =================================================================== --- ELF/OutputSections.h +++ ELF/OutputSections.h @@ -71,13 +71,8 @@ }; OutputSectionBase(StringRef Name, uint32_t Type, uintX_t Flags); - void setVA(uintX_t VA) { Header.sh_addr = VA; } - uintX_t getVA() const { return Header.sh_addr; } void setLMAOffset(uintX_t LMAOff) { LMAOffset = LMAOff; } - uintX_t getLMA() const { return Header.sh_addr + LMAOffset; } - void setFileOffset(uintX_t Off) { Header.sh_offset = Off; } - uintX_t getFileOffset() { return Header.sh_offset; } - void setSHName(unsigned Val) { Header.sh_name = Val; } + uintX_t getLMA() const { return Addr + LMAOffset; } void writeHeaderTo(Elf_Shdr *SHdr); StringRef getName() const { return Name; } @@ -89,19 +84,11 @@ unsigned SectionIndex; - // Returns the size of the section in the output file. - uintX_t getSize() const { return Header.sh_size; } - void setSize(uintX_t Val) { Header.sh_size = Val; } - uintX_t getFlags() const { return Header.sh_flags; } - void updateFlags(uintX_t Val) { Header.sh_flags |= Val; } uint32_t getPhdrFlags() const; - uintX_t getFileOff() const { return Header.sh_offset; } - uintX_t getAlignment() const { return Header.sh_addralign; } - uint32_t getType() const { return Header.sh_type; } void updateAlignment(uintX_t Alignment) { - if (Alignment > Header.sh_addralign) - Header.sh_addralign = Alignment; + if (Alignment > Addralign) + Addralign = Alignment; } // If true, this section will be page aligned on disk. @@ -122,10 +109,18 @@ virtual void writeTo(uint8_t *Buf) {} virtual ~OutputSectionBase() = default; -protected: StringRef Name; - Elf_Shdr Header; + uintX_t Size = 0; + uintX_t Entsize = 0; + uintX_t Addralign = 0; + uintX_t Offset = 0; + uintX_t Flags = 0; uintX_t LMAOffset = 0; + uintX_t Addr = 0; + uint32_t ShName = 0; + uint32_t Type = 0; + uint32_t Info = 0; + uint32_t Link = 0; }; template @@ -187,7 +182,7 @@ // after 'local' and 'global' entries. uintX_t getMipsTlsOffset() const; - uintX_t getTlsIndexVA() { return Base::getVA() + TlsIndexOff; } + uintX_t getTlsIndexVA() { return this->Addr + TlsIndexOff; } uint32_t getTlsIndexOff() const { return TlsIndexOff; } // Flag to force GOT to be in output if we have relocations @@ -794,7 +789,7 @@ template uint64_t getHeaderSize() { if (Config->OFormatBinary) return 0; - return Out::ElfHeader->getSize() + Out::ProgramHeaders->getSize(); + return Out::ElfHeader->Size + Out::ProgramHeaders->Size; } template uint8_t Out::First; Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -36,14 +36,12 @@ OutputSectionBase::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; + Addralign = 1; } template uint32_t OutputSectionBase::getPhdrFlags() const { - uintX_t Flags = getFlags(); uint32_t Ret = PF_R; if (Flags & SHF_WRITE) Ret |= PF_W; @@ -54,7 +52,16 @@ template void OutputSectionBase::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 @@ -81,7 +88,7 @@ // 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 void GdbIndexSection::writeTo(uint8_t *Buf) { @@ -104,7 +111,7 @@ template GotPltSection::GotPltSection() : OutputSectionBase(".got.plt", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE) { - this->Header.sh_addralign = Target->GotPltEntrySize; + this->Addralign = Target->GotPltEntrySize; } template void GotPltSection::addEntry(SymbolBody &Sym) { @@ -117,8 +124,8 @@ } template void GotPltSection::finalize() { - this->Header.sh_size = (Target->GotPltHeaderEntriesNum + Entries.size()) * - Target->GotPltEntrySize; + this->Size = (Target->GotPltHeaderEntriesNum + Entries.size()) * + Target->GotPltEntrySize; } template void GotPltSection::writeTo(uint8_t *Buf) { @@ -134,8 +141,8 @@ GotSection::GotSection() : OutputSectionBase(".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 void GotSection::addEntry(SymbolBody &Sym) { @@ -281,7 +288,7 @@ template typename GotSection::uintX_t GotSection::getGlobalDynAddr(const SymbolBody &B) const { - return this->getVA() + B.GlobalDynIndex * sizeof(uintX_t); + return this->Addr + B.GlobalDynIndex * sizeof(uintX_t); } template @@ -312,11 +319,11 @@ // 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 @@ -402,7 +409,7 @@ template PltSection::PltSection() : OutputSectionBase(".plt", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR) { - this->Header.sh_addralign = 16; + this->Addralign = 16; } template void PltSection::writeTo(uint8_t *Buf) { @@ -415,7 +422,7 @@ const SymbolBody *B = I.first; unsigned RelOff = I.second; uint64_t Got = B->getGotPltVA(); - 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 void PltSection::finalize() { - this->Header.sh_size = - Target->PltHeaderSize + Entries.size() * Target->PltEntrySize; + this->Size = Target->PltHeaderSize + Entries.size() * Target->PltEntrySize; } template @@ -437,8 +443,8 @@ : OutputSectionBase(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 @@ -487,25 +493,24 @@ } template unsigned RelocationSection::getRelocOffset() { - return this->Header.sh_entsize * Relocs.size(); + return this->Entsize * Relocs.size(); } template void RelocationSection::finalize() { - this->Header.sh_link = Out::DynSymTab - ? Out::DynSymTab->SectionIndex - : Out::SymTab->SectionIndex; - this->Header.sh_size = Relocs.size() * this->Header.sh_entsize; + this->Link = Out::DynSymTab ? Out::DynSymTab->SectionIndex + : Out::SymTab->SectionIndex; + this->Size = Relocs.size() * this->Entsize; } template HashTableSection::HashTableSection() : OutputSectionBase(".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 void HashTableSection::finalize() { - this->Header.sh_link = Out::DynSymTab->SectionIndex; + this->Link = Out::DynSymTab->SectionIndex; unsigned NumEntries = 2; // nbucket and nchain. NumEntries += Out::DynSymTab->getNumSymbols(); // The chain entries. @@ -514,7 +519,7 @@ // FIXME: This is simplistic. We can try to optimize it, but implementing // support for SHT_GNU_HASH is probably even more profitable. NumEntries += Out::DynSymTab->getNumSymbols(); - this->Header.sh_size = NumEntries * sizeof(Elf_Word); + this->Size = NumEntries * sizeof(Elf_Word); } template void HashTableSection::writeTo(uint8_t *Buf) { @@ -546,8 +551,8 @@ template GnuHashTableSection::GnuHashTableSection() : OutputSectionBase(".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 @@ -591,11 +596,11 @@ // Second hash shift estimation: just predefined values. Shift2 = ELFT::Is64Bits ? 6 : 5; - this->Header.sh_link = Out::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::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 void GnuHashTableSection::writeTo(uint8_t *Buf) { @@ -691,15 +696,14 @@ template DynamicSection::DynamicSection() : OutputSectionBase(".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 @@ // Add remaining entries to complete .dynamic contents. template void DynamicSection::finalize() { - if (this->Header.sh_size) + if (this->Size) return; // Already finalized. - this->Header.sh_link = Out::DynStrTab->SectionIndex; + this->Link = Out::DynStrTab->SectionIndex; if (Out::RelaDyn->hasRelocs()) { bool IsRela = Config->Rela; Add({IsRela ? DT_RELA : DT_REL, Out::RelaDyn}); - Add({IsRela ? DT_RELASZ : DT_RELSZ, Out::RelaDyn->getSize()}); + Add({IsRela ? DT_RELASZ : DT_RELSZ, Out::RelaDyn->Size}); Add({IsRela ? DT_RELAENT : DT_RELENT, uintX_t(IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel))}); @@ -770,7 +774,7 @@ } if (Out::RelaPlt && Out::RelaPlt->hasRelocs()) { Add({DT_JMPREL, Out::RelaPlt}); - Add({DT_PLTRELSZ, Out::RelaPlt->getSize()}); + Add({DT_PLTRELSZ, Out::RelaPlt->Size}); Add({Config->EMachine == EM_MIPS ? DT_MIPS_PLTGOT : DT_PLTGOT, Out::GotPlt}); Add({DT_PLTREL, uint64_t(Config->Rela ? DT_RELA : DT_REL)}); @@ -779,7 +783,7 @@ Add({DT_SYMTAB, Out::DynSymTab}); Add({DT_SYMENT, sizeof(Elf_Sym)}); Add({DT_STRTAB, Out::DynStrTab}); - Add({DT_STRSZ, Out::DynStrTab->getSize()}); + Add({DT_STRSZ, Out::DynStrTab->Size}); if (Out::GnuHashTab) Add({DT_GNU_HASH, Out::GnuHashTab}); if (Out::HashTab) @@ -831,7 +835,7 @@ } // +1 for DT_NULL - this->Header.sh_size = (Entries.size() + 1) * this->Header.sh_entsize; + this->Size = (Entries.size() + 1) * this->Entsize; } template void DynamicSection::writeTo(uint8_t *Buf) { @@ -841,10 +845,10 @@ 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(); @@ -880,11 +884,11 @@ 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(Buf + 4, Out::EhFrame->getVA() - this->getVA() - 4); + write32(Buf + 4, Out::EhFrame->Addr - this->Addr - 4); write32(Buf + 8, Fdes.size()); Buf += 12; - uintX_t VA = this->getVA(); + uintX_t VA = this->Addr; for (FdeData &Fde : Fdes) { write32(Buf, Fde.Pc - VA); write32(Buf + 4, Fde.FdeVA - VA); @@ -894,7 +898,7 @@ template void EhFrameHeader::finalize() { // .eh_frame_hdr has a 12 bytes header followed by an array of FDEs. - this->Header.sh_size = 12 + Out::EhFrame->NumFdes * 8; + this->Size = 12 + Out::EhFrame->NumFdes * 8; } template @@ -906,17 +910,17 @@ OutputSection::OutputSection(StringRef Name, uint32_t Type, uintX_t Flags) : OutputSectionBase(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 void OutputSection::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 @@ // 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::SymTab->SectionIndex; + this->Link = Out::SymTab->SectionIndex; // sh_info for SHT_REL[A] sections should contain the section header index of // the section to which the relocation applies. InputSectionBase *S = Sections[0]->getRelocatedSection(); - this->Header.sh_info = S->OutSec->SectionIndex; + this->Info = S->OutSec->SectionIndex; } template @@ -947,19 +951,19 @@ // 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 void OutputSection::assignOffsets() { - uintX_t Off = this->Header.sh_size; + uintX_t Off = this->Size; for (InputSection *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 @@ template void OutputSection::writeTo(uint8_t *Buf) { ArrayRef Filler = Script::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 *C) { C->writeTo(Buf); }); @@ -1186,7 +1190,7 @@ } template void EhOutputSection::finalize() { - if (this->Header.sh_size) + if (this->Size) return; // Already finalized. size_t Off = 0; @@ -1199,7 +1203,7 @@ Off += alignTo(Fde->size(), sizeof(uintX_t)); } } - this->Header.sh_size = Off; + this->Size = Off; } template static uint64_t readFdeAddr(uint8_t *Buf, int Size) { @@ -1231,7 +1235,7 @@ 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 @@ uint8_t Enc = getFdeEncoding(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::EhFrameHdr->addFde(Pc, FdeVA); } } @@ -1284,7 +1288,7 @@ auto *Sec = cast>(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 @@ } template bool MergeOutputSection::shouldTailMerge() const { - return Config->Optimize >= 2 && this->Header.sh_flags & SHF_STRINGS; + return Config->Optimize >= 2 && this->Flags & SHF_STRINGS; } template void MergeOutputSection::finalize() { @@ -1316,7 +1320,7 @@ Builder.finalize(); else Builder.finalizeInOrder(); - this->Header.sh_size = Builder.getSize(); + this->Size = Builder.getSize(); } template void MergeOutputSection::finalizePieces() { @@ -1330,7 +1334,7 @@ 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 @@ template unsigned StringTableSection::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 typename ELFT::uint DynamicReloc::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 @@ -1386,8 +1390,8 @@ 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 @@ } template void SymbolTableSection::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 @@ } else { const OutputSectionBase *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(); @@ -1564,7 +1568,7 @@ template VersionDefinitionSection::VersionDefinitionSection() : OutputSectionBase(".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 @@ for (VersionDefinition &V : Config->VersionDefinitions) V.NameOff = Out::DynStrTab->addString(V.Name); - this->Header.sh_size = - (sizeof(Elf_Verdef) + sizeof(Elf_Verdaux)) * getVerDefNum(); - this->Header.sh_link = Out::DynStrTab->SectionIndex; + this->Size = (sizeof(Elf_Verdef) + sizeof(Elf_Verdaux)) * getVerDefNum(); + this->Link = Out::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 @@ -1622,16 +1625,16 @@ template VersionTableSection::VersionTableSection() : OutputSectionBase(".gnu.version", SHT_GNU_versym, SHF_ALLOC) { - this->Header.sh_addralign = sizeof(uint16_t); + this->Addralign = sizeof(uint16_t); } template void VersionTableSection::finalize() { - this->Header.sh_size = + this->Size = sizeof(Elf_Versym) * (Out::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::DynSymTab->SectionIndex; + this->Link = Out::DynSymTab->SectionIndex; } template void VersionTableSection::writeTo(uint8_t *Buf) { @@ -1645,7 +1648,7 @@ template VersionNeedSection::VersionNeedSection() : OutputSectionBase(".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 void VersionNeedSection::finalize() { - this->Header.sh_link = Out::DynStrTab->SectionIndex; - this->Header.sh_info = Needed.size(); + this->Link = Out::DynStrTab->SectionIndex; + this->Info = Needed.size(); unsigned Size = Needed.size() * sizeof(Elf_Verneed); for (std::pair *, size_t> &P : Needed) Size += P.first->VerdefMap.size() * sizeof(Elf_Vernaux); - this->Header.sh_size = Size; + this->Size = Size; } template MipsReginfoOutputSection::MipsReginfoOutputSection() : OutputSectionBase(".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 @@ -1735,7 +1738,7 @@ if (Config->Relocatable) R->ri_gp_value = 0; else - R->ri_gp_value = Out::Got->getVA() + MipsGPOffset; + R->ri_gp_value = Out::Got->Addr + MipsGPOffset; R->ri_gprmask = GprMask; } @@ -1751,23 +1754,23 @@ MipsOptionsOutputSection::MipsOptionsOutputSection() : OutputSectionBase(".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 void MipsOptionsOutputSection::writeTo(uint8_t *Buf) { auto *Opt = reinterpret_cast(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(Buf + sizeof(*Opt)); if (Config->Relocatable) Reg->ri_gp_value = 0; else - Reg->ri_gp_value = Out::Got->getVA() + MipsGPOffset; + Reg->ri_gp_value = Out::Got->Addr + MipsGPOffset; Reg->ri_gprmask = GprMask; } @@ -1782,9 +1785,9 @@ template MipsAbiFlagsOutputSection::MipsAbiFlagsOutputSection() : OutputSectionBase(".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 @@ uintX_t Flags = getOutFlags(C); OutputSectionBase *&Sec = Map[Key]; if (Sec) { - Sec->updateFlags(Flags); + Sec->Flags |= Flags; return {Sec, false}; } Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -394,8 +394,8 @@ fatal("cannot create a copy relocation for symbol " + SS->getName()); uintX_t Alignment = getAlignment(SS); - uintX_t Off = alignTo(Out::Bss->getSize(), Alignment); - Out::Bss->setSize(Off + SymSize); + uintX_t Off = alignTo(Out::Bss->Size, Alignment); + Out::Bss->Size = Off + SymSize; Out::Bss->updateAlignment(Alignment); uintX_t Shndx = SS->Sym.st_shndx; uintX_t Value = SS->Sym.st_value; Index: ELF/Symbols.cpp =================================================================== --- ELF/Symbols.cpp +++ ELF/Symbols.cpp @@ -37,8 +37,8 @@ if (!Sec) return D.Value; if (D.Value == DefinedSynthetic::SectionEnd) - return Sec->getVA() + Sec->getSize(); - return Sec->getVA() + D.Value; + return Sec->Addr + Sec->Size; + return Sec->Addr + D.Value; } case SymbolBody::DefinedRegularKind: { auto &D = cast>(Body); @@ -60,7 +60,7 @@ Offset += Addend; Addend = 0; } - uintX_t VA = (SC->OutSec ? SC->OutSec->getVA() : 0) + SC->getOffset(Offset); + uintX_t VA = (SC->OutSec ? SC->OutSec->Addr : 0) + SC->getOffset(Offset); if (D.isTls() && !Config->Relocatable) { if (!Out::TlsPhdr) fatal(getFilename(D.File) + @@ -70,7 +70,7 @@ return VA; } case SymbolBody::DefinedCommonKind: - return In::Common->OutSec->getVA() + In::Common->OutSecOff + + return In::Common->OutSec->Addr + In::Common->OutSecOff + cast(Body).Offset; case SymbolBody::SharedKind: { auto &SS = cast>(Body); @@ -78,7 +78,7 @@ return 0; if (SS.isFunc()) return Body.getPltVA(); - return Out::Bss->getVA() + SS.OffsetInBss; + return Out::Bss->Addr + SS.OffsetInBss; } case SymbolBody::UndefinedKind: return 0; @@ -151,7 +151,7 @@ } template typename ELFT::uint SymbolBody::getGotVA() const { - return Out::Got->getVA() + getGotOffset(); + return Out::Got->Addr + getGotOffset(); } template typename ELFT::uint SymbolBody::getGotOffset() const { @@ -159,7 +159,7 @@ } template typename ELFT::uint SymbolBody::getGotPltVA() const { - return Out::GotPlt->getVA() + getGotPltOffset(); + return Out::GotPlt->Addr + getGotPltOffset(); } template typename ELFT::uint SymbolBody::getGotPltOffset() const { @@ -167,7 +167,7 @@ } template typename ELFT::uint SymbolBody::getPltVA() const { - return Out::Plt->getVA() + Target->PltHeaderSize + + return Out::Plt->Addr + Target->PltHeaderSize + PltIndex * Target->PltEntrySize; } Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -107,7 +107,7 @@ template uint8_t *BuildIdSection::getOutputLoc(uint8_t *Start) const { - return Start + this->OutSec->getFileOffset() + this->OutSecOff; + return Start + this->OutSec->Offset + this->OutSecOff; } static std::vector> split(ArrayRef Arr, Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -355,7 +355,7 @@ } void X86TargetInfo::writeGotPltHeader(uint8_t *Buf) const { - write32le(Buf, Out::Dynamic->getVA()); + write32le(Buf, Out::Dynamic->Addr); } void X86TargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &S) const { @@ -403,7 +403,7 @@ 0x90, 0x90, 0x90, 0x90 // nop; nop; nop; nop }; memcpy(Buf, PltData, sizeof(PltData)); - uint32_t Got = Out::GotPlt->getVA(); + uint32_t Got = Out::GotPlt->Addr; write32le(Buf + 2, Got + 4); write32le(Buf + 8, Got + 8); } @@ -420,7 +420,7 @@ // jmp *foo@GOT(%ebx) or jmp *foo_in_GOT Buf[1] = Config->Pic ? 0xa3 : 0x25; - uint32_t Got = Out::GotPlt->getVA(); + uint32_t Got = Out::GotPlt->Addr; write32le(Buf + 2, Config->Shared ? GotEntryAddr - Got : GotEntryAddr); write32le(Buf + 7, RelOff); write32le(Buf + 12, -Index * PltEntrySize - PltHeaderSize - 16); @@ -595,7 +595,7 @@ // required, but it is documented in the psabi and the glibc dynamic linker // seems to use it (note that this is relevant for linking ld.so, not any // other program). - write64le(Buf, Out::Dynamic->getVA()); + write64le(Buf, Out::Dynamic->Addr); } template @@ -613,8 +613,8 @@ 0x0f, 0x1f, 0x40, 0x00 // nopl 0x0(rax) }; memcpy(Buf, PltData, sizeof(PltData)); - uint64_t Got = Out::GotPlt->getVA(); - uint64_t Plt = Out::Plt->getVA(); + uint64_t Got = Out::GotPlt->Addr; + uint64_t Plt = Out::Plt->Addr; write32le(Buf + 2, Got - Plt + 2); // GOT+8 write32le(Buf + 8, Got - Plt + 4); // GOT+16 } @@ -1019,7 +1019,7 @@ // TOC starts where the first of these sections starts. We always create a // .got when we see a relocation that uses it, so for us the start is always // the .got. - uint64_t TocVA = Out::Got->getVA(); + uint64_t TocVA = Out::Got->Addr; // Per the ppc64-elf-linux ABI, The TOC base is TOC value plus 0x8000 // thus permitting a full 64 Kbytes segment. Note that the glibc startup @@ -1254,7 +1254,7 @@ } void AArch64TargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { - write64le(Buf, Out::Plt->getVA()); + write64le(Buf, Out::Plt->Addr); } static uint64_t getAArch64Page(uint64_t Expr) { @@ -1274,8 +1274,8 @@ }; memcpy(Buf, PltData, sizeof(PltData)); - uint64_t Got = Out::GotPlt->getVA(); - uint64_t Plt = Out::Plt->getVA(); + uint64_t Got = Out::GotPlt->Addr; + uint64_t Plt = Out::Plt->Addr; relocateOne(Buf + 4, R_AARCH64_ADR_PREL_PG_HI21, getAArch64Page(Got + 16) - getAArch64Page(Plt + 4)); relocateOne(Buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, Got + 16); @@ -1616,7 +1616,7 @@ } void ARMTargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { - write32le(Buf, Out::Plt->getVA()); + write32le(Buf, Out::Plt->Addr); } void ARMTargetInfo::writePltHeader(uint8_t *Buf) const { @@ -1628,8 +1628,8 @@ 0x00, 0x00, 0x00, 0x00, // L2: .word &(.got.plt) - L1 - 8 }; memcpy(Buf, PltData, sizeof(PltData)); - uint64_t GotPlt = Out::GotPlt->getVA(); - uint64_t L1 = Out::Plt->getVA() + 8; + uint64_t GotPlt = Out::GotPlt->Addr; + uint64_t L1 = Out::Plt->Addr + 8; write32le(Buf + 16, GotPlt - L1 - 8); } @@ -1996,7 +1996,7 @@ template void MipsTargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { - write32(Buf, Out::Plt->getVA()); + write32(Buf, Out::Plt->Addr); } template @@ -2063,7 +2063,7 @@ write32(Buf + 20, 0x0018c082); // srl $24, $24, 2 write32(Buf + 24, 0x0320f809); // jalr $25 write32(Buf + 28, 0x2718fffe); // subu $24, $24, 2 - uint64_t Got = Out::GotPlt->getVA(); + uint64_t Got = Out::GotPlt->Addr; writeMipsHi16(Buf, Got); writeMipsLo16(Buf + 4, Got); writeMipsLo16(Buf + 8, Got); Index: ELF/Thunks.cpp =================================================================== --- ELF/Thunks.cpp +++ ELF/Thunks.cpp @@ -183,7 +183,7 @@ : Destination(D), Owner(O), Offset(O.getThunkOff() + O.getThunksSize()) {} template typename ELFT::uint Thunk::getVA() const { - return Owner.OutSec->getVA() + Owner.OutSecOff + Offset; + return Owner.OutSec->Addr + Owner.OutSecOff + Offset; } template Thunk::~Thunk() = default; Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -222,7 +222,7 @@ Out::VerNeed = make>(); Out::ElfHeader = make>("", 0, SHF_ALLOC); - Out::ElfHeader->setSize(sizeof(Elf_Ehdr)); + Out::ElfHeader->Size = sizeof(Elf_Ehdr); Out::ProgramHeaders = make>("", 0, SHF_ALLOC); Out::ProgramHeaders->updateAlignment(sizeof(uintX_t)); @@ -263,7 +263,7 @@ // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf Out::MipsRldMap = make>(".rld_map", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); - Out::MipsRldMap->setSize(sizeof(uintX_t)); + Out::MipsRldMap->Size = sizeof(uintX_t); Out::MipsRldMap->updateAlignment(sizeof(uintX_t)); } if (!Config->VersionDefinitions.empty()) @@ -394,12 +394,12 @@ bool elf::isRelroSection(const OutputSectionBase *Sec) { if (!Config->ZRelro) return false; - typename ELFT::uint Flags = Sec->getFlags(); + typename ELFT::uint Flags = Sec->Flags; if (!(Flags & SHF_ALLOC) || !(Flags & SHF_WRITE)) return false; if (Flags & SHF_TLS) return true; - uint32_t Type = Sec->getType(); + uint32_t Type = Sec->Type; if (Type == SHT_INIT_ARRAY || Type == SHT_FINI_ARRAY || Type == SHT_PREINIT_ARRAY) return true; @@ -423,8 +423,8 @@ return AIsInterp; typedef typename ELFT::uint uintX_t; - uintX_t AFlags = A->getFlags(); - uintX_t BFlags = B->getFlags(); + uintX_t AFlags = A->Flags; + uintX_t BFlags = B->Flags; // Allocatable sections go first to reduce the total PT_LOAD size and // so debug info doesn't change addresses in actual code. @@ -473,8 +473,8 @@ // them is a p_memsz that is larger than p_filesz. Seeing that it // zeros the end of the PT_LOAD, so that has to correspond to the // nobits sections. - bool AIsNoBits = A->getType() == SHT_NOBITS; - bool BIsNoBits = B->getType() == SHT_NOBITS; + bool AIsNoBits = A->Type == SHT_NOBITS; + bool BIsNoBits = B->Type == SHT_NOBITS; if (AIsNoBits != BIsNoBits) return BIsNoBits; @@ -522,7 +522,7 @@ Last = Sec; if (!First) First = Sec; - H.p_align = std::max(H.p_align, Sec->getAlignment()); + H.p_align = std::max(H.p_align, Sec->Addralign); if (H.p_type == PT_LOAD) Sec->FirstInPtLoad = First; } @@ -699,17 +699,17 @@ template static bool canSharePtLoad(const OutputSectionBase &S1, const OutputSectionBase &S2) { - if (!(S1.getFlags() & SHF_ALLOC) || !(S2.getFlags() & SHF_ALLOC)) + if (!(S1.Flags & SHF_ALLOC) || !(S2.Flags & SHF_ALLOC)) return false; - bool S1IsWrite = S1.getFlags() & SHF_WRITE; - bool S2IsWrite = S2.getFlags() & SHF_WRITE; + bool S1IsWrite = S1.Flags & SHF_WRITE; + bool S2IsWrite = S2.Flags & SHF_WRITE; if (S1IsWrite != S2IsWrite) return false; if (!S1IsWrite) return true; // RO and RX share a PT_LOAD with linker scripts. - return (S1.getFlags() & SHF_EXECINSTR) == (S2.getFlags() & SHF_EXECINSTR); + return (S1.Flags & SHF_EXECINSTR) == (S2.Flags & SHF_EXECINSTR); } template void Writer::sortSections() { @@ -850,7 +850,7 @@ unsigned I = 1; for (OutputSectionBase *Sec : OutputSections) { Sec->SectionIndex = I++; - Sec->setSHName(Out::ShStrTab->addString(Sec->getName())); + Sec->ShName = Out::ShStrTab->addString(Sec->getName()); } // Finalizers fix each section's size. @@ -934,7 +934,7 @@ Add(Out::Plt); if (!Out::EhFrame->empty()) Add(Out::EhFrameHdr); - if (Out::Bss->getSize() > 0) + if (Out::Bss->Size > 0) Add(Out::Bss); } @@ -981,13 +981,13 @@ } template static bool needsPtLoad(OutputSectionBase *Sec) { - if (!(Sec->getFlags() & SHF_ALLOC)) + if (!(Sec->Flags & SHF_ALLOC)) return false; // Don't allocate VA space for TLS NOBITS sections. The PT_TLS PHDR is // responsible for allocating space for them, not the PT_LOAD that // contains the TLS initialization image. - if (Sec->getFlags() & SHF_TLS && Sec->getType() == SHT_NOBITS) + if (Sec->Flags & SHF_TLS && Sec->Type == SHT_NOBITS) return false; return true; } @@ -1035,13 +1035,13 @@ Phdr Note(PT_NOTE, PF_R); Phdr ARMExidx(PT_ARM_EXIDX, PF_R); for (OutputSectionBase *Sec : OutputSections) { - if (!(Sec->getFlags() & SHF_ALLOC)) + if (!(Sec->Flags & SHF_ALLOC)) break; // If we meet TLS section then we create TLS header // and put all TLS sections inside for further use when // assign addresses. - if (Sec->getFlags() & SHF_TLS) + if (Sec->Flags & SHF_TLS) TlsHdr.add(Sec); if (!needsPtLoad(Sec)) @@ -1062,9 +1062,9 @@ if (isRelroSection(Sec)) RelRo.add(Sec); - if (Sec->getType() == SHT_NOTE) + if (Sec->Type == SHT_NOTE) Note.add(Sec); - if (Config->EMachine == EM_ARM && Sec->getType() == SHT_ARM_EXIDX) + if (Config->EMachine == EM_ARM && Sec->Type == SHT_ARM_EXIDX) ARMExidx.add(Sec); } @@ -1148,10 +1148,10 @@ // list, but have them to simplify the code. template void Writer::fixHeaders() { uintX_t BaseVA = ScriptConfig->HasSections ? 0 : Config->ImageBase; - Out::ElfHeader->setVA(BaseVA); - uintX_t Off = Out::ElfHeader->getSize(); - Out::ProgramHeaders->setVA(Off + BaseVA); - Out::ProgramHeaders->setSize(sizeof(Elf_Phdr) * Phdrs.size()); + Out::ElfHeader->Addr = BaseVA; + uintX_t Off = Out::ElfHeader->Size; + Out::ProgramHeaders->Addr = Off + BaseVA; + Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size(); } // Assign VAs (addresses at run-time) to output sections. @@ -1159,7 +1159,7 @@ uintX_t VA = Config->ImageBase + getHeaderSize(); uintX_t ThreadBssOffset = 0; for (OutputSectionBase *Sec : OutputSections) { - uintX_t Alignment = Sec->getAlignment(); + uintX_t Alignment = Sec->Addralign; if (Sec->PageAlign) Alignment = std::max(Alignment, Config->MaxPageSize); @@ -1170,13 +1170,13 @@ // We only assign VAs to allocated sections. if (needsPtLoad(Sec)) { VA = alignTo(VA, Alignment); - Sec->setVA(VA); - VA += Sec->getSize(); - } else if (Sec->getFlags() & SHF_TLS && Sec->getType() == SHT_NOBITS) { + Sec->Addr = VA; + VA += Sec->Size; + } else if (Sec->Flags & SHF_TLS && Sec->Type == SHT_NOBITS) { uintX_t TVA = VA + ThreadBssOffset; TVA = alignTo(TVA, Alignment); - Sec->setVA(TVA); - ThreadBssOffset = TVA - VA + Sec->getSize(); + Sec->Addr = TVA; + ThreadBssOffset = TVA - VA + Sec->Size; } } } @@ -1187,7 +1187,7 @@ // executables without any address adjustment. template static uintX_t getFileAlignment(uintX_t Off, OutputSectionBase *Sec) { - uintX_t Alignment = Sec->getAlignment(); + uintX_t Alignment = Sec->Addralign; if (Sec->PageAlign) Alignment = std::max(Alignment, Config->MaxPageSize); Off = alignTo(Off, Alignment); @@ -1200,26 +1200,26 @@ // If two sections share the same PT_LOAD the file offset is calculated using // this formula: Off2 = Off1 + (VA2 - VA1). if (Sec == First) - return alignTo(Off, Target->MaxPageSize, Sec->getVA()); - return First->getFileOffset() + Sec->getVA() - First->getVA(); + return alignTo(Off, Target->MaxPageSize, Sec->Addr); + return First->Offset + Sec->Addr - First->Addr; } template void setOffset(OutputSectionBase *Sec, uintX_t &Off) { - if (Sec->getType() == SHT_NOBITS) { - Sec->setFileOffset(Off); + if (Sec->Type == SHT_NOBITS) { + Sec->Offset = Off; return; } Off = getFileAlignment(Off, Sec); - Sec->setFileOffset(Off); - Off += Sec->getSize(); + Sec->Offset = Off; + Off += Sec->Size; } template void Writer::assignFileOffsetsBinary() { uintX_t Off = 0; for (OutputSectionBase *Sec : OutputSections) - if (Sec->getFlags() & SHF_ALLOC) + if (Sec->Flags & SHF_ALLOC) setOffset(Sec, Off); FileSize = alignTo(Off, sizeof(uintX_t)); } @@ -1245,12 +1245,12 @@ OutputSectionBase *First = P.First; OutputSectionBase *Last = P.Last; if (First) { - H.p_filesz = Last->getFileOff() - First->getFileOff(); - if (Last->getType() != SHT_NOBITS) - H.p_filesz += Last->getSize(); - H.p_memsz = Last->getVA() + Last->getSize() - First->getVA(); - H.p_offset = First->getFileOff(); - H.p_vaddr = First->getVA(); + H.p_filesz = Last->Offset - First->Offset; + if (Last->Type != SHT_NOBITS) + H.p_filesz += Last->Size; + H.p_memsz = Last->Addr + Last->Size - First->Addr; + H.p_offset = First->Offset; + H.p_vaddr = First->Addr; if (!P.HasLMA) H.p_paddr = First->getLMA(); } @@ -1298,7 +1298,7 @@ template void Writer::fixAbsoluteSymbols() { // __ehdr_start is the location of program headers. if (ElfSym::EhdrStart) - ElfSym::EhdrStart->Value = Out::ProgramHeaders->getVA(); + ElfSym::EhdrStart->Value = Out::ProgramHeaders->Addr; auto Set = [](DefinedRegular *S1, DefinedRegular *S2, uintX_t V) { if (S1) @@ -1382,8 +1382,8 @@ template void Writer::writeSectionsBinary() { uint8_t *Buf = Buffer->getBufferStart(); for (OutputSectionBase *Sec : OutputSections) - if (Sec->getFlags() & SHF_ALLOC) - Sec->writeTo(Buf + Sec->getFileOff()); + if (Sec->Flags & SHF_ALLOC) + Sec->writeTo(Buf + Sec->Offset); } // Convert the .ARM.exidx table entries that use relative PREL31 offsets to @@ -1449,23 +1449,23 @@ // before processing relocations in code-containing sections. Out::Opd = findSection(".opd"); if (Out::Opd) { - Out::OpdBuf = Buf + Out::Opd->getFileOff(); - Out::Opd->writeTo(Buf + Out::Opd->getFileOff()); + Out::OpdBuf = Buf + Out::Opd->Offset; + Out::Opd->writeTo(Buf + Out::Opd->Offset); } for (OutputSectionBase *Sec : OutputSections) if (Sec != Out::Opd && Sec != Out::EhFrameHdr) - Sec->writeTo(Buf + Sec->getFileOff()); + Sec->writeTo(Buf + Sec->Offset); OutputSectionBase *ARMExidx = findSection(".ARM.exidx"); if (!Config->Relocatable) if (auto *OS = dyn_cast_or_null>(ARMExidx)) - sortARMExidx(Buf + OS->getFileOff(), OS->getVA(), OS->getSize()); + sortARMExidx(Buf + OS->Offset, OS->Addr, OS->Size); // The .eh_frame_hdr depends on .eh_frame section contents, therefore // it should be written after .eh_frame is written. if (!Out::EhFrame->empty() && Out::EhFrameHdr) - Out::EhFrameHdr->writeTo(Buf + Out::EhFrameHdr->getFileOff()); + Out::EhFrameHdr->writeTo(Buf + Out::EhFrameHdr->Offset); } template void Writer::writeBuildId() {