Add copyright notices to testsuite shell scripts
[platform/upstream/glibc.git] / sysdeps / x86_64 / tst-xmmymm.sh
1 #! /bin/bash
2 # Make sure no code in ld.so uses xmm/ymm registers on x86-64.
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
19
20 objpfx="$1"
21
22 tmp=$(mktemp ${objpfx}tst-xmmymm.XXXXXX)
23 trap 'rm -f "$tmp"' 1 2 3 15
24
25 # List of object files we have to test
26 rtldobjs=$(readelf -W -wi ${objpfx}dl-allobjs.os |
27     awk '/^ </ { if ($5 == "(DW_TAG_compile_unit)") c=1; else c=0 } $2 == "DW_AT_name" { if (c == 1) print $NF }' |
28     sed 's,\(.*/\|\)\([_[:alnum:]-]*[.]\).$,\2os,')
29 rtldobjs="$rtldobjs $(ar t ${objpfx}rtld-libc.a)"
30
31 # OBJECT symbols can be ignored.
32 readelf -sW ${objpfx}dl-allobjs.os ${objpfx}rtld-libc.a |
33 egrep " OBJECT  *GLOBAL " |
34 awk '{if ($7 != "ABS") print $8 }' |
35 sort -u > "$tmp"
36 declare -a objects
37 objects=($(cat "$tmp"))
38
39 objs="dl-runtime.os"
40 tocheck="dl-runtime.os"
41
42 while test -n "$objs"; do
43   this="$objs"
44   objs=""
45
46   for f in $this; do
47     undef=$(nm -u "$objpfx"../*/"$f" | awk '{print $2}')
48     if test -n "$undef"; then
49       for s in $undef; do
50         for obj in ${objects[*]} "_GLOBAL_OFFSET_TABLE_"; do
51           if test "$obj" = "$s"; then
52             continue 2
53           fi
54         done
55         for o in $rtldobjs; do
56           ro=$(echo "$objpfx"../*/"$o")
57           if nm -g --defined-only "$ro" | egrep -qs " $s\$"; then
58             if ! (echo "$tocheck $objs" | fgrep -qs "$o"); then
59               echo "$o needed for $s"
60               objs="$objs $o"
61             fi
62             break;
63           fi
64         done
65       done
66     fi
67   done
68   tocheck="$tocheck$objs"
69 done
70
71 echo
72 echo
73 echo "object files needed: $tocheck"
74
75 cp /dev/null "$tmp"
76 for f in $tocheck; do
77   objdump -d "$objpfx"../*/"$f" |
78   awk 'BEGIN { last="" } /^[[:xdigit:]]* <[_[:alnum:]]*>:$/ { fct=substr($2, 2, length($2)-3) } /,%[xy]mm[[:digit:]]*$/ { if (last != fct) { print fct; last=fct} }' |
79   while read fct; do
80     if test "$fct" = "_dl_runtime_profile" -o "$fct" = "_dl_x86_64_restore_sse"; then
81       continue;
82     fi
83     echo "function $fct in $f modifies xmm/ymm" >> "$tmp"
84     result=1
85   done
86 done
87
88 if test -s "$tmp"; then
89   echo
90   echo
91   cat "$tmp"
92   result=1
93 else
94   result=0
95 fi
96
97 rm "$tmp"
98 exit $result