Fix linker script operator precedence.
authorRui Ueyama <ruiu@google.com>
Thu, 15 Mar 2018 23:12:33 +0000 (23:12 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 15 Mar 2018 23:12:33 +0000 (23:12 +0000)
"&" 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

llvm-svn: 327684

lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/operators.test

index 26c88a9..6f16c45 100644 (file)
@@ -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);
 }
 
index fa6e7ee..d3c6c7a 100644 (file)
@@ -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