forked from OSchip/llvm-project
[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
This commit is contained in:
parent
3074b9e53f
commit
a50054829d
|
@ -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;
|
||||
|
|
|
@ -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 == "|")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue