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.

llvm-svn: 316378
This commit is contained in:
Rafael Espindola 2017-10-23 21:12:19 +00:00
parent 7887238c7c
commit 089dac7be1
2 changed files with 12 additions and 7 deletions

View File

@ -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);

View File

@ -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;