Size = NumEntries * Config->Wordsize;
}
-bool GotSection::empty() const {
+bool GotSection::isNeeded() const {
// We need to emit a GOT even if it's empty if there's a relocation that is
// relative to GOT(such as GOTOFFREL).
- return NumEntries == 0 && !HasGotOffRel;
+ return NumEntries || HasGotOffRel;
}
void GotSection::writeTo(uint8_t *Buf) {
}
}
-bool MipsGotSection::empty() const {
+bool MipsGotSection::isNeeded() const {
// We add the .got section to the result for dynamic MIPS target because
// its address and properties are mentioned in the .dynamic section.
- return Config->Relocatable;
+ return !Config->Relocatable;
}
uint64_t MipsGotSection::getGp(const InputFile *F) const {
}
}
-bool GotPltSection::empty() const {
+bool GotPltSection::isNeeded() const {
// We need to emit GOTPLT even if it's empty if there's a relocation relative
// to it.
- return Entries.empty() && !HasGotPltOffRel;
+ return !Entries.empty() || HasGotPltOffRel;
}
static StringRef getIgotPltName() {
if (OutputSection *Sec = In.DynStrTab->getParent())
this->Link = Sec->SectionIndex;
- if (!In.RelaDyn->empty()) {
+ if (In.RelaDyn->isNeeded()) {
addInSec(In.RelaDyn->DynamicTag, In.RelaDyn);
addSize(In.RelaDyn->SizeDynamicTag, In.RelaDyn->getParent());
}
// Glink dynamic tag is required by the V2 abi if the plt section isn't empty.
- if (Config->EMachine == EM_PPC64 && !In.Plt->empty()) {
+ if (Config->EMachine == EM_PPC64 && In.Plt->isNeeded()) {
// The Glink tag points to 32 bytes before the first lazy symbol resolution
// stub, which starts directly after the header.
Entries.push_back({DT_PPC64_GLINK, [=] {
}
}
-bool SymtabShndxSection::empty() const {
+bool SymtabShndxSection::isNeeded() const {
// SHT_SYMTAB can hold symbols with section indices values up to
// SHN_LORESERVE. If we need more, we want to use extension SHT_SYMTAB_SHNDX
// section. Problem is that we reveal the final section indices a bit too
for (BaseCommand *Base : Script->SectionCommands)
if (isa<OutputSection>(Base))
++Size;
- return Size < SHN_LORESERVE;
+ return Size >= SHN_LORESERVE;
}
void SymtabShndxSection::finalizeContents() {
}
}
-bool GdbIndexSection::empty() const { return Chunks.empty(); }
+bool GdbIndexSection::isNeeded() const { return !Chunks.empty(); }
EhFrameHeader::EhFrameHeader()
: SyntheticSection(SHF_ALLOC, SHT_PROGBITS, 4, ".eh_frame_hdr") {}
return 12 + In.EhFrame->NumFdes * 8;
}
-bool EhFrameHeader::empty() const { return In.EhFrame->empty(); }
+bool EhFrameHeader::isNeeded() const { return In.EhFrame->isNeeded(); }
VersionDefinitionSection::VersionDefinitionSection()
: SyntheticSection(SHF_ALLOC, SHT_GNU_verdef, sizeof(uint32_t),
}
}
-bool VersionTableSection::empty() const {
- return !In.VerDef && In.VerNeed->empty();
+bool VersionTableSection::isNeeded() const {
+ return In.VerDef || In.VerNeed->isNeeded();
}
VersionNeedBaseSection::VersionNeedBaseSection()
return Size;
}
-template <class ELFT> bool VersionNeedSection<ELFT>::empty() const {
- return getNeedNum() == 0;
+template <class ELFT> bool VersionNeedSection<ELFT>::isNeeded() const {
+ return getNeedNum() != 0;
}
void MergeSyntheticSection::addSection(MergeInputSection *MS) {
}
}
-bool PPC64LongBranchTargetSection::empty() const {
+bool PPC64LongBranchTargetSection::isNeeded() const {
// `removeUnusedSyntheticSections()` is called before thunk allocation which
// is too early to determine if this section will be empty or not. We need
// Finalized to keep the section alive until after thunk creation. Finalized
// only gets set to true once `finalizeSections()` is called after thunk
// creation. Becuase of this, if we don't create any long-branch thunks we end
// up with an empty .branch_lt section in the binary.
- return Finalized && Entries.empty();
+ return !Finalized || !Entries.empty();
}
InStruct elf::In;
// If the section has the SHF_ALLOC flag and the size may be changed if
// thunks are added, update the section size.
virtual bool updateAllocSize() { return false; }
- virtual bool empty() const { return false; }
+ virtual bool isNeeded() const { return true; }
static bool classof(const SectionBase *D) {
return D->kind() == InputSectionBase::Synthetic;
EhFrameSection();
void writeTo(uint8_t *Buf) override;
void finalizeContents() override;
- bool empty() const override { return Sections.empty(); }
+ bool isNeeded() const override { return !Sections.empty(); }
size_t getSize() const override { return Size; }
template <class ELFT> void addSection(InputSectionBase *S);
GotSection();
size_t getSize() const override { return Size; }
void finalizeContents() override;
- bool empty() const override;
+ bool isNeeded() const override;
void writeTo(uint8_t *Buf) override;
void addEntry(Symbol &Sym);
void writeTo(uint8_t *) override {
llvm_unreachable("unexpected writeTo() call for SHT_NOBITS section");
}
- bool empty() const override { return getSize() == 0; }
+ bool isNeeded() const override { return Size != 0; }
size_t getSize() const override { return Size; }
static bool classof(const SectionBase *S) { return S->Bss; }
size_t getSize() const override { return Size; }
bool updateAllocSize() override;
void finalizeContents() override;
- bool empty() const override;
+ bool isNeeded() const override;
// Join separate GOTs built for each input file to generate
// primary and optional multiple secondary GOTs.
void addEntry(Symbol &Sym);
size_t getSize() const override;
void writeTo(uint8_t *Buf) override;
- bool empty() const override;
+ bool isNeeded() const override;
// Flag to force GotPlt to be in output if we have relocations
// that relies on its address.
void addEntry(Symbol &Sym);
size_t getSize() const override;
void writeTo(uint8_t *Buf) override;
- bool empty() const override { return Entries.empty(); }
+ bool isNeeded() const override { return !Entries.empty(); }
private:
std::vector<const Symbol *> Entries;
uint64_t OffsetInSec, Symbol *Sym, int64_t Addend, RelExpr Expr,
RelType Type);
void addReloc(const DynamicReloc &Reloc);
- bool empty() const override { return Relocs.empty(); }
+ bool isNeeded() const override { return !Relocs.empty(); }
size_t getSize() const override { return Relocs.size() * this->Entsize; }
size_t getRelativeRelocCount() const { return NumRelativeRelocs; }
void finalizeContents() override;
class RelrBaseSection : public SyntheticSection {
public:
RelrBaseSection();
- bool empty() const override { return Relocs.empty(); }
+ bool isNeeded() const override { return !Relocs.empty(); }
std::vector<RelativeReloc> Relocs;
};
void writeTo(uint8_t *Buf) override;
size_t getSize() const override;
- bool empty() const override;
+ bool isNeeded() const override;
void finalizeContents() override;
};
PltSection(bool IsIplt);
void writeTo(uint8_t *Buf) override;
size_t getSize() const override;
- bool empty() const override { return Entries.empty(); }
+ bool isNeeded() const override { return !Entries.empty(); }
void addSymbols();
template <class ELFT> void addEntry(Symbol &Sym);
template <typename ELFT> static GdbIndexSection *create();
void writeTo(uint8_t *Buf) override;
size_t getSize() const override { return Size; }
- bool empty() const override;
+ bool isNeeded() const override;
private:
struct GdbIndexHeader {
void write();
void writeTo(uint8_t *Buf) override;
size_t getSize() const override;
- bool empty() const override;
+ bool isNeeded() const override;
};
// For more information about .gnu.version and .gnu.version_r see:
void finalizeContents() override;
size_t getSize() const override;
void writeTo(uint8_t *Buf) override;
- bool empty() const override;
+ bool isNeeded() const override;
};
class VersionNeedBaseSection : public SyntheticSection {
void writeTo(uint8_t *Buf) override;
size_t getSize() const override;
size_t getNeedNum() const override { return Needed.size(); }
- bool empty() const override;
+ bool isNeeded() const override;
};
// MergeSyntheticSection is a class that allows us to put mergeable sections
ARMExidxSyntheticSection();
size_t getSize() const override { return Size; }
void writeTo(uint8_t *Buf) override;
- bool empty() const override { return Empty; }
+ bool isNeeded() const override { return !Empty; }
// Sort and remove duplicate entries.
void finalizeContents() override;
InputSection *getLinkOrderDep() const;
void addEntry(Symbol &Sym);
size_t getSize() const override;
void writeTo(uint8_t *Buf) override;
- bool empty() const override;
+ bool isNeeded() const override;
void finalizeContents() override { Finalized = true; }
private:
}
// .rela_iplt_{start,end} mark the start and the end of .rela.plt section.
- if (ElfSym::RelaIpltStart && !In.RelaIplt->empty()) {
+ if (ElfSym::RelaIpltStart && In.RelaIplt->isNeeded()) {
ElfSym::RelaIpltStart->Section = In.RelaIplt;
ElfSym::RelaIpltEnd->Section = In.RelaIplt;
ElfSym::RelaIpltEnd->Value = In.RelaIplt->getSize();
}
static void finalizeSynthetic(SyntheticSection *Sec) {
- if (Sec && !Sec->empty() && Sec->getParent())
+ if (Sec && Sec->isNeeded() && Sec->getParent())
Sec->finalizeContents();
}
if (!SS)
return;
OutputSection *OS = SS->getParent();
- if (!OS || !SS->empty())
+ if (!OS || SS->isNeeded())
continue;
// If we reach here, then SS is an unused synthetic section and we want to
addIRelativeRelocs();
- if (In.Plt && !In.Plt->empty())
+ if (In.Plt && In.Plt->isNeeded())
In.Plt->addSymbols();
- if (In.Iplt && !In.Iplt->empty())
+ if (In.Iplt && In.Iplt->isNeeded())
In.Iplt->addSymbols();
if (!Config->AllowShlibUndefined) {
Ret.push_back(RelRo);
// PT_GNU_EH_FRAME is a special section pointing on .eh_frame_hdr.
- if (!In.EhFrame->empty() && In.EhFrameHdr && In.EhFrame->getParent() &&
+ if (In.EhFrame->isNeeded() && In.EhFrameHdr && In.EhFrame->getParent() &&
In.EhFrameHdr->getParent())
AddHdr(PT_GNU_EH_FRAME, In.EhFrameHdr->getParent()->getPhdrFlags())
->add(In.EhFrameHdr->getParent());