diff options
author | George Rimar <grimar@accesssoftek.com> | 2018-07-03 14:02:52 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2018-07-03 14:02:52 +0000 |
commit | a50054829dbf2a43d1174c05a0ba69de9099641d (patch) | |
tree | eb862c5a4a53222edad6bc24ef835cc9dd8ff278 | |
parent | 3074b9e53f46f7ea398b34c325553dcccf02607a (diff) | |
download | bcm5719-llvm-a50054829dbf2a43d1174c05a0ba69de9099641d.tar.gz bcm5719-llvm-a50054829dbf2a43d1174c05a0ba69de9099641d.zip |
[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.
llvm-svn: 336197
-rw-r--r-- | lld/ELF/ScriptLexer.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/ScriptParser.cpp | 18 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/operators.test | 16 |
3 files changed, 29 insertions, 7 deletions
diff --git a/lld/ELF/ScriptLexer.cpp b/lld/ELF/ScriptLexer.cpp index ef5a1cff759..49e808e5d8f 100644 --- a/lld/ELF/ScriptLexer.cpp +++ b/lld/ELF/ScriptLexer.cpp @@ -117,7 +117,7 @@ void ScriptLexer::tokenize(MemoryBufferRef MB) { // ">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; diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 1d6a2174832..b0982f57bc5 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -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, Expr L, Expr R) { 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 == "|") diff --git a/lld/test/ELF/linkerscript/operators.test b/lld/test/ELF/linkerscript/operators.test index 79960443a3a..2be24dfc2fe 100644 --- a/lld/test/ELF/linkerscript/operators.test +++ b/lld/test/ELF/linkerscript/operators.test @@ -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 |