[PATCH] D24860: [ELF] - Linkerscript: Implemented >> and <<

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 05:45:52 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.

Found this operators used in the wild here:
https://searchcode.com/file/103745382/board/bf561-ezkit/u-boot.lds.S

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

https://reviews.llvm.org/D24860

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/locationcounter.s

Index: test/ELF/linkerscript/locationcounter.s
===================================================================
--- test/ELF/linkerscript/locationcounter.s
+++ test/ELF/linkerscript/locationcounter.s
@@ -42,6 +42,11 @@
 # RUN:  .plusassign : { *(.plusassign) } \
 # RUN:  . = ((. + 0x1fff) & ~(0x1000 + -1)); \
 # RUN:  .unary : { *(.unary) } \
+# RUN:  . = 0x30000 + (1 << 5);    \
+# RUN:  .shiftl : { *(.shiftl) } \
+# RUN:  . = 0x30000 + (1024 >> 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           {{.*}} 0000000000030020
+# CHECK: .shiftr           {{.*}} 0000000000030100
 
 ## Mailformed number error.
 # RUN: echo "SECTIONS { \
@@ -174,3 +181,9 @@
 
 .section .unary, "a"
 .quad 0
+
+.section .shiftl, "a"
+.quad 0
+
+.section .shiftr, "a"
+.quad 0
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -1081,10 +1081,12 @@
 
 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 @@
     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 == ">")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24860.72261.patch
Type: text/x-patch
Size: 2010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160923/c7138738/attachment.bin>


More information about the llvm-commits mailing list