[PATCH] D36451: [ELF, LinkerScript] Support ! operator in linker script.
Hafiz Abid Qadeer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 9 07:55:30 PDT 2017
abidh updated this revision to Diff 110390.
https://reviews.llvm.org/D36451
Files:
ELF/ScriptLexer.cpp
ELF/ScriptParser.cpp
test/ELF/linkerscript/symbol-assignexpr.s
Index: test/ELF/linkerscript/symbol-assignexpr.s
===================================================================
--- test/ELF/linkerscript/symbol-assignexpr.s
+++ test/ELF/linkerscript/symbol-assignexpr.s
@@ -15,6 +15,8 @@
# RUN: symbol11 = ((0x28000 + 0x1fff) & ~(0x1000 + -1)); \
# RUN: symbol12 = 0x1234; \
# RUN: symbol12 += 1; \
+# RUN: symbol13 = !1; \
+# RUN: symbol14 = !0; \
# RUN: bar = 0x5678; \
# RUN: baz = 0x9abc; \
# RUN: }" > %t.script
@@ -39,6 +41,8 @@
# 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
# RUN: echo "SECTIONS { symbol2 = symbol; }" > %t2.script
# RUN: not ld.lld -o %t2 --script %t2.script %t 2>&1 \
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -884,6 +884,10 @@
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(); };
Index: ELF/ScriptLexer.cpp
===================================================================
--- ELF/ScriptLexer.cpp
+++ ELF/ScriptLexer.cpp
@@ -168,7 +168,7 @@
// 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("\""))
@@ -212,6 +212,9 @@
std::vector<StringRef> V = tokenizeExpr(Tokens[Pos]);
if (V.size() == 1)
return;
+ // Don't breakup != operator into 2 tokens
+ if (V.size() == 2 && V[0] == "!" && V[1] == "=")
+ return;
Tokens.erase(Tokens.begin() + Pos);
Tokens.insert(Tokens.begin() + Pos, V.begin(), V.end());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36451.110390.patch
Type: text/x-patch
Size: 2240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170809/c92da778/attachment.bin>
More information about the llvm-commits
mailing list