hppa: fix loading of global pointer in _start [BZ #20277]
[glibc.git] / sysdeps / nacl / nacl-after-link.sh
blobf59ac0981fc78087b5f4ebf5b25a3289c1b27f19
1 #!/bin/sh
2 # Script to validate NaCl binaries after linking.
4 # Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 # This file is part of the GNU C Library.
7 # The GNU C Library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # The GNU C Library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with the GNU C Library; if not, see
19 # <http://www.gnu.org/licenses/>.
21 # See sysdeps/nacl/Makefile for how this script is invoked.
22 READELF="$1"
23 binary="$2"
25 if [ -z "$NACL_SDK_ROOT" ]; then
26 echo >&2 "$0: NACL_SDK_ROOT must be set in the environment"
27 exit 77
30 ncval="${NACL_SDK_ROOT}/tools/ncval"
32 if [ ! -x "$ncval" ]; then
33 echo >&2 "$0: No ncval binary in $ncval"
34 exit 77
37 "${READELF}" -Wl "$binary" | awk '
38 BEGIN { saw_load = saw_text = 0 }
39 $1 == "LOAD" {
40 saw_load = 1;
41 if (/ R.E /) saw_code = 1;
43 END {
44 exit (saw_code ? 11 : saw_load ? 22 : 1);
47 case $? in
48 11)
49 # We saw a code segment, so we can try ncval.
51 22)
52 # We saw LOAD segments but none of them were code.
53 echo >&2 "+++ No code: $binary"
54 exit 0
57 # Something funny going on.
58 echo >&2 "*** Failed to analyze: $binary"
59 exit 2
61 esac
63 if "$ncval" "$binary"; then
64 echo >&2 "+++ Validated: $binary"
65 exit 0
66 else
67 echo >&2 "*** Validation failed: $binary"
68 exit 2