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