diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 5bd21dde25d1..86d5d5e37f47 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -525,8 +525,8 @@ template 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(SS); - BssSection *Sec = make(IsReadOnly ? ".bss.rel.ro" : ".bss"); - Sec->reserveSpace(SymSize, SS->getAlignment()); + BssSection *Sec = make(IsReadOnly ? ".bss.rel.ro" : ".bss", + SymSize, SS->getAlignment()); if (IsReadOnly) InX::BssRelRo->getParent()->addSection(Sec); else diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 21bd825a2386..a07ac8c371eb 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -67,10 +67,9 @@ template void elf::createCommonSections() { continue; // Create a synthetic section for the common data. - auto *Section = make("COMMON"); + auto *Section = make("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 Buf) { diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index b789cd5cac0d..99ad038fa521 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -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 { diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 7deb6b3d57f8..3fbe22ad7b07 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -290,9 +290,9 @@ template void Writer::createSyntheticSections() { Add(InX::BuildId); } - InX::Bss = make(".bss"); + InX::Bss = make(".bss", 0, 1); Add(InX::Bss); - InX::BssRelRo = make(".bss.rel.ro"); + InX::BssRelRo = make(".bss.rel.ro", 0, 1); Add(InX::BssRelRo); // Add MIPS-specific sections.