lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # Make sure no code in ld.so uses xmm/ymm/zmm registers on x86-64. |
| 3 | # Copyright (C) 2009-2015 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 | set -e |
| 21 | |
| 22 | objpfx="$1" |
| 23 | NM="$2" |
| 24 | OBJDUMP="$3" |
| 25 | READELF="$4" |
| 26 | |
| 27 | tmp=$(mktemp ${objpfx}tst-ld-sse-use.XXXXXX) |
| 28 | trap 'rm -f "$tmp"' 1 2 3 15 |
| 29 | |
| 30 | # List of object files we have to test |
| 31 | rtldobjs=$($READELF -W -wi ${objpfx}dl-allobjs.os | |
| 32 | awk '/^ </ { if ($5 == "(DW_TAG_compile_unit)") c=1; else c=0 } $2 == "DW_AT_name" { if (c == 1) print $NF }' | |
| 33 | sed 's,\(.*/\|\)\([_[:alnum:]-]*[.]\).$,\2os,') |
| 34 | rtldobjs="$rtldobjs $(ar t ${objpfx}rtld-libc.a)" |
| 35 | |
| 36 | # OBJECT symbols can be ignored. |
| 37 | $READELF -sW ${objpfx}dl-allobjs.os ${objpfx}rtld-libc.a | |
| 38 | egrep " OBJECT *GLOBAL " | |
| 39 | awk '{if ($7 != "ABS") print $8 }' | |
| 40 | sort -u > "$tmp" |
| 41 | declare -a objects |
| 42 | objects=($(cat "$tmp")) |
| 43 | |
| 44 | objs="dl-runtime.os" |
| 45 | tocheck="dl-runtime.os" |
| 46 | |
| 47 | while test -n "$objs"; do |
| 48 | this="$objs" |
| 49 | objs="" |
| 50 | |
| 51 | for f in $this; do |
| 52 | undef=$($NM -u "$objpfx"../*/"$f" | awk '{print $2}') |
| 53 | if test -n "$undef"; then |
| 54 | for s in $undef; do |
| 55 | for obj in ${objects[*]} "_GLOBAL_OFFSET_TABLE_"; do |
| 56 | if test "$obj" = "$s"; then |
| 57 | continue 2 |
| 58 | fi |
| 59 | done |
| 60 | for o in $rtldobjs; do |
| 61 | ro=$(echo "$objpfx"../*/"$o") |
| 62 | if $NM -g --defined-only "$ro" | egrep -qs " $s\$"; then |
| 63 | if ! (echo "$tocheck $objs" | fgrep -qs "$o"); then |
| 64 | echo "$o needed for $s" |
| 65 | objs="$objs $o" |
| 66 | fi |
| 67 | break; |
| 68 | fi |
| 69 | done |
| 70 | done |
| 71 | fi |
| 72 | done |
| 73 | tocheck="$tocheck$objs" |
| 74 | done |
| 75 | |
| 76 | echo |
| 77 | echo |
| 78 | echo "object files needed: $tocheck" |
| 79 | |
| 80 | cp /dev/null "$tmp" |
| 81 | for f in $tocheck; do |
| 82 | $OBJDUMP -d "$objpfx"../*/"$f" | |
| 83 | awk 'BEGIN { last="" } /^[[:xdigit:]]* <[_[:alnum:]]*>:$/ { fct=substr($2, 2, length($2)-3) } /,%[xyz]mm[[:digit:]]*$/ { if (last != fct) { print fct; last=fct} }' | |
| 84 | while read fct; do |
| 85 | if test "$fct" = "_dl_runtime_profile" -o "$fct" = "_dl_x86_64_restore_sse"; then |
| 86 | continue; |
| 87 | fi |
| 88 | echo "function $fct in $f modifies xmm/ymm/zmm" >> "$tmp" |
| 89 | result=1 |
| 90 | done |
| 91 | done |
| 92 | |
| 93 | if test -s "$tmp"; then |
| 94 | echo |
| 95 | echo |
| 96 | cat "$tmp" |
| 97 | result=1 |
| 98 | else |
| 99 | result=0 |
| 100 | fi |
| 101 | |
| 102 | rm "$tmp" |
| 103 | exit $result |