[PATCH] D44734: [ELF] - Linkerscript: support MIN and MAX.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 28 04:37:13 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL328696: [ELF] - Linkerscript: support MIN and MAX. (authored by grimar, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44734?vs=139284&id=140065#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44734

Files:
  lld/trunk/ELF/ScriptParser.cpp
  lld/trunk/test/ELF/linkerscript/operators.test


Index: lld/trunk/test/ELF/linkerscript/operators.test
===================================================================
--- lld/trunk/test/ELF/linkerscript/operators.test
+++ lld/trunk/test/ELF/linkerscript/operators.test
@@ -36,6 +36,8 @@
   _end = .;
   minus_rel = _end - 0x10;
   minus_abs = _end - _start;
+  max = MAX(11, 22);
+  min = MIN(11, 22);
 }
 
 # CHECK: 00000000000006 *ABS* 00000000 plus
@@ -66,6 +68,8 @@
 # CHECK: 0000000000fff0 *ABS* 00000000 datasegmentalign2
 # CHECK: 0000000000ffe0 .text 00000000 minus_rel
 # CHECK: 0000000000fff0 *ABS* 00000000 minus_abs
+# CHECK: 00000000000016 *ABS* 00000000 max
+# CHECK: 0000000000000b *ABS* 00000000 min
 
 ## Mailformed number error.
 # RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script
Index: lld/trunk/ELF/ScriptParser.cpp
===================================================================
--- lld/trunk/ELF/ScriptParser.cpp
+++ lld/trunk/ELF/ScriptParser.cpp
@@ -1097,6 +1097,16 @@
       return Cmd->getLMA();
     };
   }
+  if (Tok == "MAX" || Tok == "MIN") {
+    expect("(");
+    Expr A = readExpr();
+    expect(",");
+    Expr B = readExpr();
+    expect(")");
+    if (Tok == "MIN")
+      return [=] { return std::min(A().getValue(), B().getValue()); };
+    return [=] { return std::max(A().getValue(), B().getValue()); };
+  }
   if (Tok == "ORIGIN") {
     StringRef Name = readParenLiteral();
     if (Script->MemoryRegions.count(Name) == 0) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44734.140065.patch
Type: text/x-patch
Size: 1430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180328/45949595/attachment.bin>


More information about the llvm-commits mailing list