[llvm-branch-commits] [lld] r323336 - Merging r322359, r322421, and r322801:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 24 07:48:27 PST 2018


Author: hans
Date: Wed Jan 24 07:48:26 2018
New Revision: 323336

URL: http://llvm.org/viewvc/llvm-project?rev=323336&view=rev
Log:
Merging r322359, r322421, and r322801:

------------------------------------------------------------------------
r322359 | grimar | 2018-01-12 10:07:35 +0100 (Fri, 12 Jan 2018) | 8 lines

[ELF] - Fix for ld.lld does not accept "AT" syntax for declaring LMA region

AT> lma_region expression allows to specify the memory region
for section load address.

Should fix PR35684.

Differential revision: https://reviews.llvm.org/D41397
------------------------------------------------------------------------

------------------------------------------------------------------------
r322421 | rafael | 2018-01-13 00:26:25 +0100 (Sat, 13 Jan 2018) | 9 lines

Fix incorrect physical address on self-referencing AT command.

When a section placement (AT) command references the section itself,
the physical address of the section in the ELF header was calculated
incorrectly due to alignment happening right after the location
pointer's value was captured.

The problem was diagnosed and the first version of the patch written
by Erick Reyes.
------------------------------------------------------------------------

------------------------------------------------------------------------
r322801 | rafael | 2018-01-18 02:14:57 +0100 (Thu, 18 Jan 2018) | 5 lines

Handle parsing AT(ADDR(.foo-bar)).

The problem we had with it is that anything inside an AT is an
expression, so we failed to parse the section name because of the - in
it.
------------------------------------------------------------------------

Added:
    lld/branches/release_60/test/ELF/linkerscript/at-self-reference.s
      - copied unchanged from r322421, lld/trunk/test/ELF/linkerscript/at-self-reference.s
    lld/branches/release_60/test/ELF/linkerscript/at2.s
      - copied unchanged from r322359, lld/trunk/test/ELF/linkerscript/at2.s
    lld/branches/release_60/test/ELF/linkerscript/parse-section-in-addr.s
      - copied unchanged from r322801, lld/trunk/test/ELF/linkerscript/parse-section-in-addr.s
Modified:
    lld/branches/release_60/   (props changed)
    lld/branches/release_60/ELF/LinkerScript.cpp
    lld/branches/release_60/ELF/OutputSections.h
    lld/branches/release_60/ELF/ScriptParser.cpp

Propchange: lld/branches/release_60/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 24 07:48:26 2018
@@ -1 +1 @@
-/lld/trunk:321983,321986,322041,322259,322264,323221
+/lld/trunk:321983,321986,322041,322259,322264,322359,322421,322801,323221

Modified: lld/branches/release_60/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/ELF/LinkerScript.cpp?rev=323336&r1=323335&r2=323336&view=diff
==============================================================================
--- lld/branches/release_60/ELF/LinkerScript.cpp (original)
+++ lld/branches/release_60/ELF/LinkerScript.cpp Wed Jan 24 07:48:26 2018
@@ -608,13 +608,6 @@ void LinkerScript::switchTo(OutputSectio
 
   Ctx->OutSec = Sec;
   Ctx->OutSec->Addr = advance(0, Ctx->OutSec->Alignment);
-
-  // If neither AT nor AT> is specified for an allocatable section, the linker
-  // 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
-  if (Ctx->LMAOffset)
-    Ctx->OutSec->LMAOffset = Ctx->LMAOffset();
 }
 
 // This function searches for a memory region to place the given output
@@ -662,12 +655,28 @@ void LinkerScript::assignOffsets(OutputS
   if (Ctx->MemRegion)
     Dot = Ctx->MemRegionOffset[Ctx->MemRegion];
 
+  switchTo(Sec);
+
   if (Sec->LMAExpr) {
     uint64_t D = Dot;
     Ctx->LMAOffset = [=] { return Sec->LMAExpr().getValue() - D; };
   }
 
-  switchTo(Sec);
+  if (!Sec->LMARegionName.empty()) {
+    if (MemoryRegion *MR = MemoryRegions.lookup(Sec->LMARegionName)) {
+      uint64_t Offset = MR->Origin - Dot;
+      Ctx->LMAOffset = [=] { return Offset; };
+    } else {
+      error("memory region '" + Sec->LMARegionName + "' not declared");
+    }
+  }
+
+  // If neither AT nor AT> is specified for an allocatable section, the linker
+  // 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
+  if (Ctx->LMAOffset)
+    Ctx->OutSec->LMAOffset = Ctx->LMAOffset();
 
   // The Size previously denoted how many InputSections had been added to this
   // section, and was used for sorting SHF_LINK_ORDER sections. Reset it to

Modified: lld/branches/release_60/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/ELF/OutputSections.h?rev=323336&r1=323335&r2=323336&view=diff
==============================================================================
--- lld/branches/release_60/ELF/OutputSections.h (original)
+++ lld/branches/release_60/ELF/OutputSections.h Wed Jan 24 07:48:26 2018
@@ -99,6 +99,7 @@ public:
   ConstraintKind Constraint = ConstraintKind::NoConstraint;
   std::string Location;
   std::string MemoryRegionName;
+  std::string LMARegionName;
   bool Noload = false;
 
   template <class ELFT> void finalize();

Modified: lld/branches/release_60/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/ELF/ScriptParser.cpp?rev=323336&r1=323335&r2=323336&view=diff
==============================================================================
--- lld/branches/release_60/ELF/ScriptParser.cpp (original)
+++ lld/branches/release_60/ELF/ScriptParser.cpp Wed Jan 24 07:48:26 2018
@@ -709,6 +709,14 @@ OutputSection *ScriptParser::readOutputS
   if (consume(">"))
     Cmd->MemoryRegionName = next();
 
+  if (consume("AT")) {
+    expect(">");
+    Cmd->LMARegionName = next();
+  }
+
+  if (Cmd->LMAExpr && !Cmd->LMARegionName.empty())
+    error("section can't have both LMA and a load region");
+
   Cmd->Phdrs = readOutputSectionPhdrs();
 
   if (consume("="))
@@ -922,7 +930,10 @@ ByteCommand *ScriptParser::readByteComma
 
 StringRef ScriptParser::readParenLiteral() {
   expect("(");
+  bool Orig = InExpr;
+  InExpr = false;
   StringRef Tok = next();
+  InExpr = Orig;
   expect(")");
   return Tok;
 }




More information about the llvm-branch-commits mailing list