[lld] r285079 - Delete getSectionHdr.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 25 09:14:25 PDT 2016
Author: rafael
Date: Tue Oct 25 11:14:25 2016
New Revision: 285079
URL: http://llvm.org/viewvc/llvm-project?rev=285079&view=rev
Log:
Delete getSectionHdr.
We were fairly inconsistent as to what information should be accessed
with getSectionHdr and what information (like alignment) was stored
elsewhere.
Now all section info has a dedicated getter. The code is also a bit
more compact.
Modified:
lld/trunk/ELF/ICF.cpp
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/MarkLive.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=285079&r1=285078&r2=285079&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Tue Oct 25 11:14:25 2016
@@ -119,7 +119,7 @@ private:
// Returns a hash value for S. Note that the information about
// relocation targets is not included in the hash value.
template <class ELFT> uint64_t ICF<ELFT>::getHash(InputSection<ELFT> *S) {
- uint64_t Flags = S->getSectionHdr()->sh_flags;
+ uint64_t Flags = S->getFlags();
uint64_t H = hash_combine(Flags, S->getSize());
for (const Elf_Shdr *Rel : S->RelocSections)
H = hash_combine(H, (uint64_t)Rel->sh_size);
@@ -141,8 +141,7 @@ template <class ELFT> bool ICF<ELFT>::is
if (Name == ".init" || Name == ".fini")
return false;
- const Elf_Shdr &H = *S->getSectionHdr();
- return (H.sh_flags & SHF_ALLOC) && (~H.sh_flags & SHF_WRITE);
+ return (S->getFlags() & SHF_ALLOC) && !(S->getFlags() & SHF_WRITE);
}
template <class ELFT>
@@ -231,8 +230,8 @@ bool ICF<ELFT>::equalsConstant(const Inp
}
}
- return A->getSectionHdr()->sh_flags == B->getSectionHdr()->sh_flags &&
- A->getSize() == B->getSize() && A->Data == B->Data;
+ return A->getFlags() == B->getFlags() && A->getSize() == B->getSize() &&
+ A->Data == B->Data;
}
template <class ELFT>
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=285079&r1=285078&r2=285079&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Oct 25 11:14:25 2016
@@ -171,9 +171,8 @@ InputSectionBase<ELFT>::getOffset(const
template <class ELFT>
InputSectionBase<ELFT> *InputSectionBase<ELFT>::getLinkOrderDep() const {
- const Elf_Shdr *Hdr = getSectionHdr();
- if ((Hdr->sh_flags & SHF_LINK_ORDER) && Hdr->sh_link != 0)
- return getFile()->getSections()[Hdr->sh_link];
+ if ((getFlags() & SHF_LINK_ORDER) && getLink() != 0)
+ return getFile()->getSections()[getLink()];
return nullptr;
}
@@ -589,7 +588,7 @@ std::vector<SectionPiece>
MergeInputSection<ELFT>::splitStrings(ArrayRef<uint8_t> Data, size_t EntSize) {
std::vector<SectionPiece> V;
size_t Off = 0;
- bool IsAlloca = this->getSectionHdr()->sh_flags & SHF_ALLOC;
+ bool IsAlloca = this->getFlags() & SHF_ALLOC;
while (!Data.empty()) {
size_t End = findNull(Data, EntSize);
if (End == StringRef::npos)
@@ -620,7 +619,7 @@ MergeInputSection<ELFT>::splitNonStrings
std::vector<SectionPiece> V;
size_t Size = Data.size();
assert((Size % EntSize) == 0);
- bool IsAlloca = this->getSectionHdr()->sh_flags & SHF_ALLOC;
+ bool IsAlloca = this->getFlags() & SHF_ALLOC;
for (unsigned I = 0, N = Size; I != N; I += EntSize) {
Hashes.push_back(hash_value(toStringRef(Data.slice(I, EntSize))));
V.emplace_back(I, !IsAlloca);
@@ -642,7 +641,7 @@ template <class ELFT> void MergeInputSec
else
this->Pieces = splitNonStrings(Data, EntSize);
- if (Config->GcSections && (this->getSectionHdr()->sh_flags & SHF_ALLOC))
+ if (Config->GcSections && (this->getFlags() & SHF_ALLOC))
for (uintX_t Off : LiveOffsets)
this->getSectionPiece(Off)->Live = true;
}
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=285079&r1=285078&r2=285079&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Oct 25 11:14:25 2016
@@ -101,7 +101,10 @@ public:
static InputSectionBase<ELFT> Discarded;
- const Elf_Shdr *getSectionHdr() const { return Header; }
+ uintX_t getFlags() const { return Header->sh_flags; }
+ uint32_t getType() const { return Header->sh_type; }
+ uintX_t getEntsize() const { return Header->sh_entsize; }
+ uint32_t getLink() const { return Header->sh_link; }
ObjectFile<ELFT> *getFile() const { return File; }
uintX_t getOffset(const DefinedRegular<ELFT> &Sym) const;
InputSectionBase *getLinkOrderDep() const;
@@ -152,7 +155,7 @@ public:
// Mark the piece at a given offset live. Used by GC.
void markLiveAt(uintX_t Offset) {
- assert(this->getSectionHdr()->sh_flags & llvm::ELF::SHF_ALLOC);
+ assert(this->getFlags() & llvm::ELF::SHF_ALLOC);
LiveOffsets.insert(Offset);
}
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=285079&r1=285078&r2=285079&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Oct 25 11:14:25 2016
@@ -156,7 +156,7 @@ static bool matchConstraints(ArrayRef<In
return true;
bool IsRW = llvm::any_of(Sections, [=](InputSectionData *Sec2) {
auto *Sec = static_cast<InputSectionBase<ELFT> *>(Sec2);
- return Sec->getSectionHdr()->sh_flags & SHF_WRITE;
+ return Sec->getFlags() & SHF_WRITE;
});
return (IsRW && Kind == ConstraintKind::ReadWrite) ||
(!IsRW && Kind == ConstraintKind::ReadOnly);
@@ -268,13 +268,12 @@ static SectionKey<ELFT::Is64Bits> create
// Fortunately, creating symbols in the middle of a merge section is not
// supported by bfd or gold, so we can just create multiple section in that
// case.
- const typename ELFT::Shdr *H = C->getSectionHdr();
typedef typename ELFT::uint uintX_t;
- uintX_t Flags = H->sh_flags & (SHF_MERGE | SHF_STRINGS);
+ uintX_t Flags = C->getFlags() & (SHF_MERGE | SHF_STRINGS);
uintX_t Alignment = 0;
if (isa<MergeInputSection<ELFT>>(C))
- Alignment = std::max(H->sh_addralign, H->sh_entsize);
+ Alignment = std::max<uintX_t>(C->Alignment, C->getEntsize());
return SectionKey<ELFT::Is64Bits>{OutsecName, /*Type*/ 0, Flags, Alignment};
}
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=285079&r1=285078&r2=285079&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Tue Oct 25 11:14:25 2016
@@ -135,7 +135,7 @@ scanEhFrameSection(EhInputSection<ELFT>
ResolvedReloc<ELFT> R = resolveReloc(EH, Rels[I2]);
if (!R.Sec || R.Sec == &InputSection<ELFT>::Discarded)
continue;
- if (R.Sec->getSectionHdr()->sh_flags & SHF_EXECINSTR)
+ if (R.Sec->getFlags() & SHF_EXECINSTR)
continue;
Enqueue({R.Sec, 0});
}
@@ -164,14 +164,14 @@ scanEhFrameSection(EhInputSection<ELFT>
// 1) Sections used by the loader (.init, .fini, .ctors, .dtors or .jcr)
// 2) Non-allocatable sections which typically contain debugging information
template <class ELFT> static bool isReserved(InputSectionBase<ELFT> *Sec) {
- switch (Sec->getSectionHdr()->sh_type) {
+ switch (Sec->getType()) {
case SHT_FINI_ARRAY:
case SHT_INIT_ARRAY:
case SHT_NOTE:
case SHT_PREINIT_ARRAY:
return true;
default:
- if (!(Sec->getSectionHdr()->sh_flags & SHF_ALLOC))
+ if (!(Sec->getFlags() & SHF_ALLOC))
return true;
// We do not want to reclaim sections if they can be referred
@@ -201,7 +201,7 @@ template <class ELFT> void elf::markLive
return;
// We don't gc non alloc sections.
- if (!(R.Sec->getSectionHdr()->sh_flags & SHF_ALLOC))
+ if (!(R.Sec->getFlags() & SHF_ALLOC))
return;
// Usually, a whole section is marked as live or dead, but in mergeable
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=285079&r1=285078&r2=285079&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Oct 25 11:14:25 2016
@@ -966,8 +966,8 @@ void OutputSection<ELFT>::addSection(Inp
this->updateAlignment(S->Alignment);
// 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->getSectionHdr()->sh_flags & SHF_MERGE))
- this->Header.sh_entsize = S->getSectionHdr()->sh_entsize;
+ if (Config->Relocatable && (S->getFlags() & SHF_MERGE))
+ this->Header.sh_entsize = S->getEntsize();
}
// This function is called after we sort input sections
@@ -1304,7 +1304,7 @@ void MergeOutputSection<ELFT>::addSectio
auto *Sec = cast<MergeInputSection<ELFT>>(C);
Sec->OutSec = this;
this->updateAlignment(Sec->Alignment);
- this->Header.sh_entsize = Sec->getSectionHdr()->sh_entsize;
+ this->Header.sh_entsize = Sec->getEntsize();
Sections.push_back(Sec);
auto HashI = Sec->Hashes.begin();
@@ -1896,13 +1896,12 @@ void MipsAbiFlagsOutputSection<ELFT>::ad
template <class ELFT>
static typename ELFT::uint getOutFlags(InputSectionBase<ELFT> *S) {
- return S->getSectionHdr()->sh_flags & ~SHF_GROUP & ~SHF_COMPRESSED;
+ return S->getFlags() & ~SHF_GROUP & ~SHF_COMPRESSED;
}
template <class ELFT>
static SectionKey<ELFT::Is64Bits> createKey(InputSectionBase<ELFT> *C,
StringRef OutsecName) {
- const typename ELFT::Shdr *H = C->getSectionHdr();
typedef typename ELFT::uint uintX_t;
uintX_t Flags = getOutFlags(C);
@@ -1914,10 +1913,10 @@ static SectionKey<ELFT::Is64Bits> create
// output sections for them to allow merging at final linking stage.
uintX_t Alignment = 0;
if (isa<MergeInputSection<ELFT>>(C) ||
- (Config->Relocatable && (H->sh_flags & SHF_MERGE)))
- Alignment = std::max(H->sh_addralign, H->sh_entsize);
+ (Config->Relocatable && (C->getFlags() & SHF_MERGE)))
+ Alignment = std::max<uintX_t>(C->Alignment, C->getEntsize());
- uint32_t Type = H->sh_type;
+ uint32_t Type = C->getType();
return SectionKey<ELFT::Is64Bits>{OutsecName, Type, Flags, Alignment};
}
@@ -1940,7 +1939,7 @@ OutputSectionFactory<ELFT>::create(const
return {Sec, false};
}
- uint32_t Type = C->getSectionHdr()->sh_type;
+ uint32_t Type = C->getType();
switch (C->kind()) {
case InputSectionBase<ELFT>::Regular:
Sec = new OutputSection<ELFT>(Key.Name, Type, Flags);
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=285079&r1=285078&r2=285079&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Oct 25 11:14:25 2016
@@ -132,7 +132,7 @@ static unsigned handleTlsRelocation(uint
InputSectionBase<ELFT> &C,
typename ELFT::uint Offset,
typename ELFT::uint Addend, RelExpr Expr) {
- if (!(C.getSectionHdr()->sh_flags & SHF_ALLOC))
+ if (!(C.getFlags() & SHF_ALLOC))
return 0;
if (!Body.isTls())
@@ -558,7 +558,7 @@ template <class ELFT, class RelTy>
static void scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
typedef typename ELFT::uint uintX_t;
- bool IsWrite = C.getSectionHdr()->sh_flags & SHF_WRITE;
+ bool IsWrite = C.getFlags() & SHF_WRITE;
auto AddDyn = [=](const DynamicReloc<ELFT> &Reloc) {
Out<ELFT>::RelaDyn->addReloc(Reloc);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=285079&r1=285078&r2=285079&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Oct 25 11:14:25 2016
@@ -345,7 +345,7 @@ static bool shouldKeepInSymtab(InputSect
if (Config->Discard == DiscardPolicy::Locals)
return false;
- return !Sec || !(Sec->getSectionHdr()->sh_flags & SHF_MERGE);
+ return !Sec || !(Sec->getFlags() & SHF_MERGE);
}
template <class ELFT> static bool includeInSymtab(const SymbolBody &B) {
@@ -675,7 +675,7 @@ void Writer<ELFT>::forEachRelSec(
// creating GOT, PLT, copy relocations, etc.
// Note that relocations for non-alloc sections are directly
// processed by InputSection::relocateNonAlloc.
- if (!(IS->getSectionHdr()->sh_flags & SHF_ALLOC))
+ if (!(IS->getFlags() & SHF_ALLOC))
continue;
if (auto *S = dyn_cast<InputSection<ELFT>>(IS)) {
for (const Elf_Shdr *RelSec : S->RelocSections)
More information about the llvm-commits
mailing list