1#! /bin/sh 2# Copyright (C) 2011, 2013 Red Hat, Inc. 3# This file is part of elfutils. 4# 5# This file is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 3 of the License, or 8# (at your option) any later version. 9# 10# elfutils is distributed in the hope that it will be useful, but 11# WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18. $srcdir/test-subr.sh 19 20if test -n "$ELFUTILS_MEMORY_SANITIZER"; then 21 echo "binaries linked with memory sanitizer are too big" 22 exit 77 23fi 24 25tempfiles readelf.out1 readelf.out2 26tempfiles out.stripped1 out.debug1 out.stripped2 out.debug2 27 28runtest_status=0 29runtest() { 30 infile=$1 31 is_ET_REL=$2 32 outfile1=out.stripped1 33 debugfile1=out.debug1 34 outfile2=out.stripped2 35 debugfile2=out.debug2 36 37 echo "runtest $infile" 38 39 rm -f $outfile1 $debugfile1 $outfile2 $debugfile2 40 41 testrun ${abs_top_builddir}/src/strip -o $outfile1 -f $debugfile1 $infile || 42 { echo "*** failure strip $infile"; runtest_status=1; } 43 44 testrun ${abs_top_builddir}/src/strip --reloc-debug-sections -o $outfile2 \ 45 -f $debugfile2 $infile || 46 { echo "*** failure strip --reloc-debug-sections $infile"; runtest_status=1; } 47 48 testrun ${abs_top_builddir}/src/elfcmp $outfile1 $outfile2 || 49 { echo "*** failure compare stripped files $infile"; runtest_status=1; } 50 51 # debug files however should be smaller, when ET_REL. 52 SIZE1=$(stat -c%s $debugfile1) 53 SIZE2=$(stat -c%s $debugfile2) 54 test \( \( $is_ET_REL -eq 1 \) -a \( $SIZE1 -gt $SIZE2 \) \) \ 55 -o \( \( $is_ET_REL -eq 0 \) -a \( $SIZE1 -eq $SIZE2 \) \) || 56 { echo "*** failure --reloc-debug-sections not smaller $infile"; runtest_status=1; } 57 58 # Strip of DWARF section lines, offset will not match. 59 # Everything else should match. 60 testrun ${abs_top_builddir}/src/readelf -N -w $debugfile1 \ 61 | grep -v ^DWARF\ section > readelf.out1 || 62 { echo "*** failure readelf -N -w debugfile1 $infile"; runtest_status=1; } 63 64 testrun ${abs_top_builddir}/src/readelf -N -w $debugfile2 \ 65 | grep -v ^DWARF\ section > readelf.out2 || 66 { echo "*** failure readelf -N -w debugfile2 $infile"; runtest_status=1; } 67 68 testrun_compare cat readelf.out1 < readelf.out2 || 69 { echo "*** failure readelf -N -w compare $infile"; runtest_status=1; } 70 71 testrun ${abs_top_builddir}/src/strip --reloc-debug-sections-only \ 72 $debugfile1 || 73 { echo "*** failure strip --reloc-debug-sections-only $debugfile1"; \ 74 runtest_status=1; } 75 76 cmp $debugfile1 $debugfile2 || 77 { echo "*** failure --reloc-debug-sections[-only] $debugfile1 $debugfile2"; \ 78 runtest_status=1; } 79} 80