[lld] r286286 - Store the size the same way as any other OutputSection. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 12:25:44 PST 2016


Author: rafael
Date: Tue Nov  8 14:25:44 2016
New Revision: 286286

URL: http://llvm.org/viewvc/llvm-project?rev=286286&view=rev
Log:
Store the size the same way as any other OutputSection. NFC.

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=286286&r1=286285&r2=286286&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Nov  8 14:25:44 2016
@@ -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>::StringTableSec
 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;
 }

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=286286&r1=286285&r2=286286&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Tue Nov  8 14:25:44 2016
@@ -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>




More information about the llvm-commits mailing list