• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /usr/bin/env bash
2# Copyright (C) 2019 Red Hat, Inc.
3# Copyright (C) 2022 Mark J. Wielaard <mark@klomp.org>
4# This file is part of elfutils.
5#
6# 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.
10#
11# elfutils is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# 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/>.
18
19. $srcdir/test-subr.sh
20
21# Only run on 64bit systems, 32bit systems don't support > 4GB
22# ELF files.
23long_bit=$(getconf LONG_BIT)
24echo "long_bit: $long_bit"
25if test $long_bit -ne 64; then
26  echo "Only 64bit systems can create > 4GB ELF files"
27  exit 77
28fi
29
30# The test binary also needs to be 64bits itself
31elfclass=64
32testrun ${abs_top_builddir}/src/readelf -h ${abs_builddir}/addsections | grep ELF32 \
33	&& elfclass=32
34echo elfclass: $elfclass
35if test $elfclass -ne 64; then
36  echo "Only 64bit binaries can create > 4GB ELF files"
37  exit 77
38fi
39
40# These tests need lots of disk space since they test files > 4GB.
41# Skip if there just isn't enough (2.5 * 4 = 10GB).
42space_available=$[$(stat -f --format="%a*%S" .)/(1024 * 1024 * 1024)]
43echo "space_available: $space_available"
44if test $space_available -lt 10; then
45  echo "Not enough disk space, need at least 10GB available"
46  exit 77
47fi
48
49# Make sure the files fit into memory, assume 6GB needed (2.5 * 2 + 1 extra).
50# Running under valgrind might need even more.
51mem_needed=6
52if [ "x$VALGRIND_CMD" != "x" ]; then
53  mem_needed=$[${mem_needed} + 2]
54fi
55echo "mem_needed: $mem_needed"
56mem_available=$(free -g 2>/dev/null | grep ^Mem: | awk -F ' +' '{print $7}')
57echo "mem_available: $mem_available"
58if test -z "$mem_available" || test $mem_available -lt $mem_needed; then
59  echo "Need at least ${mem_needed}GB free available memory"
60  exit 77
61fi
62
63# Make sure the disk is reasonably fast, should be able to write 100MB/s
64fast_disk=1
65timeout -s9 10s dd conv=fsync if=/dev/zero of=tempfile bs=1M count=1K \
66  || fast_disk=0; rm tempfile
67if test $fast_disk -eq 0; then
68  echo "File system not fast enough, need at least 100MB/s"
69  exit 77
70fi
71
72# NOTE: test file will be mangled and removed!
73test_file ()
74{
75  in_file="$1"
76  readelf_out="${in_file}.readelf.out"
77  out_file_strip="${in_file}.strip"
78  out_file_debug="${in_file}.debug"
79
80  testfiles ${in_file}
81  tempfiles ${readelf_out} ${out_file_mmap} ${out_file_strip} ${out_file_debug}
82
83  # Add two 2GB sections to the file.
84  echo "addsections 2 ${in_file} 2147483648"
85  testrun ${abs_builddir}/addsections 2 ${in_file} 2147483648
86  testrun ${abs_top_builddir}/src/readelf -S ${in_file} > ${readelf_out}
87  nr=$(grep '.extra' ${readelf_out} | wc -l)
88  if test ${nr} != 2; then
89    # Show what went wrong
90    cat ${readelf_out}
91    exit 1
92  fi
93
94  echo "strip -o ${out_file_strip} -f ${out_file_debug} ${in_file}"
95  testrun ${abs_top_builddir}/src/strip -o ${out_file_strip} \
96                                        -f ${out_file_debug} ${in_file}
97
98  echo "elflint --gnu ${out_file_strip}"
99  testrun ${abs_top_builddir}/src/elflint --gnu ${out_file_strip}
100
101  echo "elflint --gnu -d ${out_file_debug}"
102  testrun ${abs_top_builddir}/src/elflint --gnu -d ${out_file_debug}
103
104  # Now test unstrip recombining those files.
105  echo "unstrip ${out_file_strip} ${out_file_debug}"
106  testrun ${abs_top_builddir}/src/unstrip ${out_file_strip} ${out_file_debug}
107
108  echo "elfcmp ${out_file} ${out_file_strip}"
109  testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file_debug}
110
111  # Remove the temp files immediately, they are big...
112  rm -f ${in_file} ${out_file_strip} ${out_file_debug}
113}
114
115# A collection of random testfiles to test 64bit, little/big endian
116# and non-ET_REL (with phdrs)/ET_REL (without phdrs).
117# Don't test 32bit, they cannot go beyond 4GB.
118
119# 64bit, little endian, rel
120test_file testfile38
121
122# 64bit, big endian, non-rel
123test_file testfile27
124
125exit 0
126