summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/LinkerScript.cpp10
-rw-r--r--lld/ELF/LinkerScript.h9
2 files changed, 12 insertions, 7 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 31fe3b9be49..ff7b9f169f7 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -356,7 +356,8 @@ void LinkerScript::processSectionCommands() {
// 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);
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 1afb27cd3f5..c70d6bb170e 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -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;
OpenPOWER on IntegriCloud