[lld] r307637 - [ELF] Add comment to explain LinkerScript::CurAddressState [NFC]

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 02:28:27 PDT 2017


Author: psmith
Date: Tue Jul 11 02:28:27 2017
New Revision: 307637

URL: http://llvm.org/viewvc/llvm-project?rev=307637&view=rev
Log:
[ELF] Add comment to explain LinkerScript::CurAddressState [NFC]

r307367 via D34345 split out the temporary address state used within
processCommands() and assignAddresses(). Due to the way that getSymbolValue
is used by the ScriptParser there is no way of giving the current
OutputSection to getSymbolValue() without somehow accessing the created
addressState. The suggestion was that by making a pointer that would go out
of scope we would find out by ASAN/MSAN or a crash if someone had misused
currentAddressState.

Differential Revision: https://reviews.llvm.org/D34345


Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=307637&r1=307636&r2=307637&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Jul 11 02:28:27 2017
@@ -374,6 +374,10 @@ void LinkerScript::processCommands(Outpu
   Aether = make<OutputSection>("", 0, SHF_ALLOC);
   Aether->SectionIndex = 1;
   auto State = make_unique<AddressState>(Opt);
+  // CurAddressState 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.
   CurAddressState = State.get();
   CurAddressState->OutSec = Aether;
   Dot = 0;
@@ -437,6 +441,7 @@ void LinkerScript::processCommands(Outpu
       }
     }
   }
+  CurAddressState = nullptr;
 }
 
 void LinkerScript::fabricateDefaultCommands() {
@@ -843,6 +848,10 @@ void LinkerScript::assignAddresses() {
   // Assign addresses as instructed by linker script SECTIONS sub-commands.
   Dot = 0;
   auto State = make_unique<AddressState>(Opt);
+  // CurAddressState 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.
   CurAddressState = State.get();
   ErrorOnMissingSection = true;
   switchTo(Aether);
@@ -861,6 +870,7 @@ void LinkerScript::assignAddresses() {
     auto *Cmd = cast<OutputSectionCommand>(Base);
     assignOffsets(Cmd);
   }
+  CurAddressState = nullptr;
 }
 
 // Creates program headers as instructed by PHDRS linker script command.




More information about the llvm-commits mailing list