summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2016-09-23 13:13:55 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2016-09-23 13:13:55 +0000
commitc8ccd1f1c5cba21a36e65f284929499b2f7a31b5 (patch)
tree54c11496d33a6eaba70e2f680f847da46f2ee326
parent1ff60ef28673f613db887bebcb7971bac0d98ef7 (diff)
downloadbcm5719-llvm-c8ccd1f1c5cba21a36e65f284929499b2f7a31b5.tar.gz
bcm5719-llvm-c8ccd1f1c5cba21a36e65f284929499b2f7a31b5.zip
[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 llvm-svn: 282243
-rw-r--r--lld/ELF/LinkerScript.cpp14
-rw-r--r--lld/test/ELF/linkerscript/locationcounter.s13
2 files changed, 23 insertions, 4 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 74712a27f8c..1b240f46ae9 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -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, Expr R) {
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 == ">")
diff --git a/lld/test/ELF/linkerscript/locationcounter.s b/lld/test/ELF/linkerscript/locationcounter.s
index 8d9fa062a4f..529486c20e6 100644
--- a/lld/test/ELF/linkerscript/locationcounter.s
+++ b/lld/test/ELF/linkerscript/locationcounter.s
@@ -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
OpenPOWER on IntegriCloud