From 5379aebddd0a35c052e7149fb4ff88b49676516e Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Fri, 12 Sep 2014 12:31:05 +0530 Subject: Enhance tst-xmmymm.sh to detect zmm register usage in ld.so (BZ #16194) 2d63a517e4084ec80403cd9f278690fa8b676cc4 added support to save and restore zmm register in the dynamic linker, but did not enhance test-xmmymm.sh to detect accidental usage of these registers. The patch below adds that check. The script has also been renamed to tst-ld-sse-use.sh. To see the minimal changes, run `git show -M`. [BZ #16194] * sysdeps/x86/tst-xmmymm.sh: Rename file to... * sysdeps/x86/tst-ld-sse-use.sh: ... this. Check for zmm register usage. * sysdeps/x86/Makefile: Adjust. --- ChangeLog | 8 ++++ sysdeps/x86/Makefile | 4 +- sysdeps/x86/tst-ld-sse-use.sh | 103 ++++++++++++++++++++++++++++++++++++++++++ sysdeps/x86/tst-xmmymm.sh | 103 ------------------------------------------ 4 files changed, 113 insertions(+), 105 deletions(-) create mode 100755 sysdeps/x86/tst-ld-sse-use.sh delete mode 100755 sysdeps/x86/tst-xmmymm.sh diff --git a/ChangeLog b/ChangeLog index d528cab31e..7a3346af66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2014-09-12 Siddhesh Poyarekar + + [BZ #16194] + * sysdeps/x86/tst-xmmymm.sh: Rename file to... + * sysdeps/x86/tst-ld-sse-use.sh: ... this. Check for zmm + register usage. + * sysdeps/x86/Makefile: Adjust. + 2014-09-11 Kostya Serebryany Roland McGrath diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index a96c8bd0b2..087bbdeca0 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -2,8 +2,8 @@ ifeq ($(subdir),elf) CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),\ -mno-sse -mno-mmx) -tests-special += $(objpfx)tst-xmmymm.out -$(objpfx)tst-xmmymm.out: ../sysdeps/x86/tst-xmmymm.sh $(objpfx)ld.so +tests-special += $(objpfx)tst-ld-sse-use.out +$(objpfx)tst-ld-sse-use.out: ../sysdeps/x86/tst-ld-sse-use.sh $(objpfx)ld.so @echo "Checking ld.so for SSE register use. This will take a few seconds..." $(SHELL) $< $(objpfx) '$(NM)' '$(OBJDUMP)' '$(READELF)' > $@; \ $(evaluate-test) diff --git a/sysdeps/x86/tst-ld-sse-use.sh b/sysdeps/x86/tst-ld-sse-use.sh new file mode 100755 index 0000000000..c707ca9cc9 --- /dev/null +++ b/sysdeps/x86/tst-ld-sse-use.sh @@ -0,0 +1,103 @@ +#! /bin/bash +# Make sure no code in ld.so uses xmm/ymm/zmm registers on x86-64. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# . + +set -e + +objpfx="$1" +NM="$2" +OBJDUMP="$3" +READELF="$4" + +tmp=$(mktemp ${objpfx}tst-ld-sse-use.XXXXXX) +trap 'rm -f "$tmp"' 1 2 3 15 + +# List of object files we have to test +rtldobjs=$($READELF -W -wi ${objpfx}dl-allobjs.os | + awk '/^ "$tmp" +declare -a objects +objects=($(cat "$tmp")) + +objs="dl-runtime.os" +tocheck="dl-runtime.os" + +while test -n "$objs"; do + this="$objs" + objs="" + + for f in $this; do + undef=$($NM -u "$objpfx"../*/"$f" | awk '{print $2}') + if test -n "$undef"; then + for s in $undef; do + for obj in ${objects[*]} "_GLOBAL_OFFSET_TABLE_"; do + if test "$obj" = "$s"; then + continue 2 + fi + done + for o in $rtldobjs; do + ro=$(echo "$objpfx"../*/"$o") + if $NM -g --defined-only "$ro" | egrep -qs " $s\$"; then + if ! (echo "$tocheck $objs" | fgrep -qs "$o"); then + echo "$o needed for $s" + objs="$objs $o" + fi + break; + fi + done + done + fi + done + tocheck="$tocheck$objs" +done + +echo +echo +echo "object files needed: $tocheck" + +cp /dev/null "$tmp" +for f in $tocheck; do + $OBJDUMP -d "$objpfx"../*/"$f" | + awk 'BEGIN { last="" } /^[[:xdigit:]]* <[_[:alnum:]]*>:$/ { fct=substr($2, 2, length($2)-3) } /,%[xyz]mm[[:digit:]]*$/ { if (last != fct) { print fct; last=fct} }' | + while read fct; do + if test "$fct" = "_dl_runtime_profile" -o "$fct" = "_dl_x86_64_restore_sse"; then + continue; + fi + echo "function $fct in $f modifies xmm/ymm/zmm" >> "$tmp" + result=1 + done +done + +if test -s "$tmp"; then + echo + echo + cat "$tmp" + result=1 +else + result=0 +fi + +rm "$tmp" +exit $result diff --git a/sysdeps/x86/tst-xmmymm.sh b/sysdeps/x86/tst-xmmymm.sh deleted file mode 100755 index 69ddb587d4..0000000000 --- a/sysdeps/x86/tst-xmmymm.sh +++ /dev/null @@ -1,103 +0,0 @@ -#! /bin/bash -# Make sure no code in ld.so uses xmm/ymm registers on x86-64. -# Copyright (C) 2009-2014 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, see -# . - -set -e - -objpfx="$1" -NM="$2" -OBJDUMP="$3" -READELF="$4" - -tmp=$(mktemp ${objpfx}tst-xmmymm.XXXXXX) -trap 'rm -f "$tmp"' 1 2 3 15 - -# List of object files we have to test -rtldobjs=$($READELF -W -wi ${objpfx}dl-allobjs.os | - awk '/^ "$tmp" -declare -a objects -objects=($(cat "$tmp")) - -objs="dl-runtime.os" -tocheck="dl-runtime.os" - -while test -n "$objs"; do - this="$objs" - objs="" - - for f in $this; do - undef=$($NM -u "$objpfx"../*/"$f" | awk '{print $2}') - if test -n "$undef"; then - for s in $undef; do - for obj in ${objects[*]} "_GLOBAL_OFFSET_TABLE_"; do - if test "$obj" = "$s"; then - continue 2 - fi - done - for o in $rtldobjs; do - ro=$(echo "$objpfx"../*/"$o") - if $NM -g --defined-only "$ro" | egrep -qs " $s\$"; then - if ! (echo "$tocheck $objs" | fgrep -qs "$o"); then - echo "$o needed for $s" - objs="$objs $o" - fi - break; - fi - done - done - fi - done - tocheck="$tocheck$objs" -done - -echo -echo -echo "object files needed: $tocheck" - -cp /dev/null "$tmp" -for f in $tocheck; do - $OBJDUMP -d "$objpfx"../*/"$f" | - awk 'BEGIN { last="" } /^[[:xdigit:]]* <[_[:alnum:]]*>:$/ { fct=substr($2, 2, length($2)-3) } /,%[xy]mm[[:digit:]]*$/ { if (last != fct) { print fct; last=fct} }' | - while read fct; do - if test "$fct" = "_dl_runtime_profile" -o "$fct" = "_dl_x86_64_restore_sse"; then - continue; - fi - echo "function $fct in $f modifies xmm/ymm" >> "$tmp" - result=1 - done -done - -if test -s "$tmp"; then - echo - echo - cat "$tmp" - result=1 -else - result=0 -fi - -rm "$tmp" -exit $result -- cgit 1.4.1