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 // 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. // memory protection by reserving space in the .bss.rel.ro section.
bool IsReadOnly = isReadOnly<ELFT>(SS); bool IsReadOnly = isReadOnly<ELFT>(SS);
BssSection *Sec = make<BssSection>(IsReadOnly ? ".bss.rel.ro" : ".bss"); BssSection *Sec = make<BssSection>(IsReadOnly ? ".bss.rel.ro" : ".bss",
Sec->reserveSpace(SymSize, SS->getAlignment<ELFT>()); SymSize, SS->getAlignment<ELFT>());
if (IsReadOnly) if (IsReadOnly)
InX::BssRelRo->getParent()->addSection(Sec); InX::BssRelRo->getParent()->addSection(Sec);
else else

View File

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

View File

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

View File

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