]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gold/testsuite/relro_test.sh
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gold / testsuite / relro_test.sh
CommitLineData
fc497986
CC
1#!/bin/sh
2
3# relro_test.sh -- test -z relro
4
250d07de 5# Copyright (C) 2010-2021 Free Software Foundation, Inc.
fc497986
CC
6# Written by Cary Coutant <ccoutant@google.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
25# This test checks that the PT_GNU_RELRO segment is properly
26# aligned and is coincident with the beginning of the data segment.
27
28
29# Cleans a hexadecimal number for input to dc.
30clean_hex()
31{
32 echo "$1" | sed -e 's/0x//' -e 'y/abcdef/ABCDEF/'
33}
34
35check()
36{
37 # Get the address and length of the PT_GNU_RELRO segment.
38 RELRO_START=`grep GNU_RELRO "$1" | awk '{ print $3; }'`
39 RELRO_LEN=`grep GNU_RELRO "$1" | awk '{ print $6; }'`
40
41 if test -z "$RELRO_START"
42 then
43 echo "Did not find a PT_GNU_RELRO segment."
44 exit 1
45 fi
46
47 # Get the address and alignment of the PT_LOAD segment whose address
48 # matches the PT_GNU_RELRO segment.
49 LOAD_ALIGN=`grep LOAD "$1" | awk -v A=$RELRO_START '$3 == A { print $NF; }'`
50 LOAD_LEN=`grep LOAD "$1" | awk -v A=$RELRO_START '$3 == A { print $6; }'`
51
52 if test -z "$LOAD_LEN"
53 then
54 echo "Did not find a PT_LOAD segment matching the PT_GNU_RELRO segment."
55 exit 1
56 fi
57
58 # Compute the address of the end of the PT_GNU_RELRO segment,
59 # modulo the alignment of the PT_LOAD segment.
60 RELRO_START=`clean_hex "$RELRO_START"`
61 RELRO_LEN=`clean_hex "$RELRO_LEN"`
62 LOAD_ALIGN=`clean_hex "$LOAD_ALIGN"`
63 RELRO_END=`echo "16o 16i $RELRO_START $RELRO_LEN + p" | dc`
64 REM=`echo "16i $RELRO_END $LOAD_ALIGN % p" | dc`
65
07aead7b
ILT
66 if test "$REM" -eq 0; then
67 :
68 else
fc497986
CC
69 echo "PT_GNU_RELRO segment does not end at page boundary."
70 exit 1
71 fi
72}
73
74check relro_test.stdout