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 20 testfiles hello_i386.ko hello_x86_64.ko hello_ppc64.ko hello_s390.ko \ 21 hello_aarch64.ko 22 23 tempfiles readelf.out readelf.out1 readelf.out2 24 tempfiles out.stripped1 out.debug1 out.stripped2 out.debug2 25 26 status=0 27 runtest() { 28 infile=$1 29 is_ET_REL=$2 30 outfile1=out.stripped1 31 debugfile1=out.debug1 32 outfile2=out.stripped2 33 debugfile2=out.debug2 34 35 testrun ${abs_top_builddir}/src/strip -o $outfile1 -f $debugfile1 $infile || 36 { echo "*** failure strip $infile"; status=1; } 37 38 testrun ${abs_top_builddir}/src/strip --reloc-debug-sections -o $outfile2 \ 39 -f $debugfile2 $infile || 40 { echo "*** failure strip --reloc-debug-sections $infile"; status=1; } 41 42 # shouldn't make any difference for stripped files. 43 testrun ${abs_top_builddir}/src/readelf -a $outfile1 > readelf.out || 44 { echo "*** failure readelf -a outfile1 $infile"; status=1; } 45 46 testrun_compare ${abs_top_builddir}/src/readelf -a $outfile2 < readelf.out || 47 { echo "*** failure compare stripped files $infile"; status=1; } 48 49 # debug files however should be smaller, when ET_REL. 50 SIZE1=$(stat -c%s $debugfile1) 51 SIZE2=$(stat -c%s $debugfile2) 52 test \( \( $is_ET_REL -eq 1 \) -a \( $SIZE1 -gt $SIZE2 \) \) \ 53 -o \( \( $is_ET_REL -eq 0 \) -a \( $SIZE1 -eq $SIZE2 \) \) || 54 { echo "*** failure --reloc-debug-sections not smaller $infile"; status=1; } 55 56 # Strip of DWARF section lines, offset will not match. 57 # Everything else should match. 58 testrun ${abs_top_builddir}/src/readelf -w $debugfile1 \ 59 | grep -v ^DWARF\ section > readelf.out1 || 60 { echo "*** failure readelf -w debugfile1 $infile"; status=1; } 61 62 testrun ${abs_top_builddir}/src/readelf -w $debugfile2 \ 63 | grep -v ^DWARF\ section > readelf.out2 || 64 { echo "*** failure readelf -w debugfile2 $infile"; status=1; } 65 66 testrun_compare cat readelf.out1 < readelf.out2 || 67 { echo "*** failure readelf -w compare $infile"; status=1; } 68 } 69 70 # Most simple hello world kernel module for various architectures. 71 # :::::::::::::: 72 # Makefile 73 # :::::::::::::: 74 # obj-m := hello.o 75 # hello-y := init.o exit.o 76 # 77 # all: 78 # make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 79 # :::::::::::::: 80 # init.c 81 # :::::::::::::: 82 # #include <linux/kernel.h> 83 # #include <linux/module.h> 84 # 85 # int init_module(void) 86 # { 87 # printk(KERN_INFO "Hello, world!\n"); 88 # return 0; 89 # } 90 # :::::::::::::: 91 # exit.c 92 # :::::::::::::: 93 # #include <linux/kernel.h> 94 # #include <linux/module.h> 95 # 96 # void cleanup_module() 97 # { 98 # printk(KERN_INFO "Goodbye, World!\n"); 99 # } 100 runtest hello_i386.ko 1 101 runtest hello_x86_64.ko 1 102 runtest hello_ppc64.ko 1 103 runtest hello_s390.ko 1 104 runtest hello_aarch64.ko 1 105 106 # self test, shouldn't impact non-ET_REL files at all. 107 runtest ${abs_top_builddir}/src/strip 0 108 runtest ${abs_top_builddir}/src/strip.o 1 109 110 exit $status 111