Remove BssSection::reserveSpace().

We no longer call reserveSpace more than once, so it can be merged with
its constructor.

llvm-svn: 314867
This commit is contained in:
Rui Ueyama 2017-10-04 00:21:17 +00:00
parent 50d7b36f5e
commit 732f4e2778
4 changed files with 10 additions and 16 deletions

View File

@ -525,8 +525,8 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol *SS) {
// See if this symbol is in a read-only segment. If so, preserve the symbol's
// memory protection by reserving space in the .bss.rel.ro section.
bool IsReadOnly = isReadOnly<ELFT>(SS);
BssSection *Sec = make<BssSection>(IsReadOnly ? ".bss.rel.ro" : ".bss");
Sec->reserveSpace(SymSize, SS->getAlignment<ELFT>());
BssSection *Sec = make<BssSection>(IsReadOnly ? ".bss.rel.ro" : ".bss",
SymSize, SS->getAlignment<ELFT>());
if (IsReadOnly)
InX::BssRelRo->getParent()->addSection(Sec);
else

View File

@ -67,10 +67,9 @@ template <class ELFT> void elf::createCommonSections() {
continue;
// Create a synthetic section for the common data.
auto *Section = make<BssSection>("COMMON");
auto *Section = make<BssSection>("COMMON", Sym->Size, Sym->Alignment);
Section->File = Sym->getFile();
Section->Live = !Config->GcSections;
Section->reserveSpace(Sym->Size, Sym->Alignment);
InputSections.push_back(Section);
// Replace all DefinedCommon symbols with DefinedRegular symbols so that we
@ -361,15 +360,11 @@ void BuildIdSection::computeHash(
HashFn(HashBuf, Hashes);
}
BssSection::BssSection(StringRef Name)
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_NOBITS, 0, Name) {}
size_t BssSection::reserveSpace(uint64_t Size, uint32_t Alignment) {
BssSection::BssSection(StringRef Name, uint64_t Size, uint32_t Alignment)
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_NOBITS, Alignment, Name) {
if (OutputSection *Sec = getParent())
Sec->updateAlignment(Alignment);
this->Size = alignTo(this->Size, Alignment) + Size;
this->Alignment = std::max(this->Alignment, Alignment);
return this->Size - Size;
this->Size = Size;
}
void BuildIdSection::writeBuildId(ArrayRef<uint8_t> Buf) {

View File

@ -157,14 +157,13 @@ private:
// respectively.
class BssSection final : public SyntheticSection {
public:
BssSection(StringRef Name);
BssSection(StringRef Name, uint64_t Size, uint32_t Alignment);
void writeTo(uint8_t *) override {}
bool empty() const override { return getSize() == 0; }
size_t reserveSpace(uint64_t Size, uint32_t Alignment);
size_t getSize() const override { return Size; }
private:
uint64_t Size = 0;
uint64_t Size;
};
class MipsGotSection final : public SyntheticSection {

View File

@ -290,9 +290,9 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
Add(InX::BuildId);
}
InX::Bss = make<BssSection>(".bss");
InX::Bss = make<BssSection>(".bss", 0, 1);
Add(InX::Bss);
InX::BssRelRo = make<BssSection>(".bss.rel.ro");
InX::BssRelRo = make<BssSection>(".bss.rel.ro", 0, 1);
Add(InX::BssRelRo);
// Add MIPS-specific sections.