blob: 280814e6debfffab0ce9dcfb392fdf277dd47dd8 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001#! /bin/sh
Roland McGrath521c47d2008-04-11 07:01:58 +00002# Copyright (C) 1999, 2000, 2002, 2003, 2005, 2007, 2008 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003# This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
Roland McGrath6d0c2e82006-04-05 00:59:43 +00005#
Mark Wielaardde2ed972012-06-05 17:15:16 +02006# This file is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or
9# (at your option) any later version.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000010#
Mark Wielaardde2ed972012-06-05 17:15:16 +020011# elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000012# WITHOUT ANY WARRANTY; without even the implied warranty of
Mark Wielaardde2ed972012-06-05 17:15:16 +020013# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000015#
Mark Wielaardde2ed972012-06-05 17:15:16 +020016# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000018
Roland McGrath1b8b4462005-11-16 01:33:38 +000019. $srcdir/test-subr.sh
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000020
21original=${original:-testfile11}
22stripped=${stripped:-testfile7}
23debugout=${debugfile:+-f testfile.debug.temp -F $debugfile}
24
Roland McGrath521c47d2008-04-11 07:01:58 +000025testfiles $original
26test x$stripped = xtestfile.temp || testfiles $stripped $debugfile
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000027
Roland McGrath4be15242007-04-25 03:09:33 +000028tempfiles testfile.temp testfile.debug.temp testfile.unstrip
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000029
Mark Wielaard86be7922013-04-26 23:44:25 +020030testrun ${abs_top_builddir}/src/strip -o testfile.temp $debugout $original
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000031
Roland McGrath9aa8ef72007-05-18 08:59:43 +000032status=0
33
34cmp $stripped testfile.temp || status=$?
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000035
36# Check elflint and the expected result.
Mark Wielaard22035602016-02-04 09:53:41 +010037testrun ${abs_top_builddir}/src/elflint --gnu -q testfile.temp || status=$?
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000038
39test -z "$debugfile" || {
Roland McGrath9aa8ef72007-05-18 08:59:43 +000040cmp $debugfile testfile.debug.temp || status=$?
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000041
42# Check elflint and the expected result.
Mark Wielaard22035602016-02-04 09:53:41 +010043testrun ${abs_top_builddir}/src/elflint --gnu -q -d testfile.debug.temp || status=$?
Roland McGrath4be15242007-04-25 03:09:33 +000044
45# Now test unstrip recombining those files.
Mark Wielaard86be7922013-04-26 23:44:25 +020046testrun ${abs_top_builddir}/src/unstrip -o testfile.unstrip testfile.temp testfile.debug.temp
Roland McGrath4be15242007-04-25 03:09:33 +000047
48# Check that it came back whole.
Mark Wielaard86be7922013-04-26 23:44:25 +020049testrun ${abs_top_builddir}/src/elfcmp --hash-inexact $original testfile.unstrip
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000050}
51
Mark Wielaarde0b32322017-06-07 14:05:36 +020052# test strip -g
53testrun ${abs_top_builddir}/src/strip -g -o testfile.temp $original
54
55# Buggy eu-strip created multiple .shstrtab sections
56shstrtab_SECS=$(testrun ${abs_top_builddir}/src/readelf -S testfile.temp | grep '.shstrtab' | wc --lines)
57test $shstrtab_SECS -eq 1 ||
58 { echo "*** failure not just one '.shstrtab' testfile.temp ($shstrtab_SECS)"; status=1; }
59
Mark Wielaard0d011652015-06-16 14:05:35 +020060# Now strip in-place and make sure it is smaller.
Mark Wielaard3a45dbb2015-10-04 23:47:47 +020061SIZE_original=$(stat -c%s $original)
62testrun ${abs_top_builddir}/src/strip $original
63SIZE_stripped=$(stat -c%s $original)
64test $SIZE_stripped -lt $SIZE_original ||
65 { echo "*** failure in-place strip file not smaller $original"; status=1; }
Mark Wielaard0d011652015-06-16 14:05:35 +020066
Roland McGrath521c47d2008-04-11 07:01:58 +000067tempfiles testfile.sections
Mark Wielaard86be7922013-04-26 23:44:25 +020068testrun ${abs_top_builddir}/src/readelf -S testfile.temp > testfile.sections || status=$?
Roland McGrath521c47d2008-04-11 07:01:58 +000069fgrep ' .debug_' testfile.sections && status=1
70
Roland McGrath9aa8ef72007-05-18 08:59:43 +000071exit $status