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:
// 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");
// 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.
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);
}
: 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 {
// 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; }
};
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
// 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);
// 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;
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())
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)
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);
}