[lld] r327684 - Fix linker script operator precedence.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 15 16:12:33 PDT 2018
Author: ruiu
Date: Thu Mar 15 16:12:33 2018
New Revision: 327684
URL: http://llvm.org/viewvc/llvm-project?rev=327684&view=rev
Log:
Fix linker script operator precedence.
"&" should have higher priority than "|" [1]. Previously, they had
the same priority.
[1] https://sourceware.org/binutils/docs/ld/Operators.html
Differential Revision: https://reviews.llvm.org/D43880
Modified:
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/operators.test
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=327684&r1=327683&r2=327684&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Thu Mar 15 16:12:33 2018
@@ -469,11 +469,12 @@ void ScriptParser::readSections() {
static int precedence(StringRef Op) {
return StringSwitch<int>(Op)
- .Cases("*", "/", "%", 5)
- .Cases("+", "-", 4)
- .Cases("<<", ">>", 3)
- .Cases("<", "<=", ">", ">=", "==", "!=", 2)
- .Cases("&", "|", 1)
+ .Cases("*", "/", "%", 6)
+ .Cases("+", "-", 5)
+ .Cases("<<", ">>", 4)
+ .Cases("<", "<=", ">", ">=", "==", "!=", 3)
+ .Case("&", 2)
+ .Case("|", 1)
.Default(-1);
}
Modified: lld/trunk/test/ELF/linkerscript/operators.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/operators.test?rev=327684&r1=327683&r2=327684&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/operators.test (original)
+++ lld/trunk/test/ELF/linkerscript/operators.test Thu Mar 15 16:12:33 2018
@@ -26,6 +26,8 @@ SECTIONS {
unary = -1 + 3;
lshift = 1 << 5;
rshift = 0xff >> 3;
+ precedence1 = 1 | 0xff & 1 << 1 + 1 * 2;
+ precedence2 = (1 | (0xff & (1 << (1 + (1 * 2)))));
maxpagesize = CONSTANT (MAXPAGESIZE);
commonpagesize = CONSTANT (COMMONPAGESIZE);
. = 0xfff0;
@@ -56,6 +58,8 @@ SECTIONS {
# CHECK: 00000000000002 *ABS* 00000000 unary
# CHECK: 00000000000020 *ABS* 00000000 lshift
# CHECK: 0000000000001f *ABS* 00000000 rshift
+# CHECK: 00000000000009 *ABS* 00000000 precedence1
+# CHECK: 00000000000009 *ABS* 00000000 precedence2
# CHECK: 00000000001000 *ABS* 00000000 maxpagesize
# CHECK: 00000000001000 *ABS* 00000000 commonpagesize
# CHECK: 0000000000ffff *ABS* 00000000 datasegmentalign
More information about the llvm-commits
mailing list