[lld] r282243 - [ELF] - Linkerscript: Implemented >> and <<

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 06:13:56 PDT 2016


Author: grimar
Date: Fri Sep 23 08:13:55 2016
New Revision: 282243

URL: http://llvm.org/viewvc/llvm-project?rev=282243&view=rev
Log:
[ELF] - Linkerscript: Implemented >> and <<

Found this operators used in the wild scripts, for example:

__got2_entries = (_FIXUP_TABLE_ - _GOT2_TABLE_) >>2;
__fixup_entries = (. - _FIXUP_TABLE_)>>2;

Differential revision: https://reviews.llvm.org/D24860

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/locationcounter.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=282243&r1=282242&r2=282243&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Sep 23 08:13:55 2016
@@ -1081,10 +1081,12 @@ void ScriptParser::readSections() {
 
 static int precedence(StringRef Op) {
   return StringSwitch<int>(Op)
-      .Case("*", 4)
-      .Case("/", 4)
-      .Case("+", 3)
-      .Case("-", 3)
+      .Case("*", 5)
+      .Case("/", 5)
+      .Case("+", 4)
+      .Case("-", 4)
+      .Case("<<", 3)
+      .Case(">>", 3)
       .Case("<", 2)
       .Case(">", 2)
       .Case(">=", 2)
@@ -1361,6 +1363,10 @@ static Expr combine(StringRef Op, Expr L
     return [=](uint64_t Dot) { return L(Dot) + R(Dot); };
   if (Op == "-")
     return [=](uint64_t Dot) { return L(Dot) - R(Dot); };
+  if (Op == "<<")
+    return [=](uint64_t Dot) { return L(Dot) << R(Dot); };
+  if (Op == ">>")
+    return [=](uint64_t Dot) { return L(Dot) >> R(Dot); };
   if (Op == "<")
     return [=](uint64_t Dot) { return L(Dot) < R(Dot); };
   if (Op == ">")

Modified: lld/trunk/test/ELF/linkerscript/locationcounter.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/locationcounter.s?rev=282243&r1=282242&r2=282243&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/locationcounter.s (original)
+++ lld/trunk/test/ELF/linkerscript/locationcounter.s Fri Sep 23 08:13:55 2016
@@ -42,6 +42,11 @@
 # RUN:  .plusassign : { *(.plusassign) } \
 # RUN:  . = ((. + 0x1fff) & ~(0x1000 + -1)); \
 # RUN:  .unary : { *(.unary) } \
+# RUN:  . = 0x30000 + (1 + 1 << 5); \
+# RUN:  .shiftl : { *(.shiftl) } \
+# RUN:  . = 0x30000 + (1 + 1023 >> 2); \
+# RUN:  .shiftr : { *(.shiftr) } \
+
 # RUN: }" > %t.script
 # RUN: ld.lld %t --script %t.script -o %t2
 # RUN: llvm-objdump -section-headers %t2 | FileCheck %s
@@ -65,6 +70,8 @@
 # CHECK: .datasegmentalign {{.*}} 0000000000200000
 # CHECK: .plusassign       {{.*}} 0000000000028000
 # CHECK: .unary            {{.*}} 000000000002a000
+# CHECK: .shiftl           {{.*}} 0000000000030040
+# CHECK: .shiftr           {{.*}} 0000000000030100
 
 ## Mailformed number error.
 # RUN: echo "SECTIONS { \
@@ -174,3 +181,9 @@ nop
 
 .section .unary, "a"
 .quad 0
+
+.section .shiftl, "a"
+.quad 0
+
+.section .shiftr, "a"
+.quad 0




More information about the llvm-commits mailing list