summaryrefslogtreecommitdiffstats
path: root/tests/run-readelf-zdebug-rel.sh
blob: 53fa42a27f598b0a0933ecee48bab7cf079f38da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#! /bin/sh
# Copyright (C) 2015 Red Hat, Inc.
# This file is part of elfutils.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# elfutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

. $srcdir/test-subr.sh

# - testfile-zdebug-rel.c
# #define UINT64_MAX 18446744073709551615UL
#
# int
# main (int argc, char **argv)
# {
#   unsigned long a = UINT64_MAX - 8;
#   unsigned long b = 42 + argc;
#
#   if ( a + b < b )
#     argc = a + argc;
#   else
#      b--;
#
#   return a - b;
# }
#
# gcc -Og -g -Xassembler --compress-debug-sections=none \
#     -c -o testfile-debug-rel.o testfile-zdebug-rel.c
# gcc -Og -g -Xassembler --compress-debug-sections=zlib-gnu \
#     -c -o testfile-debug-rel-g.o testfile-zdebug-rel.c
# gcc -Og -g -Xassembler --compress-debug-sections=zlib-gabi \
#     -c -o testfile-debug-rel-z.o testfile-zdebug-rel.c

testfiles testfile-debug-rel.o testfile-debug-rel-g.o testfile-debug-rel-z.o
tempfiles readelf.out
tempfiles info.out loc.out

cat > info.out << \EOF

DWARF section [ 4] '.debug_info' at offset 0x58:
 [Offset]
 Compilation unit at offset 0:
 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 [     b]  compile_unit         abbrev: 1
           producer             (strp) "GNU C11 5.3.1 20151207 (Red Hat 5.3.1-2) -mtune=generic -march=x86-64 -g -Og"
           language             (data1) C99 (12)
           name                 (strp) "testfile-zdebug-rel.c"
           comp_dir             (strp) "/tmp"
           low_pc               (addr) 000000000000000000
           high_pc              (data8) 24 (0x0000000000000018)
           stmt_list            (sec_offset) 0
 [    2d]    subprogram           abbrev: 2
             external             (flag_present) yes
             name                 (strp) "main"
             decl_file            (data1) testfile-zdebug-rel.c (1)
             decl_line            (data1) 4
             prototyped           (flag_present) yes
             type                 (ref4) [    80]
             low_pc               (addr) 000000000000000000
             high_pc              (data8) 24 (0x0000000000000018)
             frame_base           (exprloc) 
              [ 0] call_frame_cfa
             GNU_all_call_sites   (flag_present) yes
             sibling              (ref4) [    80]
 [    4e]      formal_parameter     abbrev: 3
               name                 (strp) "argc"
               decl_file            (data1) testfile-zdebug-rel.c (1)
               decl_line            (data1) 4
               type                 (ref4) [    80]
               location             (sec_offset) location list [     0]
 [    5d]      formal_parameter     abbrev: 4
               name                 (strp) "argv"
               decl_file            (data1) testfile-zdebug-rel.c (1)
               decl_line            (data1) 4
               type                 (ref4) [    87]
               location             (exprloc) 
                [ 0] reg4
 [    6a]      variable             abbrev: 5
               name                 (string) "a"
               decl_file            (data1) testfile-zdebug-rel.c (1)
               decl_line            (data1) 6
               type                 (ref4) [    9a]
               const_value          (sdata) 18446744073709551607 (-9)
 [    74]      variable             abbrev: 6
               name                 (string) "b"
               decl_file            (data1) testfile-zdebug-rel.c (1)
               decl_line            (data1) 7
               type                 (ref4) [    9a]
               location             (exprloc) 
                [ 0] reg5
 [    80]    base_type            abbrev: 7
             byte_size            (data1) 4
             encoding             (data1) signed (5)
             name                 (string) "int"
 [    87]    pointer_type         abbrev: 8
             byte_size            (data1) 8
             type                 (ref4) [    8d]
 [    8d]    pointer_type         abbrev: 8
             byte_size            (data1) 8
             type                 (ref4) [    93]
 [    93]    base_type            abbrev: 9
             byte_size            (data1) 1
             encoding             (data1) signed_char (6)
             name                 (strp) "char"
 [    9a]    base_type            abbrev: 9
             byte_size            (data1) 8
             encoding             (data1) unsigned (7)
             name                 (strp) "long unsigned int"
EOF

cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel.o

cat 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

cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-z.o

cat > loc.out << \EOF

DWARF section [ 7] '.debug_loc' at offset 0x185:

 CU [     b] base: 000000000000000000
 [     0] range 0, 3
           [ 0] reg5
          range 3, 10
           [ 0] breg5 -42
           [ 2] stack_value
          range 10, 18
           [ 0] GNU_entry_value:
                [ 0] reg5
           [ 3] stack_value
EOF

cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel.o

cat 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

cat 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

# Same as above, but on ppc64
testfiles testfile-debug-rel-ppc64.o
testfiles testfile-debug-rel-ppc64-g.o testfile-debug-rel-ppc64-z.o

cat > info.out << \EOF

DWARF section [ 6] '.debug_info' at offset 0x80:
 [Offset]
 Compilation unit at offset 0:
 Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 [     b]  compile_unit         abbrev: 1
           producer             (strp) "GNU C11 7.3.1 20180712 (Red Hat 7.3.1-6) -Asystem=linux -Asystem=unix -Asystem=posix -msecure-plt -g -Og"
           language             (data1) C99 (12)
           name                 (strp) "testfile-zdebug-rel.c"
           comp_dir             (strp) "/home/mjw"
           low_pc               (addr) 000000000000000000
           high_pc              (data8) 44 (0x000000000000002c)
           stmt_list            (sec_offset) 0
 [    2d]    subprogram           abbrev: 2
             external             (flag_present) yes
             name                 (strp) "main"
             decl_file            (data1) testfile-zdebug-rel.c (1)
             decl_line            (data1) 4
             prototyped           (flag_present) yes
             type                 (ref4) [    82]
             low_pc               (addr) 000000000000000000
             high_pc              (data8) 44 (0x000000000000002c)
             frame_base           (exprloc) 
              [ 0] call_frame_cfa
             GNU_all_call_sites   (flag_present) yes
             sibling              (ref4) [    82]
 [    4e]      formal_parameter     abbrev: 3
               name                 (strp) "argc"
               decl_file            (data1) testfile-zdebug-rel.c (1)
               decl_line            (data1) 4
               type                 (ref4) [    82]
               location             (sec_offset) location list [     0]
 [    5d]      formal_parameter     abbrev: 4
               name                 (strp) "argv"
               decl_file            (data1) testfile-zdebug-rel.c (1)
               decl_line            (data1) 4
               type                 (ref4) [    89]
               location             (exprloc) 
                [ 0] reg4
 [    6a]      variable             abbrev: 5
               name                 (string) "a"
               decl_file            (data1) testfile-zdebug-rel.c (1)
               decl_line            (data1) 6
               type                 (ref4) [    9c]
               const_value          (sdata) 18446744073709551607 (-9)
 [    74]      variable             abbrev: 6
               name                 (string) "b"
               decl_file            (data1) testfile-zdebug-rel.c (1)
               decl_line            (data1) 7
               type                 (ref4) [    9c]
               location             (sec_offset) location list [    4e]
 [    82]    base_type            abbrev: 7
             byte_size            (data1) 4
             encoding             (data1) signed (5)
             name                 (string) "int"
 [    89]    pointer_type         abbrev: 8
             byte_size            (data1) 8
             type                 (ref4) [    8f]
 [    8f]    pointer_type         abbrev: 8
             byte_size            (data1) 8
             type                 (ref4) [    95]
 [    95]    base_type            abbrev: 9
             byte_size            (data1) 1
             encoding             (data1) unsigned_char (8)
             name                 (strp) "char"
 [    9c]    base_type            abbrev: 9
             byte_size            (data1) 8
             encoding             (data1) unsigned (7)
             name                 (strp) "long unsigned int"
EOF

cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-ppc64.o

cat 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

cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=info testfile-debug-rel-ppc64-z.o

cat > loc.out << \EOF

DWARF section [ 9] '.debug_loc' at offset 0x1af:

 CU [     b] base: 000000000000000000
 [     0] range 0, 4
           [ 0] reg3
          range 4, 14
           [ 0] breg3 -42
           [ 2] stack_value
          range 14, 2c
           [ 0] GNU_entry_value:
                [ 0] reg3
           [ 3] stack_value
 [    4e] range 8, 18
           [ 0] reg3
EOF

cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel-ppc64.o

cat 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

cat 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

exit 0