This is also a preparation for ICF.
llvm-svn: 261711
InputSectionBase<ELFT>::InputSectionBase(ObjectFile<ELFT> *File,
const Elf_Shdr *Header,
Kind SectionKind)
- : Header(Header), File(File), SectionKind(SectionKind) {}
+ : 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;
+}
template <class ELFT> StringRef InputSectionBase<ELFT>::getSectionName() const {
ErrorOr<StringRef> Name = File->getObj().getSectionName(this->Header);
OutputSectionBase<ELFT> *OutSec = nullptr;
// Used for garbage collection.
- // Live bit makes sense only when Config->GcSections is true.
- bool isLive() const { return !Config->GcSections || Live; }
bool Live = false;
// Returns the size of this section (even if this is a common or BSS.)
// 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->isLive())
+ 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->isLive()) {
+ if (Target != &InputSection<ELFT>::Discarded && Target->Live) {
uint32_t CieOffset = Offset + 4 - ID;
auto I = OffsetToIndex.find(CieOffset);
if (I == OffsetToIndex.end())
continue;
if (Sym.st_shndx != SHN_ABS) {
InputSectionBase<ELFT> *Section = F->getSection(Sym);
- if (!Section->isLive())
+ if (!Section->Live)
continue;
}
++Out<ELFT>::SymTab->NumLocals;
template <class ELFT>
void reportDiscarded(InputSectionBase<ELFT> *IS,
const std::unique_ptr<ObjectFile<ELFT>> &File) {
- if (!Config->PrintGcSections || !IS || IS->isLive())
+ if (!Config->PrintGcSections || !IS || IS->Live)
return;
llvm::errs() << "removing unused section from '" << IS->getSectionName()
<< "' in file '" << File->getName() << "'\n";
template <class ELFT>
bool Writer<ELFT>::isDiscarded(InputSectionBase<ELFT> *S) const {
- return !S || !S->isLive() || S == &InputSection<ELFT>::Discarded ||
+ return !S || !S->Live || S == &InputSection<ELFT>::Discarded ||
Script->isDiscarded(S);
}
if (&D->Sym == &ElfSym<ELFT>::Ignored)
return false;
// Exclude symbols pointing to garbage-collected sections.
- if (D->Section && !D->Section->isLive())
+ if (D->Section && !D->Section->Live)
return false;
}
return true;