From c8ccd1f1c5cba21a36e65f284929499b2f7a31b5 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 23 Sep 2016 13:13:55 +0000 Subject: [PATCH] [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 --- lld/ELF/LinkerScript.cpp | 14 ++++++++++---- lld/test/ELF/linkerscript/locationcounter.s | 13 +++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 74712a2..1b240f4 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(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 8d9fa06..529486c 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 -- 2.7.4