[lld] r316378 - Make Ctx a plain pointer again.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 14:12:19 PDT 2017


Author: rafael
Date: Mon Oct 23 14:12:19 2017
New Revision: 316378

URL: http://llvm.org/viewvc/llvm-project?rev=316378&view=rev
Log:
Make Ctx a plain pointer again.

If a struct has a std::unique_ptr member, the logical interpretation
is that that member will be destroyed with the struct.

That is not the case for Ctx. It is has to be deleted earlier and its
lifetime is defined by the functions where the AddressState is
created.

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

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=316378&r1=316377&r2=316378&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Oct 23 14:12:19 2017
@@ -356,7 +356,8 @@ void LinkerScript::processSectionCommand
   // This is needed as there are some cases where we cannot just
   // thread the current state through to a lambda function created by the
   // script parser.
-  Ctx = make_unique<AddressState>();
+  auto Deleter = make_unique<AddressState>();
+  Ctx = Deleter.get();
   Ctx->OutSec = Aether;
 
   DenseMap<SectionBase *, int> Order = buildSectionOrder();
@@ -803,11 +804,8 @@ void LinkerScript::assignAddresses() {
   // -image-base if set.
   Dot = Config->ImageBase ? *Config->ImageBase : 0;
 
-  // Ctx captures the local AddressState and makes it accessible
-  // deliberately. This is needed as there are some cases where we cannot just
-  // thread the current state through to a lambda function created by the
-  // script parser.
-  Ctx = make_unique<AddressState>();
+  auto Deleter = make_unique<AddressState>();
+  Ctx = Deleter.get();
   ErrorOnMissingSection = true;
   switchTo(Aether);
 

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=316378&r1=316377&r2=316378&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Mon Oct 23 14:12:19 2017
@@ -222,7 +222,14 @@ class LinkerScript final {
 
   void assignOffsets(OutputSection *Sec);
 
-  std::unique_ptr<AddressState> Ctx;
+  // Ctx captures the local AddressState and makes it accessible
+  // deliberately. This is needed as there are some cases where we cannot just
+  // thread the current state through to a lambda function created by the
+  // script parser.
+  // This should remain a plain pointer as its lifetime is smaller than
+  // LinkerScript.
+  AddressState *Ctx = nullptr;
+
   OutputSection *Aether;
 
   uint64_t Dot;




More information about the llvm-commits mailing list