1#! /bin/sh 2# Copyright (C) 2015 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# - testfile-zdebug-rel.c 21# #define UINT64_MAX 18446744073709551615UL 22# 23# int 24# main (int argc, char **argv) 25# { 26# unsigned long a = UINT64_MAX - 8; 27# unsigned long b = 42 + argc; 28# 29# if ( a + b < b ) 30# argc = a + argc; 31# else 32# b--; 33# 34# return a - b; 35# } 36# 37# gcc -Og -g -Xassembler --compress-debug-sections=none \ 38# -c -o testfile-debug-rel.o testfile-zdebug-rel.c 39# gcc -Og -g -Xassembler --compress-debug-sections=zlib-gnu \ 40# -c -o testfile-debug-rel-g.o testfile-zdebug-rel.c 41# gcc -Og -g -Xassembler --compress-debug-sections=zlib-gabi \ 42# -c -o testfile-debug-rel-z.o testfile-zdebug-rel.c 43 44testfiles testfile-debug-rel.o testfile-debug-rel-g.o testfile-debug-rel-z.o 45tempfiles readelf.out 46tempfiles info.out loc.out 47 48cat > info.out << \EOF 49 50DWARF section [ 4] '.debug_info' at offset 0x58: 51 [Offset] 52 Compilation unit at offset 0: 53 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 54 [ b] compile_unit abbrev: 1 55 producer (strp) "GNU C11 5.3.1 20151207 (Red Hat 5.3.1-2) -mtune=generic -march=x86-64 -g -Og" 56 language (data1) C99 (12) 57 name (strp) "testfile-zdebug-rel.c" 58 comp_dir (strp) "/tmp" 59 low_pc (addr) 000000000000000000 60 high_pc (data8) 24 (0x0000000000000018) 61 stmt_list (sec_offset) 0 62 [ 2d] subprogram abbrev: 2 63 external (flag_present) yes 64 name (strp) "main" 65 decl_file (data1) testfile-zdebug-rel.c (1) 66 decl_line (data1) 4 67 prototyped (flag_present) yes 68 type (ref4) [ 80] 69 low_pc (addr) 000000000000000000 70 high_pc (data8) 24 (0x0000000000000018) 71 frame_base (exprloc) 72 [ 0] call_frame_cfa 73 GNU_all_call_sites (flag_present) yes 74 sibling (ref4) [ 80] 75 [ 4e] formal_parameter abbrev: 3 76 name (strp) "argc" 77 decl_file (data1) testfile-zdebug-rel.c (1) 78 decl_line (data1) 4 79 type (ref4) [ 80] 80 location (sec_offset) location list [ 0] 81 [ 5d] formal_parameter abbrev: 4 82 name (strp) "argv" 83 decl_file (data1) testfile-zdebug-rel.c (1) 84 decl_line (data1) 4 85 type (ref4) [ 87] 86 location (exprloc) 87 [ 0] reg4 88 [ 6a] variable abbrev: 5 89 name (string) "a" 90 decl_file (data1) testfile-zdebug-rel.c (1) 91 decl_line (data1) 6 92 type (ref4) [ 9a] 93 const_value (sdata) 18446744073709551607 (-9) 94 [ 74] variable abbrev: 6 95 name (string) "b" 96 decl_file (data1) testfile-zdebug-rel.c (1) 97 decl_line (data1) 7 98 type (ref4) [ 9a] 99 location (exprloc) 100 [ 0] reg5 101 [ 80] base_type abbrev: 7 102 byte_size (data1) 4 103 encoding (data1) signed (5) 104 name (string) "int" 105 [ 87] pointer_type abbrev: 8 106 byte_size (data1) 8 107 type (ref4) [ 8d] 108 [ 8d] pointer_type abbrev: 8 109 byte_size (data1) 8 110 type (ref4) [ 93] 111 [ 93] base_type abbrev: 9 112 byte_size (data1) 1 113 encoding (data1) signed_char (6) 114 name (strp) "char" 115 [ 9a] base_type abbrev: 9 116 byte_size (data1) 8 117 encoding (data1) unsigned (7) 118 name (strp) "long unsigned int" 119EOF 120 121cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel.o 122 123cat info.out | sed -e "s/'.debug_info'/'.zdebug_info'/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-g.o 124 125cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-z.o 126 127cat > loc.out << \EOF 128 129DWARF section [ 7] '.debug_loc' at offset 0x185: 130 131 CU [ b] base: 000000000000000000 132 [ 0] range 0, 3 133 [ 0] reg5 134 range 3, 10 135 [ 0] breg5 -42 136 [ 2] stack_value 137 range 10, 18 138 [ 0] GNU_entry_value: 139 [ 0] reg5 140 [ 3] stack_value 141EOF 142 143cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel.o 144 145cat loc.out | sed -e "s/'.debug_loc' at offset 0x185/'.zdebug_loc' at offset 0x138/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-g.o 146 147cat loc.out | sed -e "s/at offset 0x185/at offset 0x150/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-z.o 148 149# Same as above, but on ppc64 150testfiles testfile-debug-rel-ppc64.o 151testfiles testfile-debug-rel-ppc64-g.o testfile-debug-rel-ppc64-z.o 152 153cat > info.out << \EOF 154 155DWARF section [ 6] '.debug_info' at offset 0x80: 156 [Offset] 157 Compilation unit at offset 0: 158 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 159 [ b] compile_unit abbrev: 1 160 producer (strp) "GNU C11 7.3.1 20180712 (Red Hat 7.3.1-6) -Asystem=linux -Asystem=unix -Asystem=posix -msecure-plt -g -Og" 161 language (data1) C99 (12) 162 name (strp) "testfile-zdebug-rel.c" 163 comp_dir (strp) "/home/mjw" 164 low_pc (addr) 000000000000000000 165 high_pc (data8) 44 (0x000000000000002c) 166 stmt_list (sec_offset) 0 167 [ 2d] subprogram abbrev: 2 168 external (flag_present) yes 169 name (strp) "main" 170 decl_file (data1) testfile-zdebug-rel.c (1) 171 decl_line (data1) 4 172 prototyped (flag_present) yes 173 type (ref4) [ 82] 174 low_pc (addr) 000000000000000000 175 high_pc (data8) 44 (0x000000000000002c) 176 frame_base (exprloc) 177 [ 0] call_frame_cfa 178 GNU_all_call_sites (flag_present) yes 179 sibling (ref4) [ 82] 180 [ 4e] formal_parameter abbrev: 3 181 name (strp) "argc" 182 decl_file (data1) testfile-zdebug-rel.c (1) 183 decl_line (data1) 4 184 type (ref4) [ 82] 185 location (sec_offset) location list [ 0] 186 [ 5d] formal_parameter abbrev: 4 187 name (strp) "argv" 188 decl_file (data1) testfile-zdebug-rel.c (1) 189 decl_line (data1) 4 190 type (ref4) [ 89] 191 location (exprloc) 192 [ 0] reg4 193 [ 6a] variable abbrev: 5 194 name (string) "a" 195 decl_file (data1) testfile-zdebug-rel.c (1) 196 decl_line (data1) 6 197 type (ref4) [ 9c] 198 const_value (sdata) 18446744073709551607 (-9) 199 [ 74] variable abbrev: 6 200 name (string) "b" 201 decl_file (data1) testfile-zdebug-rel.c (1) 202 decl_line (data1) 7 203 type (ref4) [ 9c] 204 location (sec_offset) location list [ 4e] 205 [ 82] base_type abbrev: 7 206 byte_size (data1) 4 207 encoding (data1) signed (5) 208 name (string) "int" 209 [ 89] pointer_type abbrev: 8 210 byte_size (data1) 8 211 type (ref4) [ 8f] 212 [ 8f] pointer_type abbrev: 8 213 byte_size (data1) 8 214 type (ref4) [ 95] 215 [ 95] base_type abbrev: 9 216 byte_size (data1) 1 217 encoding (data1) unsigned_char (8) 218 name (strp) "char" 219 [ 9c] base_type abbrev: 9 220 byte_size (data1) 8 221 encoding (data1) unsigned (7) 222 name (strp) "long unsigned int" 223EOF 224 225cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-ppc64.o 226 227cat info.out | sed -e "s/'.debug_info'/'.zdebug_info'/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-ppc64-g.o 228 229cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-ppc64-z.o 230 231cat > loc.out << \EOF 232 233DWARF section [ 9] '.debug_loc' at offset 0x1af: 234 235 CU [ b] base: 000000000000000000 236 [ 0] range 0, 4 237 [ 0] reg3 238 range 4, 14 239 [ 0] breg3 -42 240 [ 2] stack_value 241 range 14, 2c 242 [ 0] GNU_entry_value: 243 [ 0] reg3 244 [ 3] stack_value 245 [ 4e] range 8, 18 246 [ 0] reg3 247EOF 248 249cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-ppc64.o 250 251cat loc.out | sed -e "s/'.debug_loc' at offset 0x1af/'.zdebug_loc' at offset 0x15f/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-ppc64-g.o 252 253cat loc.out | sed -e "s/at offset 0x1af/at offset 0x177/" | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-ppc64-z.o 254 255exit 0 256