1#! /usr/bin/env bash 2# Copyright (C) 2019 Red Hat, Inc. 3# Copyright (C) 2022 Mark J. Wielaard <[email protected]> 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 125# See testfile-dwp-cu-index-overflow.source 126testfiles testfile-dwp-5-cu-index-overflow testfile-dwp-5-cu-index-overflow.dwp 127 128testrun_compare ${abs_builddir}/cu-dwp-section-info testfile-dwp-5-cu-index-overflow.dwp << EOF 129file: testfile-dwp-5-cu-index-overflow.dwp 130INFO: 0x0 0x8000004c 131TYPES: 0x0 0x0 132ABBREV: 0x0 0x50 133LINE: 0x0 0x61 134LOCLISTS: 0x0 0x0 135STR_OFFSETS: 0x0 0x1c 136MACRO: 0x0 0x0 137RNGLISTS: 0x0 0x0 138 139INFO: 0x8000004c 0x6f 140TYPES: 0x0 0x0 141ABBREV: 0x50 0x15e 142LINE: 0x61 0x63 143LOCLISTS: 0x0 0xd4 144STR_OFFSETS: 0x1c 0x24 145MACRO: 0x0 0x0 146RNGLISTS: 0x0 0x22 147 148INFO: 0x800000bb 0xff 149TYPES: 0x0 0x0 150ABBREV: 0x50 0x15e 151LINE: 0x61 0x63 152LOCLISTS: 0x0 0xd4 153STR_OFFSETS: 0x1c 0x24 154MACRO: 0x0 0x0 155RNGLISTS: 0x0 0x22 156 157INFO: 0x800001ba 0x8000004c 158TYPES: 0x0 0x0 159ABBREV: 0x1ae 0x50 160LINE: 0xc4 0x61 161LOCLISTS: 0x0 0x0 162STR_OFFSETS: 0x40 0x1c 163MACRO: 0x0 0x0 164RNGLISTS: 0x0 0x0 165 166INFO: 0x100000206 0x6c 167TYPES: 0x0 0x0 168ABBREV: 0x1fe 0xc8 169LINE: 0x125 0x63 170LOCLISTS: 0x0 0x0 171STR_OFFSETS: 0x5c 0x20 172MACRO: 0x0 0x0 173RNGLISTS: 0x0 0x0 174 175INFO: 0x100000272 0x6f 176TYPES: 0x0 0x0 177ABBREV: 0x1fe 0xc8 178LINE: 0x125 0x63 179LOCLISTS: 0x0 0x0 180STR_OFFSETS: 0x5c 0x20 181MACRO: 0x0 0x0 182RNGLISTS: 0x0 0x0 183 184INFO: 0x1000002e1 0x182 185TYPES: 0x0 0x0 186ABBREV: 0x2c6 0x188 187LINE: 0x188 0x65 188LOCLISTS: 0xd4 0xee 189STR_OFFSETS: 0x7c 0x44 190MACRO: 0x0 0x0 191RNGLISTS: 0x22 0x43 192 193EOF 194 195testrun_compare ${abs_builddir}/get-units-split testfile-dwp-5-cu-index-overflow << EOF 196file: testfile-dwp-5-cu-index-overflow 197Got cudie unit_type: 4 198Found a skeleton unit, with split die: filler1.cc 199Got cudie unit_type: 4 200Found a skeleton unit, with split die: foo.cc 201Got cudie unit_type: 4 202Found a skeleton unit, with split die: filler2.cc 203Got cudie unit_type: 4 204Found a skeleton unit, with split die: bar.cc 205Got cudie unit_type: 4 206Found a skeleton unit, with split die: main.cc 207 208EOF 209 210rm -f testfile-dwp-5-cu-index-overflow testfile-dwp-5-cu-index-overflow.dwp 211 212# See testfile-dwp-cu-index-overflow.source 213testfiles testfile-dwp-4-cu-index-overflow testfile-dwp-4-cu-index-overflow.dwp 214 215testrun_compare ${abs_builddir}/cu-dwp-section-info testfile-dwp-4-cu-index-overflow.dwp << EOF 216file: testfile-dwp-4-cu-index-overflow.dwp 217INFO: 0x0 0x8000004b 218TYPES: 0x0 0x0 219ABBREV: 0x0 0x58 220LINE: 0x0 0x2c 221LOCLISTS: 0x0 0x0 222STR_OFFSETS: 0x0 0x14 223MACRO: 0x0 0x0 224RNGLISTS: 0x0 0x0 225 226INFO: 0x8000004b 0x116 227TYPES: 0x0 0x0 228ABBREV: 0x58 0x16f 229LINE: 0x2c 0x34 230LOCLISTS: 0x0 0x110 231STR_OFFSETS: 0x14 0x1c 232MACRO: 0x0 0x0 233RNGLISTS: 0x0 0x0 234 235INFO: 0x80000161 0x8000004b 236TYPES: 0x0 0x0 237ABBREV: 0x1c7 0x58 238LINE: 0x60 0x2c 239LOCLISTS: 0x0 0x0 240STR_OFFSETS: 0x30 0x14 241MACRO: 0x0 0x0 242RNGLISTS: 0x0 0x0 243 244INFO: 0x1000001ac 0x6e 245TYPES: 0x0 0x0 246ABBREV: 0x21f 0xd4 247LINE: 0x8c 0x34 248LOCLISTS: 0x0 0x0 249STR_OFFSETS: 0x44 0x18 250MACRO: 0x0 0x0 251RNGLISTS: 0x0 0x0 252 253INFO: 0x10000021a 0x1b5 254TYPES: 0x0 0x0 255ABBREV: 0x2f3 0x19b 256LINE: 0xc0 0x35 257LOCLISTS: 0x110 0x12a 258STR_OFFSETS: 0x5c 0x3c 259MACRO: 0x0 0x0 260RNGLISTS: 0x0 0x0 261 262INFO: 0x0 0x0 263TYPES: 0x0 0x6e 264ABBREV: 0x58 0x16f 265LINE: 0x2c 0x34 266LOCLISTS: 0x0 0x110 267STR_OFFSETS: 0x14 0x1c 268MACRO: 0x0 0x0 269RNGLISTS: 0x0 0x0 270 271INFO: 0x0 0x0 272TYPES: 0x6e 0x6b 273ABBREV: 0x21f 0xd4 274LINE: 0x8c 0x34 275LOCLISTS: 0x0 0x0 276STR_OFFSETS: 0x44 0x18 277MACRO: 0x0 0x0 278RNGLISTS: 0x0 0x0 279 280EOF 281 282testrun_compare ${abs_builddir}/get-units-split testfile-dwp-4-cu-index-overflow << EOF 283file: testfile-dwp-4-cu-index-overflow 284Got cudie unit_type: 4 285Found a skeleton unit, with split die: filler1.cc 286Got cudie unit_type: 4 287Found a skeleton unit, with split die: foo.cc 288Got cudie unit_type: 4 289Found a skeleton unit, with split die: filler2.cc 290Got cudie unit_type: 4 291Found a skeleton unit, with split die: bar.cc 292Got cudie unit_type: 4 293Found a skeleton unit, with split die: main.cc 294 295EOF 296 297rm -f testfile-dwp-4-cu-index-overflow testfile-dwp-4-cu-index-overflow.dwp 298 299exit 0 300