[lld] r267382 - [ELF] - Implemented comparsion operators for linkerscript.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 25 01:14:41 PDT 2016


Author: grimar
Date: Mon Apr 25 03:14:41 2016
New Revision: 267382

URL: http://llvm.org/viewvc/llvm-project?rev=267382&view=rev
Log:
[ELF] - Implemented comparsion operators for linkerscript.

Patch adds support of <,>,!=,==,>=,<= operators.

Differential revision: http://reviews.llvm.org/D19419

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/test/ELF/linkerscript-locationcounter.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=267382&r1=267381&r2=267382&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Apr 25 03:14:41 2016
@@ -63,9 +63,15 @@ private:
 static int precedence(StringRef Op) {
   return StringSwitch<int>(Op)
       .Case("*", 4)
-      .Case("/", 3)
-      .Case("+", 2)
-      .Case("-", 2)
+      .Case("/", 4)
+      .Case("+", 3)
+      .Case("-", 3)
+      .Case("<", 2)
+      .Case(">", 2)
+      .Case(">=", 2)
+      .Case("<=", 2)
+      .Case("==", 2)
+      .Case("!=", 2)
       .Case("&", 1)
       .Default(-1);
 }
@@ -115,10 +121,6 @@ uint64_t ExprParser::parseTernary(uint64
 }
 
 uint64_t ExprParser::apply(StringRef Op, uint64_t L, uint64_t R) {
-  if (Op == "+")
-    return L + R;
-  if (Op == "-")
-    return L - R;
   if (Op == "*")
     return L * R;
   if (Op == "/") {
@@ -128,6 +130,22 @@ uint64_t ExprParser::apply(StringRef Op,
     }
     return L / R;
   }
+  if (Op == "+")
+    return L + R;
+  if (Op == "-")
+    return L - R;
+  if (Op == "<")
+    return L < R;
+  if (Op == ">")
+    return L > R;
+  if (Op == ">=")
+    return L >= R;
+  if (Op == "<=")
+    return L <= R;
+  if (Op == "==")
+    return L == R;
+  if (Op == "!=")
+    return L != R;
   if (Op == "&")
     return L & R;
   llvm_unreachable("invalid operator");

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=267382&r1=267381&r2=267382&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Mon Apr 25 03:14:41 2016
@@ -75,7 +75,7 @@ std::vector<StringRef> ScriptParserBase:
     // Unquoted token
     size_t Pos = S.find_first_not_of(
         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
-        "0123456789_.$/\\~=+[]*?-:");
+        "0123456789_.$/\\~=+[]*?-:!<>");
     // A character that cannot start a word (which is usually a
     // punctuation) forms a single character token.
     if (Pos == 0)

Modified: lld/trunk/test/ELF/linkerscript-locationcounter.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript-locationcounter.s?rev=267382&r1=267381&r2=267382&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript-locationcounter.s (original)
+++ lld/trunk/test/ELF/linkerscript-locationcounter.s Mon Apr 25 03:14:41 2016
@@ -18,6 +18,18 @@
 # RUN:  .ternary1 : { *(.ternary1) } \
 # RUN:  . = 0x0 ? 0x999999 : 0x17000; \
 # RUN:  .ternary2 : { *(.ternary2) } \
+# RUN:  . = 0x0 < 0x1 ? 0x18000 : 0x999999; \
+# RUN:  .less : { *(.less) } \
+# RUN:  . = 0x1 <= 0x1 ? 0x19000 : 0x999999; \
+# RUN:  .lesseq : { *(.lesseq) } \
+# RUN:  . = 0x1 > 0x0 ? 0x20000 : 0x999999; \
+# RUN:  .great : { *(.great) } \
+# RUN:  . = 0x1 >= 0x1 ? 0x21000 : 0x999999; \
+# RUN:  .greateq : { *(.greateq) } \
+# RUN:  . = 0x1 == 0x1 ? 0x22000 : 0x999999; \
+# RUN:  .eq : { *(.eq) } \
+# RUN:  . = 0x2 != 0x1 ? 0x23000 : 0x999999; \
+# RUN:  .neq : { *(.neq) } \
 # RUN: }" > %t.script
 # RUN: ld.lld %t --script %t.script -o %t2
 # RUN: llvm-readobj -s %t2 | FileCheck %s
@@ -142,6 +154,96 @@
 # CHECK-NEXT:   AddressAlignment:
 # CHECK-NEXT:   EntrySize:
 # CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT:   Index:
+# CHECK-NEXT:   Name: .less
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x18000
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Link:
+# CHECK-NEXT:   Info:
+# CHECK-NEXT:   AddressAlignment:
+# CHECK-NEXT:   EntrySize:
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT:   Index:
+# CHECK-NEXT:   Name: .lesseq
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x19000
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Link:
+# CHECK-NEXT:   Info:
+# CHECK-NEXT:   AddressAlignment:
+# CHECK-NEXT:   EntrySize:
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT:   Index:
+# CHECK-NEXT:   Name: .great
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x20000
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Link:
+# CHECK-NEXT:   Info:
+# CHECK-NEXT:   AddressAlignment:
+# CHECK-NEXT:   EntrySize:
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT:   Index:
+# CHECK-NEXT:   Name: .greateq
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x21000
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Link:
+# CHECK-NEXT:   Info:
+# CHECK-NEXT:   AddressAlignment:
+# CHECK-NEXT:   EntrySize:
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT:   Index:
+# CHECK-NEXT:   Name: .eq
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x22000
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Link:
+# CHECK-NEXT:   Info:
+# CHECK-NEXT:   AddressAlignment:
+# CHECK-NEXT:   EntrySize:
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT:   Index:
+# CHECK-NEXT:   Name: .neq
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x23000
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Link:
+# CHECK-NEXT:   Info:
+# CHECK-NEXT:   AddressAlignment:
+# CHECK-NEXT:   EntrySize:
+# CHECK-NEXT: }
 
 ## Mailformed number error.
 # RUN: echo "SECTIONS { \
@@ -218,3 +320,21 @@ nop
 
 .section .ternary2, "a"
 .quad 0
+
+.section .less, "a"
+.quad 0
+
+.section .lesseq, "a"
+.quad 0
+
+.section .great, "a"
+.quad 0
+
+.section .greateq, "a"
+.quad 0
+
+.section .eq, "a"
+.quad 0
+
+.section .neq, "a"
+.quad 0




More information about the llvm-commits mailing list