[lld] r310607 - [ELF, LinkerScript] Support ! operator in linker script.

Hafiz Abid Qadeer via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 08:25:47 PDT 2017


Author: abidh
Date: Thu Aug 10 08:25:47 2017
New Revision: 310607

URL: http://llvm.org/viewvc/llvm-project?rev=310607&view=rev
Log:
[ELF, LinkerScript] Support ! operator in linker script.

Summary: This small patch adds the support for ! operator in linker scripts. 

Reviewers: ruiu, rafael

Reviewed By: ruiu

Subscribers: meadori, grimar, emaste, llvm-commits

Differential Revision: https://reviews.llvm.org/D36451

Modified:
    lld/trunk/ELF/ScriptLexer.cpp
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/test/ELF/linkerscript/symbol-assignexpr.s

Modified: lld/trunk/ELF/ScriptLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptLexer.cpp?rev=310607&r1=310606&r2=310607&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptLexer.cpp (original)
+++ lld/trunk/ELF/ScriptLexer.cpp Thu Aug 10 08:25:47 2017
@@ -168,7 +168,7 @@ bool ScriptLexer::atEOF() { return Error
 // Split a given string as an expression.
 // This function returns "3", "*" and "5" for "3*5" for example.
 static std::vector<StringRef> tokenizeExpr(StringRef S) {
-  StringRef Ops = "+-*/:"; // List of operators
+  StringRef Ops = "+-*/:!"; // List of operators
 
   // Quoted strings are literal strings, so we don't want to split it.
   if (S.startswith("\""))
@@ -189,9 +189,14 @@ static std::vector<StringRef> tokenizeEx
     if (E != 0)
       Ret.push_back(S.substr(0, E));
 
-    // Get the operator as a token.
-    Ret.push_back(S.substr(E, 1));
-    S = S.substr(E + 1);
+    // Get the operator as a token. Keep != as one token.
+    if (S.substr(E).startswith("!=")) {
+      Ret.push_back(S.substr(E, 2));
+      S = S.substr(E + 2);
+    } else {
+      Ret.push_back(S.substr(E, 1));
+      S = S.substr(E + 1);
+    }
   }
   return Ret;
 }

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=310607&r1=310606&r2=310607&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Thu Aug 10 08:25:47 2017
@@ -884,6 +884,10 @@ Expr ScriptParser::readPrimary() {
     Expr E = readPrimary();
     return [=] { return ~E().getValue(); };
   }
+  if (consume("!")) {
+    Expr E = readPrimary();
+    return [=] { return !E().getValue(); };
+  }
   if (consume("-")) {
     Expr E = readPrimary();
     return [=] { return -E().getValue(); };

Modified: lld/trunk/test/ELF/linkerscript/symbol-assignexpr.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/symbol-assignexpr.s?rev=310607&r1=310606&r2=310607&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-assignexpr.s (original)
+++ lld/trunk/test/ELF/linkerscript/symbol-assignexpr.s Thu Aug 10 08:25:47 2017
@@ -15,6 +15,9 @@
 # RUN:         symbol11 = ((0x28000 + 0x1fff) & ~(0x1000 + -1)); \
 # RUN:         symbol12 = 0x1234; \
 # RUN:         symbol12 += 1; \
+# RUN:         symbol13 = !1; \
+# RUN:         symbol14 = !0; \
+# RUN:         symbol15 = 0!=1; \
 # RUN:         bar = 0x5678; \
 # RUN:         baz = 0x9abc; \
 # RUN:       }" > %t.script
@@ -39,6 +42,9 @@
 # CHECK-NEXT: fedcba9876543210 *ABS* 00000000 symbol10
 # CHECK-NEXT: 0000000000029000 *ABS* 00000000 symbol11
 # CHECK-NEXT: 0000000000001235 *ABS* 00000000 symbol12
+# CHECK-NEXT: 0000000000000000 *ABS* 00000000 symbol13
+# CHECK-NEXT: 0000000000000001 *ABS* 00000000 symbol14
+# CHECK-NEXT: 0000000000000001 *ABS* 00000000 symbol15
 
 # RUN: echo "SECTIONS { symbol2 = symbol; }" > %t2.script
 # RUN: not ld.lld -o %t2 --script %t2.script %t 2>&1 \




More information about the llvm-commits mailing list