[lld] r234396 - [ELF] Do not save a reference to GOTFile instance in xxxWriter classes

Simon Atanasyan simon at atanasyan.com
Wed Apr 8 02:19:45 PDT 2015


Author: atanasyan
Date: Wed Apr  8 04:19:45 2015
New Revision: 234396

URL: http://llvm.org/viewvc/llvm-project?rev=234396&view=rev
Log:
[ELF] Do not save a reference to GOTFile instance in xxxWriter classes

It's a follow-up to r234347. We do not need to keep a reference to
`GOTFile` instance in a xxxWriter class after ownership is transferred
to the caller of the `createImplicitFiles` method.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h
    lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h
    lld/trunk/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h

Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h?rev=234396&r1=234395&r2=234396&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h Wed Apr  8 04:19:45 2015
@@ -32,22 +32,21 @@ private:
     GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {}
     llvm::BumpPtrAllocator _alloc;
   };
-
-  std::unique_ptr<GOTFile> _gotFile;
 };
 
 template <class ELFT>
 AArch64DynamicLibraryWriter<ELFT>::AArch64DynamicLibraryWriter(
     AArch64LinkingContext &ctx, TargetLayout<ELFT> &layout)
-    : DynamicLibraryWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)) {}
+    : DynamicLibraryWriter<ELFT>(ctx, layout) {}
 
 template <class ELFT>
 void AArch64DynamicLibraryWriter<ELFT>::createImplicitFiles(
     std::vector<std::unique_ptr<File>> &result) {
   DynamicLibraryWriter<ELFT>::createImplicitFiles(result);
-  _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile));
-  _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile));
-  result.push_back(std::move(_gotFile));
+  auto gotFile = llvm::make_unique<GOTFile>(this->_ctx);
+  gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile));
+  gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile));
+  result.push_back(std::move(gotFile));
 }
 
 } // namespace elf

Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h?rev=234396&r1=234395&r2=234396&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h Wed Apr  8 04:19:45 2015
@@ -31,23 +31,22 @@ private:
     GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {}
     llvm::BumpPtrAllocator _alloc;
   };
-
-  std::unique_ptr<GOTFile> _gotFile;
 };
 
 template <class ELFT>
 AArch64ExecutableWriter<ELFT>::AArch64ExecutableWriter(
     AArch64LinkingContext &ctx, TargetLayout<ELFT> &layout)
-    : ExecutableWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)) {}
+    : ExecutableWriter<ELFT>(ctx, layout) {}
 
 template <class ELFT>
 void AArch64ExecutableWriter<ELFT>::createImplicitFiles(
     std::vector<std::unique_ptr<File>> &result) {
   ExecutableWriter<ELFT>::createImplicitFiles(result);
-  _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile));
+  auto gotFile = llvm::make_unique<GOTFile>(this->_ctx);
+  gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile));
   if (this->_ctx.isDynamic())
-    _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile));
-  result.push_back(std::move(_gotFile));
+    gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile));
+  result.push_back(std::move(gotFile));
 }
 
 } // namespace elf

Modified: lld/trunk/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h?rev=234396&r1=234395&r2=234396&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h Wed Apr  8 04:19:45 2015
@@ -30,22 +30,21 @@ private:
     GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {}
     llvm::BumpPtrAllocator _alloc;
   };
-
-  std::unique_ptr<GOTFile> _gotFile;
 };
 
 template <class ELFT>
 X86DynamicLibraryWriter<ELFT>::X86DynamicLibraryWriter(
     X86LinkingContext &ctx, TargetLayout<ELFT> &layout)
-    : DynamicLibraryWriter<ELFT>(ctx, layout), _gotFile(new GOTFile(ctx)) {}
+    : DynamicLibraryWriter<ELFT>(ctx, layout) {}
 
 template <class ELFT>
 void X86DynamicLibraryWriter<ELFT>::createImplicitFiles(
     std::vector<std::unique_ptr<File>> &result) {
   DynamicLibraryWriter<ELFT>::createImplicitFiles(result);
-  _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile));
-  _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile));
-  result.push_back(std::move(_gotFile));
+  auto gotFile = llvm::make_unique<GOTFile>(this->_ctx);
+  gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile));
+  gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile));
+  result.push_back(std::move(gotFile));
 }
 
 } // namespace elf

Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h?rev=234396&r1=234395&r2=234396&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h Wed Apr  8 04:19:45 2015
@@ -32,20 +32,19 @@ private:
     GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {}
     llvm::BumpPtrAllocator _alloc;
   };
-
-  std::unique_ptr<GOTFile> _gotFile;
 };
 
 X86_64DynamicLibraryWriter::X86_64DynamicLibraryWriter(
     X86_64LinkingContext &ctx, X86_64TargetLayout &layout)
-    : DynamicLibraryWriter(ctx, layout), _gotFile(new GOTFile(ctx)) {}
+    : DynamicLibraryWriter(ctx, layout) {}
 
 void X86_64DynamicLibraryWriter::createImplicitFiles(
     std::vector<std::unique_ptr<File>> &result) {
   DynamicLibraryWriter::createImplicitFiles(result);
-  _gotFile->addAtom(*new (_gotFile->_alloc) GlobalOffsetTableAtom(*_gotFile));
-  _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile));
-  result.push_back(std::move(_gotFile));
+  auto gotFile = llvm::make_unique<GOTFile>(this->_ctx);
+  gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile));
+  gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile));
+  result.push_back(std::move(gotFile));
 }
 
 } // namespace elf

Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h?rev=234396&r1=234395&r2=234396&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h Wed Apr  8 04:19:45 2015
@@ -19,18 +19,18 @@ namespace elf {
 class X86_64ExecutableWriter : public ExecutableWriter<X86_64ELFType> {
 public:
   X86_64ExecutableWriter(X86_64LinkingContext &ctx, X86_64TargetLayout &layout)
-      : ExecutableWriter(ctx, layout), _gotFile(new GOTFile(ctx)) {}
+      : ExecutableWriter(ctx, layout) {}
 
 protected:
   // Add any runtime files and their atoms to the output
   void
   createImplicitFiles(std::vector<std::unique_ptr<File>> &result) override {
     ExecutableWriter::createImplicitFiles(result);
-    _gotFile->addAtom(*new (_gotFile->_alloc)
-                      GlobalOffsetTableAtom(*_gotFile));
+    auto gotFile = llvm::make_unique<GOTFile>(this->_ctx);
+    gotFile->addAtom(*new (gotFile->_alloc) GlobalOffsetTableAtom(*gotFile));
     if (this->_ctx.isDynamic())
-      _gotFile->addAtom(*new (_gotFile->_alloc) DynamicAtom(*_gotFile));
-    result.push_back(std::move(_gotFile));
+      gotFile->addAtom(*new (gotFile->_alloc) DynamicAtom(*gotFile));
+    result.push_back(std::move(gotFile));
   }
 
 private:
@@ -39,8 +39,6 @@ private:
     GOTFile(const ELFLinkingContext &eti) : SimpleFile("GOTFile") {}
     llvm::BumpPtrAllocator _alloc;
   };
-
-  std::unique_ptr<GOTFile> _gotFile;
 };
 
 } // namespace elf





More information about the llvm-commits mailing list