From 5ac589171da63e78b438781542f28f3ac68987b2 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 24 Feb 2016 00:38:18 +0000 Subject: [PATCH] ELF: Remove InputSectionBase::getAlign and instead add Align member. This is a preparation for ICF. If we merge two sections, we want to align the merged section at the largest alignment requirement. That means we want to update the alignment value, which was impossible before this patch because Header is a const value. llvm-svn: 261712 --- lld/ELF/InputSection.cpp | 5 +++++ lld/ELF/InputSection.h | 9 +-------- lld/ELF/OutputSections.cpp | 11 +++++------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 4e96fb3..7b3b8b8 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -31,6 +31,11 @@ InputSectionBase::InputSectionBase(ObjectFile *File, // NB: "Discarded" section is initialized at start-up and when it // happens Config is still null. Live = Config && !Config->GcSections; + + // The ELF spec states that a value of 0 means the section has + // no alignment constraits. + if (Header) + Align = std::max(Header->sh_addralign, 1); } template StringRef InputSectionBase::getSectionName() const { diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 7b98f8b..2faec9a 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -42,6 +42,7 @@ public: InputSectionBase(ObjectFile *File, const Elf_Shdr *Header, Kind SectionKind); OutputSectionBase *OutSec = nullptr; + uint32_t Align = 1; // Used for garbage collection. bool Live = false; @@ -54,14 +55,6 @@ public: StringRef getSectionName() const; const Elf_Shdr *getSectionHdr() const { return Header; } ObjectFile *getFile() const { return File; } - - // The writer sets and uses the addresses. - uintX_t getAlign() { - // The ELF spec states that a value of 0 means the section has no alignment - // constraits. - return std::max(Header->sh_addralign, 1); - } - uintX_t getOffset(const Elf_Sym &Sym); // Translate an offset in the input section to an offset in the output diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index f2b88db..7f225ca 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -737,11 +737,10 @@ void OutputSection::addSection(InputSectionBase *C) { auto *S = cast>(C); Sections.push_back(S); S->OutSec = this; - uint32_t Align = S->getAlign(); - this->updateAlign(Align); + this->updateAlign(S->Align); uintX_t Off = this->Header.sh_size; - Off = alignTo(Off, Align); + Off = alignTo(Off, S->Align); S->OutSecOff = Off; Off += S->getSize(); this->Header.sh_size = Off; @@ -765,7 +764,7 @@ static int getPriority(StringRef S) { template void OutputSection::reassignOffsets() { uintX_t Off = 0; for (InputSection *S : Sections) { - Off = alignTo(Off, S->getAlign()); + Off = alignTo(Off, S->Align); S->OutSecOff = Off; Off += S->getSize(); } @@ -1098,7 +1097,7 @@ void EHOutputSection::addSectionAux( const endianness E = ELFT::TargetEndianness; S->OutSec = this; - this->updateAlign(S->getAlign()); + this->updateAlign(S->Align); Sections.push_back(S); ArrayRef SecData = S->getSectionData(); @@ -1256,7 +1255,7 @@ template void MergeOutputSection::addSection(InputSectionBase *C) { auto *S = cast>(C); S->OutSec = this; - this->updateAlign(S->getAlign()); + this->updateAlign(S->Align); ArrayRef D = S->getSectionData(); StringRef Data((const char *)D.data(), D.size()); -- 2.7.4