[lld] r336197 - [ELF] - Add support for '||' and '&&' in linker scripts.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 3 07:02:52 PDT 2018
Author: grimar
Date: Tue Jul 3 07:02:52 2018
New Revision: 336197
URL: http://llvm.org/viewvc/llvm-project?rev=336197&view=rev
Log:
[ELF] - Add support for '||' and '&&' in linker scripts.
This is https://bugs.llvm.org//show_bug.cgi?id=37976,
we had no support, but seems someone faced it.
Modified:
lld/trunk/ELF/ScriptLexer.cpp
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/operators.test
Modified: lld/trunk/ELF/ScriptLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptLexer.cpp?rev=336197&r1=336196&r2=336197&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptLexer.cpp (original)
+++ lld/trunk/ELF/ScriptLexer.cpp Tue Jul 3 07:02:52 2018
@@ -117,7 +117,7 @@ void ScriptLexer::tokenize(MemoryBufferR
// ">foo" is parsed to ">" and "foo", but ">>" is parsed to ">>".
if (S.startswith("<<") || S.startswith("<=") || S.startswith(">>") ||
- S.startswith(">=")) {
+ S.startswith(">=") || S.startswith("||") || S.startswith("&&")) {
Vec.push_back(S.substr(0, 2));
S = S.substr(2);
continue;
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=336197&r1=336196&r2=336197&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Tue Jul 3 07:02:52 2018
@@ -524,12 +524,14 @@ void ScriptParser::readSections() {
static int precedence(StringRef Op) {
return StringSwitch<int>(Op)
- .Cases("*", "/", "%", 6)
- .Cases("+", "-", 5)
- .Cases("<<", ">>", 4)
- .Cases("<", "<=", ">", ">=", "==", "!=", 3)
- .Case("&", 2)
- .Case("|", 1)
+ .Cases("*", "/", "%", 8)
+ .Cases("+", "-", 7)
+ .Cases("<<", ">>", 6)
+ .Cases("<", "<=", ">", ">=", "==", "!=", 5)
+ .Case("&", 4)
+ .Case("|", 3)
+ .Case("&&", 2)
+ .Case("||", 1)
.Default(-1);
}
@@ -924,6 +926,10 @@ Expr ScriptParser::combine(StringRef Op,
return [=] { return L().getValue() == R().getValue(); };
if (Op == "!=")
return [=] { return L().getValue() != R().getValue(); };
+ if (Op == "||")
+ return [=] { return L().getValue() || R().getValue(); };
+ if (Op == "&&")
+ return [=] { return L().getValue() && R().getValue(); };
if (Op == "&")
return [=] { return bitAnd(L(), R()); };
if (Op == "|")
Modified: lld/trunk/test/ELF/linkerscript/operators.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/operators.test?rev=336197&r1=336196&r2=336197&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/operators.test (original)
+++ lld/trunk/test/ELF/linkerscript/operators.test Tue Jul 3 07:02:52 2018
@@ -38,6 +38,14 @@ SECTIONS {
minus_abs = _end - _start;
max = MAX(11, 22);
min = MIN(11, 22);
+ logicaland1 = 0 && 0;
+ logicaland2 = 0 && 1;
+ logicaland3 = 1 && 0;
+ logicaland4 = 1 && 1;
+ logicalor1 = 0 || 0;
+ logicalor2 = 0 || 1;
+ logicalor3 = 1 || 0;
+ logicalor4 = 1 || 1;
}
# CHECK: 00000000000006 *ABS* 00000000 plus
@@ -70,6 +78,14 @@ SECTIONS {
# CHECK: 0000000000fff0 *ABS* 00000000 minus_abs
# CHECK: 00000000000016 *ABS* 00000000 max
# CHECK: 0000000000000b *ABS* 00000000 min
+# CHECK: 00000000000000 *ABS* 00000000 logicaland1
+# CHECK: 00000000000000 *ABS* 00000000 logicaland2
+# CHECK: 00000000000000 *ABS* 00000000 logicaland3
+# CHECK: 00000000000001 *ABS* 00000000 logicaland4
+# CHECK: 00000000000000 *ABS* 00000000 logicalor1
+# CHECK: 00000000000001 *ABS* 00000000 logicalor2
+# CHECK: 00000000000001 *ABS* 00000000 logicalor3
+# CHECK: 00000000000001 *ABS* 00000000 logicalor4
## Mailformed number error.
# RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script
More information about the llvm-commits
mailing list