diff options
-rw-r--r-- | lld/ELF/OutputSections.cpp | 11 | ||||
-rw-r--r-- | lld/ELF/OutputSections.h | 3 |
2 files changed, 7 insertions, 7 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index bd3bec0579e..9b08ef122f1 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -1328,7 +1328,10 @@ template <class ELFT> StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic) : OutputSectionBase<ELFT>(Name, SHT_STRTAB, Dynamic ? (uintX_t)SHF_ALLOC : 0), - Dynamic(Dynamic) {} + Dynamic(Dynamic) { + // ELF string tables start with a NUL byte, so 1. + this->setSize(1); +} // Adds a string to the string table. If HashIt is true we hash and check for // duplicates. It is optional because the name of global symbols are already @@ -1337,12 +1340,12 @@ StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic) template <class ELFT> unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) { if (HashIt) { - auto R = StringMap.insert(std::make_pair(S, Size)); + auto R = StringMap.insert(std::make_pair(S, this->getSize())); if (!R.second) return R.first->second; } - unsigned Ret = Size; - Size += S.size() + 1; + unsigned Ret = this->getSize(); + this->setSize(this->getSize() + S.size() + 1); Strings.push_back(S); return Ret; } diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index c71c6340fe7..ed503f4a57b 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -524,8 +524,6 @@ public: StringTableSection(StringRef Name, bool Dynamic); unsigned addString(StringRef S, bool HashIt = true); void writeTo(uint8_t *Buf) override; - unsigned getSize() const { return Size; } - void finalize() override { this->Header.sh_size = getSize(); } bool isDynamic() const { return Dynamic; } typename Base::Kind getKind() const override { return Base::StrTable; } static bool classof(const Base *B) { return B->getKind() == Base::StrTable; } @@ -534,7 +532,6 @@ private: const bool Dynamic; llvm::DenseMap<StringRef, unsigned> StringMap; std::vector<StringRef> Strings; - unsigned Size = 1; // ELF string tables start with a NUL byte, so 1. }; template <class ELFT> |