0f4919ad1f6c927c3ec7dccd6bdee35e3d1d3654
[platform/upstream/elfutils.git] / tests / run-strip-reloc.sh
1 #! /bin/sh
2 # Copyright (C) 2011 Red Hat, Inc.
3 # This file is part of Red Hat elfutils.
4 #
5 # Red Hat elfutils is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; version 2 of the License.
8 #
9 # Red Hat elfutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Red Hat elfutils; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
17 #
18 # Red Hat elfutils is an included package of the Open Invention Network.
19 # An included package of the Open Invention Network is a package for which
20 # Open Invention Network licensees cross-license their patents.  No patent
21 # license is granted, either expressly or impliedly, by designation as an
22 # included package.  Should you wish to participate in the Open Invention
23 # Network licensing program, please visit www.openinventionnetwork.com
24 # <http://www.openinventionnetwork.com>.
25
26 . $srcdir/test-subr.sh
27
28 testfiles hello_i386.ko hello_x86_64.ko hello_ppc64.ko hello_s390.ko
29
30 status=0
31 runtest() {
32   infile=$1
33   is_ET_REL=$2
34   outfile1=out.stripped1
35   debugfile1=out.debug1
36   outfile2=out.stripped2
37   debugfile2=out.debug2
38
39   testrun ../src/strip -o $outfile1 -f $debugfile1 $infile ||
40   { echo "*** failure strip $infile"; status=1; }
41
42   testrun ../src/strip --reloc-debug-sections -o $outfile2 \
43         -f $debugfile2 $infile ||
44   { echo "*** failure strip --reloc-debug-sections $infile"; status=1; }
45
46   # shouldn't make any difference for stripped files.
47   testrun ../src/readelf -a $outfile1 > readelf.out ||
48   { echo "*** failure readelf -a outfile1 $infile"; status=1; }
49
50   testrun_compare ../src/readelf -a $outfile2 < readelf.out ||
51   { echo "*** failure compare stripped files $infile"; status=1; }
52
53   # debug files however should be smaller, when ET_REL.
54   SIZE1=$(stat -c%s $debugfile1)
55   SIZE2=$(stat -c%s $debugfile2)
56   test \( \( $is_ET_REL -eq 1 \) -a \( $SIZE1 -gt $SIZE2 \) \) \
57         -o \( \( $is_ET_REL -eq 0 \) -a \( $SIZE1 -eq $SIZE2 \) \) ||
58   { echo "*** failure --reloc-debug-sections not smaller $infile"; status=1; }
59
60   # Strip of DWARF section lines, offset will not match.
61   # Everything else should match.
62   testrun ../src/readelf -w $debugfile1 \
63         | grep -v ^DWARF\ section > readelf.out1 ||
64   { echo "*** failure readelf -w debugfile1 $infile"; status=1; }
65
66   testrun ../src/readelf -w $debugfile2 \
67         | grep -v ^DWARF\ section > readelf.out2 ||
68   { echo "*** failure readelf -w debugfile2 $infile"; status=1; }
69
70   testrun_compare cat readelf.out1 < readelf.out2 ||
71   { echo "*** failure readelf -w compare $infile"; status=1; }
72
73   rm -f $outfile1 $debugfile1 $outfile2 $debugfile2 readelf.out*
74 }
75
76 # Most simple hello world kernel module for various architectures.
77 # ::::::::::::::
78 # Makefile
79 # ::::::::::::::
80 # obj-m := hello.o
81 # hello-y := init.o exit.o
82
83 # all:
84 #       make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
85 # ::::::::::::::
86 # init.c
87 # ::::::::::::::
88 # #include <linux/kernel.h>
89 # #include <linux/module.h>
90
91 # int init_module(void)
92 # {
93 #   printk(KERN_INFO "Hello, world!\n");
94 #   return 0;
95 # }
96 # ::::::::::::::
97 # exit.c
98 # ::::::::::::::
99 # #include <linux/kernel.h>
100 # #include <linux/module.h>
101
102 # void cleanup_module()
103 # {
104 #   printk(KERN_INFO "Goodbye, World!\n");
105 # }
106 runtest hello_i386.ko 1
107 runtest hello_x86_64.ko 1
108 runtest hello_ppc64.ko 1
109 runtest hello_s390.ko 1
110
111 # self test, shouldn't impact non-ET_REL files at all.
112 runtest ../src/strip 0
113 runtest ../src/strip.o 1
114
115 exit $status