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 20testfiles hello_i386.ko hello_x86_64.ko hello_ppc64.ko hello_s390.ko \ 21 hello_aarch64.ko hello_m68k.ko hello_riscv64.ko hello_csky.ko 22 23tempfiles readelf.out readelf.out1 readelf.out2 24tempfiles out.stripped1 out.debug1 out.stripped2 out.debug2 25 26status=0 27runtest() { 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 echo "runtest $infile" 36 37 rm -f $outfile1 $debugfile1 $outfile2 $debugfile2 38 39 testrun ${abs_top_builddir}/src/strip -o $outfile1 -f $debugfile1 $infile || 40 { echo "*** failure strip $infile"; status=1; } 41 42 testrun ${abs_top_builddir}/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 ${abs_top_builddir}/src/readelf -a $outfile1 > readelf.out || 48 { echo "*** failure readelf -a outfile1 $infile"; status=1; } 49 50 testrun_compare ${abs_top_builddir}/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 ${abs_top_builddir}/src/readelf -w $debugfile1 \ 63 | grep -v ^DWARF\ section > readelf.out1 || 64 { echo "*** failure readelf -w debugfile1 $infile"; status=1; } 65 66 testrun ${abs_top_builddir}/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 testrun ${abs_top_builddir}/src/strip --reloc-debug-sections-only \ 74 $debugfile1 || 75 { echo "*** failure strip --reloc-debug-sections-only $debugfile1"; \ 76 status=1; } 77 78 cmp $debugfile1 $debugfile2 || 79 { echo "*** failure --reloc-debug-sections[-only] $debugfile1 $debugfile2"; \ 80 status=1; } 81} 82 83# Most simple hello world kernel module for various architectures. 84# Make sure that it contains debuginfo with CONFIG_DEBUG_INFO=y. 85# :::::::::::::: 86# Makefile 87# :::::::::::::: 88# obj-m := hello.o 89# hello-y := init.o exit.o 90# 91# all: 92# make -C /lib/modules/$(shell uname -r)/build M=$(PWD) \ 93# CONFIG_DEBUG_INFO=y modules 94# :::::::::::::: 95# init.c 96# :::::::::::::: 97# #include <linux/kernel.h> 98# #include <linux/module.h> 99# 100# int init_module(void) 101# { 102# printk(KERN_INFO "Hello, world!\n"); 103# return 0; 104# } 105# :::::::::::::: 106# exit.c 107# :::::::::::::: 108# #include <linux/kernel.h> 109# #include <linux/module.h> 110# 111# void cleanup_module() 112# { 113# printk(KERN_INFO "Goodbye, World!\n"); 114# } 115runtest hello_i386.ko 1 116runtest hello_x86_64.ko 1 117runtest hello_ppc64.ko 1 118runtest hello_s390.ko 1 119runtest hello_aarch64.ko 1 120runtest hello_m68k.ko 1 121runtest hello_riscv64.ko 1 122runtest hello_csky.ko 1 123 124# self test, shouldn't impact non-ET_REL files at all. 125runtest ${abs_top_builddir}/src/strip 0 126runtest ${abs_top_builddir}/src/strip.o 1 127 128# Copy ET_REL file for self-test and make sure to run with/without 129# elf section compression. 130tempfiles strip-uncompressed.o strip-compressed.o 131testrun ${abs_top_builddir}/src/elfcompress -o strip-uncompressed.o -t none \ 132 ${abs_top_builddir}/src/strip.o 133testrun ${abs_top_builddir}/src/elfcompress -o strip-compressed.o -t zlib \ 134 --force ${abs_top_builddir}/src/strip.o 135 136runtest strip-uncompressed.o 1 137runtest strip-compressed.o 1 138 139# See run-readelf-zdebug-rel.sh 140testfiles testfile-debug-rel-ppc64.o 141runtest testfile-debug-rel-ppc64.o 1 142 143testfiles testfile-debug-rel-ppc64-z.o 144runtest testfile-debug-rel-ppc64-z.o 1 145 146testfiles testfile-debug-rel-ppc64-g.o 147runtest testfile-debug-rel-ppc64-g.o 1 148 149exit $status 150