3 # relro_test.sh -- test -z relro
5 # Copyright 2010 Free Software Foundation, Inc.
6 # Written by Cary Coutant <ccoutant@google.com>.
8 # This file is part of gold.
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.
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.
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,
25 # This test checks that the PT_GNU_RELRO segment is properly
26 # aligned and is coincident with the beginning of the data segment.
29 # Cleans a hexadecimal number for input to dc.
32 echo "$1" |
sed -e 's/0x//' -e 'y/abcdef/ABCDEF/'
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; }'`
41 if test -z "$RELRO_START"
43 echo "Did not find a PT_GNU_RELRO segment."
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; }'`
52 if test -z "$LOAD_LEN"
54 echo "Did not find a PT_LOAD segment matching the PT_GNU_RELRO segment."
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`
68 echo "PT_GNU_RELRO segment does not end at page boundary."
73 check relro_test.stdout