[lld] r261712 - ELF: Remove InputSectionBase::getAlign and instead add Align member.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 23 16:38:18 PST 2016
Author: ruiu
Date: Tue Feb 23 18:38:18 2016
New Revision: 261712
URL: http://llvm.org/viewvc/llvm-project?rev=261712&view=rev
Log:
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.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/OutputSections.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=261712&r1=261711&r2=261712&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Feb 23 18:38:18 2016
@@ -31,6 +31,11 @@ InputSectionBase<ELFT>::InputSectionBase
// 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<uintX_t>(Header->sh_addralign, 1);
}
template <class ELFT> StringRef InputSectionBase<ELFT>::getSectionName() const {
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=261712&r1=261711&r2=261712&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Feb 23 18:38:18 2016
@@ -42,6 +42,7 @@ public:
InputSectionBase(ObjectFile<ELFT> *File, const Elf_Shdr *Header,
Kind SectionKind);
OutputSectionBase<ELFT> *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<ELFT> *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<uintX_t>(Header->sh_addralign, 1);
- }
-
uintX_t getOffset(const Elf_Sym &Sym);
// Translate an offset in the input section to an offset in the output
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=261712&r1=261711&r2=261712&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Feb 23 18:38:18 2016
@@ -737,11 +737,10 @@ void OutputSection<ELFT>::addSection(Inp
auto *S = cast<InputSection<ELFT>>(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 <class ELFT> void OutputSection<ELFT>::reassignOffsets() {
uintX_t Off = 0;
for (InputSection<ELFT> *S : Sections) {
- Off = alignTo(Off, S->getAlign());
+ Off = alignTo(Off, S->Align);
S->OutSecOff = Off;
Off += S->getSize();
}
@@ -1098,7 +1097,7 @@ void EHOutputSection<ELFT>::addSectionAu
const endianness E = ELFT::TargetEndianness;
S->OutSec = this;
- this->updateAlign(S->getAlign());
+ this->updateAlign(S->Align);
Sections.push_back(S);
ArrayRef<uint8_t> SecData = S->getSectionData();
@@ -1256,7 +1255,7 @@ template <class ELFT>
void MergeOutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) {
auto *S = cast<MergeInputSection<ELFT>>(C);
S->OutSec = this;
- this->updateAlign(S->getAlign());
+ this->updateAlign(S->Align);
ArrayRef<uint8_t> D = S->getSectionData();
StringRef Data((const char *)D.data(), D.size());
More information about the llvm-commits
mailing list