1#!/bin/sh
2
3# aarch64_tlsdesc.sh -- test R_AARCH64_TLSDESC_* relocations.
4
5# Copyright (C) 2017-2020 Free Software Foundation, Inc.
6# Written by Igor Kudrin <ikudrin@accesssoftek.com>.
7
8# This file is part of gold.
9
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 3 of the License, or
13# (at your option) any later version.
14
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23# MA 02110-1301, USA.
24
25file=aarch64_tlsdesc.stdout
26
27get_address_by_reloc()
28{
29    var=$1
30    pattern="\<R_AARCH64_TLSDESC\>"
31    found=$(grep "$pattern" "$file")
32    if test -z "$found"; then
33        echo "GOT entry for a TLS symbol is not found in file $file."
34        echo "Search pattern: $pattern"
35        echo ""
36        echo "Actual output below:"
37        cat "$file"
38        exit 1
39    fi
40    eval $var="0x0$(echo $found | awk -F'[: ]' '{ print $1 }')"
41}
42
43check_adrp()
44{
45    pattern="\<adrp[[:space:]]\+x0, 0\>"
46    found=$(grep "$pattern" "$file")
47    if test -z "$found"; then
48        echo "An ADRP immediate is supposed to be 0"
49        echo "Search pattern: $pattern"
50        echo ""
51        echo "Actual output below:"
52        cat "$file"
53        exit 1
54    fi
55}
56
57get_address_from_ldr()
58{
59    var=$1
60    pattern="\<ldr[[:space:]]\+x1\>"
61    found=$(grep "$pattern" "$file")
62    if test -z "$found"; then
63        echo "An LDR instruction is not found in file $file."
64        echo "Search pattern: $pattern"
65        echo ""
66        echo "Actual output below:"
67        cat "$file"
68        exit 1
69    fi
70    eval $var="$(echo $found | awk -F'[#\\]]' '{ print $2 }')"
71}
72
73get_address_from_add()
74{
75    var=$1
76    pattern="\<add[[:space:]]\+x0\>"
77    found=$(grep "$pattern" "$file")
78    if test -z "$found"; then
79        echo "An ADD instruction is not found in file $file."
80        echo "Search pattern: $pattern"
81        echo ""
82        echo "Actual output below:"
83        cat "$file"
84        exit 1
85    fi
86    eval $var="$(echo $found | awk -F'#' '{ print $2 }')"
87}
88
89check_adrp
90get_address_by_reloc address_by_reloc
91get_address_from_ldr address_from_ldr
92get_address_from_add address_from_add
93
94if test $(($address_by_reloc)) -ne $(($address_from_ldr)); then
95    echo "The address in LDR instruction is wrong."
96    echo ""
97    echo "Actual output below:"
98    cat "$file"
99    exit 1
100fi
101
102if test $(($address_by_reloc)) -ne $(($address_from_add)); then
103    echo "The address in ADD instruction is wrong."
104    echo ""
105    echo "Actual output below:"
106    cat "$file"
107    exit 1
108fi
109
110exit 0
111