1#!/usr/local/bin/bash
2# Copyright (C) 2017 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
20# When stripping just the debug sections/symbols we keep the symtab
21# in the main ELF file. There should be no symbols pointing into the
22# debug sections and so there should not be a copy in the debug file
23# except for a NOBITS one.
24
25tempfiles a.out strip.out debug.out readelf.out
26
27echo Create debug a.out.
28echo "int main() { return 1; }" | gcc -g -xc -
29
30echo strip -g to file with debug file
31testrun ${abs_top_builddir}/src/strip -g -o strip.out -f debug.out ||
32  { echo "*** failed to strip -g -o strip.out -f debug.out a.out"; exit -1; }
33
34status=0
35testrun ${abs_top_builddir}/src/readelf -S strip.out > readelf.out
36grep SYMTAB readelf.out || status=$?
37echo $status
38if test $status -ne 0; then
39  echo no symtab found in strip.out
40  exit 1
41fi
42
43status=0
44testrun ${abs_top_builddir}/src/readelf -S debug.out > readelf.out
45grep SYMTAB readelf.out || status=$?
46echo $status
47if test $status -ne 1; then
48  echo symtab found in debug.out
49  exit 1
50fi
51
52# arm (with data marker in .debug_frame). See tests/run-addrcfi.sh
53testfiles testfilearm
54
55echo arm strip -g to file with debug file
56testrun ${abs_top_builddir}/src/strip -g -o strip.out -f debug.out testfilearm ||
57  { echo "*** failed to strip -g -o strip.out -f debug.out a.out"; exit -1; }
58
59status=0
60testrun ${abs_top_builddir}/src/readelf -S strip.out > readelf.out
61grep SYMTAB readelf.out || status=$?
62echo $status
63if test $status -ne 0; then
64  echo no symtab found in strip.out
65  exit 1
66fi
67
68status=0
69testrun ${abs_top_builddir}/src/readelf -S debug.out > readelf.out
70grep SYMTAB readelf.out || status=$?
71echo $status
72if test $status -ne 1; then
73  echo symtab found in debug.out
74  exit 1
75fi
76
77# aarch64 (with data marker in .debug_frame). See tests/run-addrcfi.sh
78testfiles testfileaarch64
79
80echo aarch64 strip -g to file with debug file
81testrun ${abs_top_builddir}/src/strip -g -o strip.out -f debug.out testfileaarch64 ||
82  { echo "*** failed to strip -g -o strip.out -f debug.out a.out"; exit -1; }
83
84status=0
85testrun ${abs_top_builddir}/src/readelf -S strip.out > readelf.out
86grep SYMTAB readelf.out || status=$?
87echo $status
88if test $status -ne 0; then
89  echo no symtab found in strip.out
90  exit 1
91fi
92
93status=0
94testrun ${abs_top_builddir}/src/readelf -S debug.out > readelf.out
95grep SYMTAB readelf.out || status=$?
96echo $status
97if test $status -ne 1; then
98  echo symtab found in debug.out
99  exit 1
100fi
101
102exit 0
103