[lld] r300131 - Allow expressions in MEMORY command.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 12 16:16:52 PDT 2017


Author: ruiu
Date: Wed Apr 12 18:16:52 2017
New Revision: 300131

URL: http://llvm.org/viewvc/llvm-project?rev=300131&view=rev
Log:
Allow expressions in MEMORY command.

Previously, we allowed only integers in this context. Now you can
write expressions there. LLD is now able to handle the following
linker, for example.

  MEMORY { rom (rx) : ORIGIN = (1024 * 1024) }

Modified:
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/test/ELF/linkerscript/memory.s

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=300131&r1=300130&r2=300131&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Wed Apr 12 18:16:52 2017
@@ -1102,12 +1102,7 @@ uint64_t ScriptParser::readMemoryAssignm
     return 0;
   }
   expect("=");
-
-  // TODO: Fully support constant expressions.
-  if (Optional<uint64_t> Val = parseInt(next()))
-    return *Val;
-  setError("nonconstant expression for " + S1);
-  return 0;
+  return readExpr()().getValue();
 }
 
 // Parse the MEMORY command as specified in:

Modified: lld/trunk/test/ELF/linkerscript/memory.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/memory.s?rev=300131&r1=300130&r2=300131&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/memory.s (original)
+++ lld/trunk/test/ELF/linkerscript/memory.s Wed Apr 12 18:16:52 2017
@@ -18,7 +18,7 @@
 
 # RUN: echo "MEMORY { \
 # RUN:   ram (rwx) : ORIGIN = 0, LENGTH = 1024M \
-# RUN:   rom (rx) : org = 0x80000000, len = 64M \
+# RUN:   rom (rx) : org = (0x80 * 0x1000 * 0x1000), len = 64M \
 # RUN: } \
 # RUN: SECTIONS { \
 # RUN:   .text : { *(.text) } > rom \




More information about the llvm-commits mailing list