[lld] r295943 - [ELF] - Refactoring of LMA offset handling code. NFC.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 23:57:55 PST 2017


Author: grimar
Date: Thu Feb 23 01:57:55 2017
New Revision: 295943

URL: http://llvm.org/viewvc/llvm-project?rev=295943&view=rev
Log:
[ELF] - Refactoring of LMA offset handling code. NFC.

Thanks to Rui Ueyama for suggestion.

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=295943&r1=295942&r2=295943&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Feb 23 01:57:55 2017
@@ -463,9 +463,8 @@ void LinkerScript<ELFT>::switchTo(Output
   // will set the LMA such that the difference between VMA and LMA for the
   // section is the same as the preceding output section in the same region
   // https://sourceware.org/binutils/docs-2.20/ld/Output-Section-LMA.html
-  Expr LMAExpr = CurLMA.first;
-  if (LMAExpr)
-    CurOutSec->setLMAOffset(LMAExpr(CurLMA.second) - CurLMA.second);
+  if (LMAOffset)
+    CurOutSec->setLMAOffset(LMAOffset());
 }
 
 template <class ELFT> void LinkerScript<ELFT>::process(BaseCommand &Base) {
@@ -565,8 +564,10 @@ MemoryRegion *LinkerScript<ELFT>::findMe
 // for a single sections command (e.g. ".text { *(.text); }").
 template <class ELFT>
 void LinkerScript<ELFT>::assignOffsets(OutputSectionCommand *Cmd) {
-  if (Cmd->LMAExpr)
-    CurLMA = {Cmd->LMAExpr, Dot};
+  if (Cmd->LMAExpr) {
+    uintX_t D = Dot;
+    LMAOffset = [=] { return Cmd->LMAExpr(D) - D; };
+  }
   OutputSectionBase *Sec = findSection<ELFT>(Cmd->Name, *OutputSections);
   if (!Sec)
     return;

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=295943&r1=295942&r2=295943&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Thu Feb 23 01:57:55 2017
@@ -298,7 +298,7 @@ private:
                                  OutputSectionBase *Sec);
 
   uintX_t Dot;
-  std::pair<Expr, uintX_t> CurLMA;
+  std::function<uint64_t()> LMAOffset;
   OutputSectionBase *CurOutSec = nullptr;
   MemoryRegion *CurMemRegion = nullptr;
   uintX_t ThreadBssOffset = 0;




More information about the llvm-commits mailing list