[lld] r261761 - ELF: Do not instantiate InputSectionBase::Discarded.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 24 10:33:36 PST 2016
Author: ruiu
Date: Wed Feb 24 12:33:35 2016
New Revision: 261761
URL: http://llvm.org/viewvc/llvm-project?rev=261761&view=rev
Log:
ELF: Do not instantiate InputSectionBase::Discarded.
"Discarded" section is a marker for discarded sections, and we do not
use the instance except for checking its identity. In that sense, it
is just another type of a "null" pointer for InputSectionBase. So,
it doesn't have to be a real instance of InputSectionBase class.
In this patch, we no longer instantiate Discarded section but instead
use -1 as a pointer value. This eliminates a global variable which
needed initialization at startup.
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/MarkLive.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=261761&r1=261760&r2=261761&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Feb 24 12:33:35 2016
@@ -186,18 +186,18 @@ void elf2::ObjectFile<ELFT>::initializeS
const ELFFile<ELFT> &Obj = this->ELFObj;
for (const Elf_Shdr &Sec : Obj.sections()) {
++I;
- if (Sections[I] == &InputSection<ELFT>::Discarded)
+ if (Sections[I] == InputSection<ELFT>::Discarded)
continue;
switch (Sec.sh_type) {
case SHT_GROUP:
- Sections[I] = &InputSection<ELFT>::Discarded;
+ Sections[I] = InputSection<ELFT>::Discarded;
if (ComdatGroups.insert(getShtGroupSignature(Sec)).second)
continue;
for (uint32_t SecIndex : getShtGroupEntries(Sec)) {
if (SecIndex >= Size)
fatal("Invalid section index in group");
- Sections[SecIndex] = &InputSection<ELFT>::Discarded;
+ Sections[SecIndex] = InputSection<ELFT>::Discarded;
}
break;
case SHT_SYMTAB:
@@ -222,7 +222,7 @@ void elf2::ObjectFile<ELFT>::initializeS
// Strictly speaking, a relocation section must be included in the
// group of the section it relocates. However, LLVM 3.3 and earlier
// would fail to do so, so we gracefully handle that case.
- if (RelocatedSection == &InputSection<ELFT>::Discarded)
+ if (RelocatedSection == InputSection<ELFT>::Discarded)
continue;
if (!RelocatedSection)
fatal("Unsupported relocation reference");
@@ -255,7 +255,7 @@ elf2::ObjectFile<ELFT>::createInputSecti
// is controlled only by the command line option (-z execstack) in LLD,
// .note.GNU-stack is ignored.
if (Name == ".note.GNU-stack")
- return &InputSection<ELFT>::Discarded;
+ return InputSection<ELFT>::Discarded;
// A MIPS object file has a special section that contains register
// usage info, which needs to be handled by the linker specially.
@@ -313,7 +313,7 @@ SymbolBody *elf2::ObjectFile<ELFT>::crea
case STB_WEAK:
case STB_GNU_UNIQUE: {
InputSectionBase<ELFT> *Sec = getSection(*Sym);
- if (Sec == &InputSection<ELFT>::Discarded)
+ if (Sec == InputSection<ELFT>::Discarded)
return new (Alloc) UndefinedElf<ELFT>(Name, *Sym);
return new (Alloc) DefinedRegular<ELFT>(Name, *Sym, Sec);
}
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=261761&r1=261760&r2=261761&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Feb 24 12:33:35 2016
@@ -28,14 +28,11 @@ InputSectionBase<ELFT>::InputSectionBase
: Header(Header), File(File), SectionKind(SectionKind) {
// The garbage collector sets sections' Live bits.
// If GC is disabled, all sections are considered live by default.
- // NB: "Discarded" section is initialized at start-up and when it
- // happens Config is still null.
- Live = Config && !Config->GcSections;
+ Live = !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);
+ 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=261761&r1=261760&r2=261761&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Feb 24 12:33:35 2016
@@ -50,7 +50,7 @@ public:
// Returns the size of this section (even if this is a common or BSS.)
size_t getSize() const { return Header->sh_size; }
- static InputSectionBase<ELFT> Discarded;
+ static InputSectionBase<ELFT> *Discarded;
StringRef getSectionName() const;
const Elf_Shdr *getSectionHdr() const { return Header; }
@@ -81,9 +81,8 @@ private:
};
template <class ELFT>
-InputSectionBase<ELFT>
- InputSectionBase<ELFT>::Discarded(nullptr, nullptr,
- InputSectionBase<ELFT>::Regular);
+InputSectionBase<ELFT> *
+ InputSectionBase<ELFT>::Discarded = (InputSectionBase<ELFT> *)-1ULL;
// Usually sections are copied to the output as atomic chunks of data,
// but some special types of sections are split into small pieces of data
Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=261761&r1=261760&r2=261761&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Wed Feb 24 12:33:35 2016
@@ -118,7 +118,7 @@ template <class ELFT> void elf2::markLiv
// script KEEP command.
for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab->getObjectFiles())
for (InputSectionBase<ELFT> *Sec : F->getSections())
- if (Sec && Sec != &InputSection<ELFT>::Discarded)
+ if (Sec && Sec != InputSection<ELFT>::Discarded)
if (isReserved(Sec) || Script->shouldKeep<ELFT>(Sec))
Enqueue(Sec);
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=261761&r1=261760&r2=261761&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Feb 24 12:33:35 2016
@@ -884,7 +884,7 @@ elf2::getLocalRelTarget(const ObjectFile
// the group are not allowed. Unfortunately .eh_frame breaks that rule
// and must be treated specially. For now we just replace the symbol with
// 0.
- if (Section == &InputSection<ELFT>::Discarded || !Section->Live)
+ if (Section == InputSection<ELFT>::Discarded || !Section->Live)
return Addend;
uintX_t Offset = Sym->st_value;
@@ -1147,7 +1147,7 @@ void EHOutputSection<ELFT>::addSectionAu
if (!HasReloc)
fatal("FDE doesn't reference another section");
InputSectionBase<ELFT> *Target = S->getRelocTarget(*RelI);
- if (Target != &InputSection<ELFT>::Discarded && Target->Live) {
+ if (Target != InputSection<ELFT>::Discarded && Target->Live) {
uint32_t CieOffset = Offset + 4 - ID;
auto I = OffsetToIndex.find(CieOffset);
if (I == OffsetToIndex.end())
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=261761&r1=261760&r2=261761&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Feb 24 12:33:35 2016
@@ -515,7 +515,7 @@ static bool shouldKeepInSymtab(const Obj
InputSectionBase<ELFT> *Sec = File.getSection(Sym);
// If sym references a section in a discarded group, don't keep it.
- if (Sec == &InputSection<ELFT>::Discarded)
+ if (Sec == InputSection<ELFT>::Discarded)
return false;
if (Config->DiscardNone)
@@ -752,7 +752,7 @@ void reportDiscarded(InputSectionBase<EL
template <class ELFT>
bool Writer<ELFT>::isDiscarded(InputSectionBase<ELFT> *S) const {
- return !S || !S->Live || S == &InputSection<ELFT>::Discarded ||
+ return !S || S == InputSection<ELFT>::Discarded || !S->Live ||
Script->isDiscarded(S);
}
More information about the llvm-commits
mailing list