]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - binutils/testsuite/binutils-all/compress.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / binutils / testsuite / binutils-all / compress.exp
CommitLineData
d87bef3a 1# Copyright (C) 2010-2023 Free Software Foundation, Inc.
4a114e3e
L
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
65951855 7#
4a114e3e
L
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
65951855 12#
4a114e3e
L
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
16
17# Test compressed .debug section.
18
dae148f3 19if { [is_remote host] || ![is_elf_format] } then {
4a114e3e
L
20 return
21}
22
e268c0a6
L
23set testfile tmpdir/dw2-1
24set compressedfile tmpdir/dw2-1-compressed
4a114e3e 25set copyfile tmpdir/dw2-copy
e268c0a6
L
26set compressedfile2 tmpdir/dw2-2-compressed
27set libfile tmpdir/libdw2
4a114e3e 28set compressedcopyfile tmpdir/dw2-copy-compressed
e268c0a6
L
29set testfile3 tmpdir/dw2-3
30set compressedfile3 tmpdir/dw2-3-compressed
4a114e3e 31
e268c0a6 32if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${testfile}.o --nocompress-debug-sections] } then {
6dbf72d7 33 unsupported "compressed debug sections"
4a114e3e
L
34 return
35}
36
e268c0a6 37if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${compressedfile}.o --compress-debug-sections] } then {
4a114e3e
L
38 unsupported "compressed debug sections"
39 return
40}
41
19a7fe52
L
42if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${compressedfile}gnu.o --compress-debug-sections=zlib-gnu] } then {
43 unsupported "compressed debug sections with zlib-gnu"
44 return
45}
46
47set got [remote_exec host "cmp ${testfile}.o ${compressedfile}gnu.o"]
317974f6
L
48# Use it to set up xfail.
49set exec_output [lindex $got 1]
50if [string match "" $exec_output] then {
51 set compression_used ""
52} else {
53 set compression_used "yes"
54}
55
e268c0a6 56if { ![binutils_assemble_flags $srcdir/$subdir/dw2-2.S ${compressedfile2}.o --compress-debug-sections] } then {
4a114e3e
L
57 unsupported "compressed debug sections"
58 return
59}
60
e268c0a6
L
61if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${testfile3}.o --nocompress-debug-sections] } then {
62 unsupported "compressed debug sections"
63 return
64}
65
66if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${compressedfile3}.o --compress-debug-sections] } then {
67 unsupported "compressed debug sections"
68 return
69}
70
71remote_file host delete ${libfile}.a
72set got [binutils_run $AR "rc ${libfile}.a ${compressedfile}.o ${compressedfile2}.o ${compressedfile3}.o"]
4a114e3e
L
73if ![string match "" $got] then {
74 fail "compressed debug sections"
75 return
76}
77
78set testname "objcopy compress debug sections"
e268c0a6 79set got [binutils_run $OBJCOPY "--compress-debug-sections ${testfile}.o ${copyfile}.o"]
4a114e3e
L
80if ![string match "" $got] then {
81 fail "objcopy ($testname)"
82} else {
e268c0a6
L
83 send_log "cmp ${compressedfile}.o ${copyfile}.o\n"
84 verbose "cmp ${compressedfile}.o ${copyfile}.o"
85 set src1 ${compressedfile}.o
4a114e3e
L
86 set src2 ${copyfile}.o
87 set status [remote_exec build cmp "${src1} ${src2}"]
88 set exec_output [lindex $status 1]
89 set exec_output [prune_warnings $exec_output]
90
91 if [string match "" $exec_output] then {
92 pass "objcopy ($testname)"
93 } else {
94 send_log "$exec_output\n"
95 verbose "$exec_output" 1
96 fail "objcopy ($testname)"
97 }
98}
99
100set testname "objcopy decompress compressed debug sections"
e268c0a6 101set got [binutils_run $OBJCOPY "--decompress-debug-sections ${compressedfile}.o ${copyfile}.o"]
4a114e3e
L
102if ![string match "" $got] then {
103 fail "objcopy ($testname)"
104} else {
e268c0a6
L
105 send_log "cmp ${testfile}.o ${copyfile}.o\n"
106 verbose "cmp ${testfile}.o ${copyfile}.o"
107 set src1 ${testfile}.o
4a114e3e
L
108 set src2 ${copyfile}.o
109 set status [remote_exec build cmp "${src1} ${src2}"]
110 set exec_output [lindex $status 1]
111 set exec_output [prune_warnings $exec_output]
112
113 if [string match "" $exec_output] then {
114 pass "objcopy ($testname)"
115 } else {
116 send_log "$exec_output\n"
117 verbose "$exec_output" 1
118 fail "objcopy ($testname)"
119 }
120}
121
122set testname "objcopy decompress debug sections in archive"
e268c0a6 123set got [binutils_run $OBJCOPY "--decompress-debug-sections ${libfile}.a ${copyfile}.a"]
4a114e3e
L
124if ![string match "" $got] then {
125 fail "objcopy ($testname)"
126} else {
127 set got [remote_exec host "$READELF -S --wide ${copyfile}.a" "" "/dev/null" "tmpdir/libdw2.out"]
128
129 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
130 fail "$testname (reason: unexpected output)"
131 send_log $got
132 send_log "\n"
133 }
134
135 if { [regexp_diff tmpdir/libdw2.out $srcdir/$subdir/libdw2.out] } then {
136 fail "$testname"
137 } else {
138 pass "$testname"
139 }
140}
141
317974f6
L
142# Xfail this test if there are no compressed sections.
143setup_xfail "$compression_used$target_triplet"
19a7fe52
L
144set testname "objcopy compress debug sections in archive with zlib-gnu"
145set got [binutils_run $OBJCOPY "--compress-debug-sections=zlib-gnu ${copyfile}.a ${compressedcopyfile}.a"]
4a114e3e
L
146if ![string match "" $got] then {
147 fail "objcopy ($testname)"
148} else {
149 set got [remote_exec host "$OBJDUMP -s -j .zdebug_line ${compressedcopyfile}.a" "" "/dev/null" "tmpdir/libdw2-compressed.out"]
150
151 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
152 fail "$testname (reason: unexpected output)"
153 send_log $got
154 send_log "\n"
155 }
156
317974f6 157 setup_xfail "$compression_used$target_triplet"
4a114e3e
L
158 if { [regexp_diff tmpdir/libdw2-compressed.out $srcdir/$subdir/libdw2-compressed.out] } then {
159 fail "$testname"
160 } else {
161 pass "$testname"
162 }
163}
5a5ed5b0 164
a9481b58 165set testname "objdump compress debug sections"
e268c0a6 166set got [remote_exec host "$OBJDUMP -W ${compressedfile}.o" "" "/dev/null" "objdump.out"]
a9481b58
L
167if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
168 fail "$testname"
169 send_log "$got\n"
170}
171if { [regexp_diff objdump.out $srcdir/$subdir/dw2-1.W] } then {
172 fail "$testname"
173} else {
174 pass "$testname"
175}
176
e268c0a6
L
177set testname "objdump compress debug sections 3"
178set got [remote_exec host "$OBJDUMP -W ${compressedfile3}.o" "" "/dev/null" "objdump.out"]
179if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
180 fail "$testname"
181 send_log "$got\n"
182}
183if { [regexp_diff objdump.out $srcdir/$subdir/dw2-3.W] } then {
184 fail "$testname"
185} else {
186 pass "$testname"
187}
5a5ed5b0 188
e268c0a6 189if { ![binutils_assemble_flags $srcdir/$subdir/dw2-empty.S ${testfile}empty.o --nocompress-debug-sections] } then {
5a5ed5b0
L
190 unsupported "compressed debug sections"
191 return
192}
193
194set testname "objcopy compress empty debug sections"
e268c0a6 195set got [binutils_run $OBJCOPY "--compress-debug-sections ${testfile}empty.o ${copyfile}empty.o"]
5a5ed5b0
L
196if ![string match "" $got] then {
197 fail "objcopy ($testname)"
198} else {
e268c0a6
L
199 send_log "cmp ${testfile}empty.o ${copyfile}empty.o\n"
200 verbose "cmp ${testfile}empty.o ${copyfile}empty.o"
201 set src1 ${testfile}empty.o
202 set src2 ${copyfile}empty.o
5a5ed5b0
L
203 set status [remote_exec build cmp "${src1} ${src2}"]
204 set exec_output [lindex $status 1]
205 set exec_output [prune_warnings $exec_output]
206
207 if [string match "" $exec_output] then {
208 pass "objcopy ($testname)"
209 } else {
210 send_log "$exec_output\n"
211 verbose "$exec_output" 1
212 fail "objcopy ($testname)"
213 }
214}
a953eec9
NC
215
216if ![is_remote host] {
217 set tempfile tmpdir/debug_str.o
218 set copyfile tmpdir/debug_str.copy
219} else {
220 set tempfile [remote_download host tmpdir/debug_str.o]
221 set copyfile debug_str.copy
222}
223
224run_dump_test "debug_str"
151411f8
L
225
226if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${compressedfile}gabi.o --compress-debug-sections=zlib-gabi] } then {
227 fail "compressed debug sections with zlib-gabi"
228 return
229}
230
231if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${compressedfile}gnu.o --compress-debug-sections=zlib-gnu] } then {
232 fail "compressed debug sections with zlib-gnu"
233 return
234}
235
19a7fe52 236set src1 ${compressedfile}gabi.o
151411f8
L
237set src2 ${compressedfile}.o
238set status [remote_exec build cmp "${src1} ${src2}"]
239set exec_output [lindex $status 1]
240set exec_output [prune_warnings $exec_output]
241if ![string match "" $exec_output] then {
19a7fe52 242 fail "compressed debug sections with zlib-gabi"
151411f8
L
243 return
244}
245
246if { ![binutils_assemble_flags $srcdir/$subdir/dw2-2.S ${compressedfile2}gabi.o --compress-debug-sections=zlib-gabi] } then {
247 fail "compressed debug sections with zlib-gabi"
248 return
249}
250
251if { ![binutils_assemble_flags $srcdir/$subdir/dw2-2.S ${compressedfile2}gnu.o --compress-debug-sections=zlib-gnu] } then {
252 fail "compressed debug sections with zlib-gnu"
253 return
254}
255
19a7fe52 256set src1 ${compressedfile2}gabi.o
151411f8
L
257set src2 ${compressedfile2}.o
258set status [remote_exec build cmp "${src1} ${src2}"]
259set exec_output [lindex $status 1]
260set exec_output [prune_warnings $exec_output]
261if ![string match "" $exec_output] then {
19a7fe52 262 fail "compressed debug sections with zlib-gabi"
151411f8
L
263 return
264}
265
266if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${compressedfile3}gabi.o --compress-debug-sections=zlib-gabi] } then {
267 fail "compressed debug sections with zlib-gabi"
268 return
269}
270
271set testname "readelf -t zlib-gabi compress debug sections"
272set got [remote_exec host "$READELF -t --wide ${compressedfile3}gabi.o" "" "/dev/null" "tmpdir/dw2-3.rt"]
273if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
274 fail "$testname (reason: unexpected output)"
275 send_log "$got\n"
276}
277if { [regexp_diff tmpdir/dw2-3.rt $srcdir/$subdir/dw2-3.rt] } then {
278 fail "$testname"
279} else {
280 pass "$testname"
281}
282
283set testname "readelf -S zlib-gabi compress debug sections"
284set got [remote_exec host "$READELF -S --wide ${compressedfile3}gabi.o" "" "/dev/null" "tmpdir/dw2-3.rS"]
285if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
286 fail "$testname (reason: unexpected output)"
287 send_log "$got\n"
288}
289if { [regexp_diff tmpdir/dw2-3.rS $srcdir/$subdir/dw2-3.rS] } then {
290 fail "$testname"
291} else {
292 pass "$testname"
293}
294
295if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${compressedfile3}gnu.o --compress-debug-sections=zlib-gnu] } then {
296 fail "compressed debug sections with zlib-gnu"
297 return
298}
299
19a7fe52 300set src1 ${compressedfile3}gabi.o
151411f8
L
301set src2 ${compressedfile3}.o
302set status [remote_exec build cmp "${src1} ${src2}"]
303set exec_output [lindex $status 1]
304set exec_output [prune_warnings $exec_output]
305if ![string match "" $exec_output] then {
19a7fe52 306 fail "compressed debug sections with zlib-gabi"
151411f8
L
307 return
308}
309
310remote_file host delete ${libfile}gabi.a
311set got [binutils_run $AR "rc ${libfile}gabi.a ${compressedfile}gabi.o ${compressedfile2}gabi.o ${compressedfile3}gabi.o"]
312if ![string match "" $got] then {
313 fail "compressed debug sections"
314 return
315}
316
317set testname "objcopy compress debug sections with zlib-gabi"
318set got [binutils_run $OBJCOPY "--compress-debug-sections=zlib-gabi ${testfile}.o ${copyfile}gabi.o"]
319if ![string match "" $got] then {
320 fail "objcopy ($testname)"
321 return
322}
323send_log "cmp ${compressedfile}gabi.o ${copyfile}gabi.o\n"
324verbose "cmp ${compressedfile}gabi.o ${copyfile}gabi.o"
325set src1 ${compressedfile}gabi.o
326set src2 ${copyfile}gabi.o
327set status [remote_exec build cmp "${src1} ${src2}"]
328set exec_output [lindex $status 1]
329set exec_output [prune_warnings $exec_output]
330if ![string match "" $exec_output] then {
331 send_log "$exec_output\n"
332 verbose "$exec_output" 1
333 fail "objcopy ($testname)"
334} else {
335 pass "objcopy ($testname)"
336}
337
338set testname "objcopy decompress compressed debug sections with zlib-gabi"
339set got [binutils_run $OBJCOPY "--decompress-debug-sections ${compressedfile}gabi.o ${copyfile}gabi.o"]
340if ![string match "" $got] then {
341 fail "objcopy ($testname)"
342 return
343}
344send_log "cmp ${testfile}.o ${copyfile}gabi.o\n"
345verbose "cmp ${testfile}.o ${copyfile}gabi.o"
346set src1 ${testfile}.o
347set src2 ${copyfile}gabi.o
348set status [remote_exec build cmp "${src1} ${src2}"]
349set exec_output [lindex $status 1]
350set exec_output [prune_warnings $exec_output]
351if ![string match "" $exec_output] then {
352 send_log "$exec_output\n"
353 verbose "$exec_output" 1
354 fail "objcopy ($testname)"
355} else {
356 pass "objcopy ($testname)"
357}
358
359set testname "objcopy zlib-gnu compress debug sections with zlib-gabi"
360set got [binutils_run $OBJCOPY "--compress-debug-sections=zlib-gabi ${compressedfile}.o ${copyfile}gabi.o"]
361if ![string match "" $got] then {
362 fail "objcopy ($testname)"
363 return
364}
365send_log "cmp ${compressedfile}gabi.o ${copyfile}gabi.o\n"
366verbose "cmp ${compressedfile}gabi.o ${copyfile}gabi.o"
367set src1 ${compressedfile}gabi.o
368set src2 ${copyfile}gabi.o
369set status [remote_exec build cmp "${src1} ${src2}"]
370set exec_output [lindex $status 1]
371set exec_output [prune_warnings $exec_output]
372if ![string match "" $exec_output] then {
373 send_log "$exec_output\n"
374 verbose "$exec_output" 1
375 fail "objcopy ($testname)"
376} else {
377 pass "objcopy ($testname)"
378}
379
380set testname "objcopy zlib-gabi compress debug sections with zlib-gnu"
381set got [binutils_run $OBJCOPY "--compress-debug-sections=zlib-gnu ${compressedfile}gabi.o ${copyfile}gnu.o"]
382if ![string match "" $got] then {
383 fail "objcopy ($testname)"
384 return
385}
386send_log "cmp ${compressedfile}gnu.o ${copyfile}gnu.o\n"
387verbose "cmp ${compressedfile}gnu.o ${copyfile}gnu.o"
388set src1 ${compressedfile}gnu.o
389set src2 ${copyfile}gnu.o
390set status [remote_exec build cmp "${src1} ${src2}"]
391set exec_output [lindex $status 1]
392set exec_output [prune_warnings $exec_output]
393if ![string match "" $exec_output] then {
394 send_log "$exec_output\n"
395 verbose "$exec_output" 1
396 fail "objcopy ($testname)"
397} else {
398 pass "objcopy ($testname)"
399}
400
401set testname "objcopy compress debug sections 3 with zlib-gabi"
402set got [binutils_run $OBJCOPY "--compress-debug-sections=zlib-gabi ${testfile3}.o ${copyfile}gabi.o"]
403if ![string match "" $got] then {
404 fail "objcopy ($testname)"
405 return
406}
407send_log "cmp ${compressedfile3}gabi.o ${copyfile}gabi.o\n"
408verbose "cmp ${compressedfile3}gabi.o ${copyfile}gabi.o"
409set src1 ${compressedfile3}gabi.o
410set src2 ${copyfile}gabi.o
411set status [remote_exec build cmp "${src1} ${src2}"]
412set exec_output [lindex $status 1]
413set exec_output [prune_warnings $exec_output]
414if ![string match "" $exec_output] then {
415 send_log "$exec_output\n"
416 verbose "$exec_output" 1
417 fail "objcopy ($testname)"
418} else {
419 pass "objcopy ($testname)"
420}
421
422set testname "objcopy decompress compressed debug sections 3 with zlib-gabi"
423set got [binutils_run $OBJCOPY "--decompress-debug-sections ${compressedfile3}gabi.o ${copyfile}gabi.o"]
424if ![string match "" $got] then {
425 fail "objcopy ($testname)"
426 return
427}
428send_log "cmp ${testfile3}.o ${copyfile}gabi.o\n"
429verbose "cmp ${testfile3}.o ${copyfile}gabi.o"
430set src1 ${testfile3}.o
431set src2 ${copyfile}gabi.o
432set status [remote_exec build cmp "${src1} ${src2}"]
433set exec_output [lindex $status 1]
434set exec_output [prune_warnings $exec_output]
435if ![string match "" $exec_output] then {
436 send_log "$exec_output\n"
437 verbose "$exec_output" 1
438 fail "objcopy ($testname)"
439} else {
440 pass "objcopy ($testname)"
441}
442
443set testname "objcopy zlib-gnu compress debug sections 3 with zlib-gabi"
444set got [binutils_run $OBJCOPY "--compress-debug-sections=zlib-gabi ${compressedfile3}.o ${copyfile}gabi.o"]
445if ![string match "" $got] then {
446 fail "objcopy ($testname)"
447 return
448}
449send_log "cmp ${compressedfile3}gabi.o ${copyfile}gabi.o\n"
450verbose "cmp ${compressedfile3}gabi.o ${copyfile}gabi.o"
451set src1 ${compressedfile3}gabi.o
452set src2 ${copyfile}gabi.o
453set status [remote_exec build cmp "${src1} ${src2}"]
454set exec_output [lindex $status 1]
455set exec_output [prune_warnings $exec_output]
456if ![string match "" $exec_output] then {
457 send_log "$exec_output\n"
458 verbose "$exec_output" 1
459 fail "objcopy ($testname)"
460} else {
461 pass "objcopy ($testname)"
462}
463
464set testname "objcopy zlib-gabi compress debug sections 3 with zlib-gnu"
465set got [binutils_run $OBJCOPY "--compress-debug-sections=zlib-gnu ${compressedfile3}gabi.o ${copyfile}gnu.o"]
466if ![string match "" $got] then {
467 fail "objcopy ($testname)"
468 return
469}
470send_log "cmp ${compressedfile3}gnu.o ${copyfile}gnu.o\n"
471verbose "cmp ${compressedfile3}gnu.o ${copyfile}gnu.o"
472set src1 ${compressedfile3}gnu.o
473set src2 ${copyfile}gnu.o
474set status [remote_exec build cmp "${src1} ${src2}"]
475set exec_output [lindex $status 1]
476set exec_output [prune_warnings $exec_output]
477if ![string match "" $exec_output] then {
478 send_log "$exec_output\n"
479 verbose "$exec_output" 1
480 fail "objcopy ($testname)"
481} else {
482 pass "objcopy ($testname)"
483}
484
485set testname "objcopy zlib-gnu compress debug sections 3"
486set got [binutils_run $OBJCOPY "${compressedfile3}gnu.o ${copyfile}gnu.o"]
487if ![string match "" $got] then {
488 fail "objcopy ($testname)"
489 return
490}
491send_log "cmp ${compressedfile3}gnu.o ${copyfile}gnu.o\n"
492verbose "cmp ${compressedfile3}gnu.o ${copyfile}gnu.o"
493set src1 ${compressedfile3}gnu.o
494set src2 ${copyfile}gnu.o
495set status [remote_exec build cmp "${src1} ${src2}"]
496set exec_output [lindex $status 1]
497set exec_output [prune_warnings $exec_output]
498if ![string match "" $exec_output] then {
499 send_log "$exec_output\n"
500 verbose "$exec_output" 1
501 fail "objcopy ($testname)"
502} else {
503 pass "objcopy ($testname)"
504}
505
a0a8a934
NC
506set testname "objcopy zlib-gabi compress debug sections 3"
507set got [binutils_run $OBJCOPY "${compressedfile3}gabi.o ${copyfile}gabi.o"]
151411f8
L
508if ![string match "" $got] then {
509 fail "objcopy ($testname)"
510 return
511}
a0a8a934
NC
512send_log "cmp ${compressedfile3}gabi.o ${copyfile}gabi.o\n"
513verbose "cmp ${compressedfile3}gabi.o ${copyfile}gabi.o"
514set src1 ${compressedfile3}gabi.o
515set src2 ${copyfile}gabi.o
151411f8
L
516set status [remote_exec build cmp "${src1} ${src2}"]
517set exec_output [lindex $status 1]
518set exec_output [prune_warnings $exec_output]
519if ![string match "" $exec_output] then {
520 send_log "$exec_output\n"
521 verbose "$exec_output" 1
522 fail "objcopy ($testname)"
523} else {
524 pass "objcopy ($testname)"
525}
526
527set testname "objcopy decompress debug sections in archive with zlib-gabi"
528set got [binutils_run $OBJCOPY "--decompress-debug-sections ${libfile}gabi.a ${copyfile}gabi.a"]
529if ![string match "" $got] then {
530 fail "objcopy ($testname)"
531} else {
532 set got [remote_exec host "$READELF -S --wide ${copyfile}gabi.a" "" "/dev/null" "tmpdir/libdw2.out"]
533
534 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
535 fail "$testname (reason: unexpected output)"
536 send_log $got
537 send_log "\n"
538 }
539
540 if { [regexp_diff tmpdir/libdw2.out $srcdir/$subdir/libdw2.out] } then {
541 fail "$testname"
542 } else {
543 pass "$testname"
544 }
545}
546
547set testname "objcopy compress debug sections in archive with zlib-gabi"
548set got [binutils_run $OBJCOPY "--compress-debug-sections=zlib-gabi ${copyfile}gabi.a ${compressedcopyfile}gabi.a"]
549if ![string match "" $got] then {
550 fail "objcopy ($testname)"
551} else {
dab394de 552 set got [remote_exec host "$OBJDUMP -W ${compressedcopyfile}gabi.a" "" "/dev/null" "tmpdir/libdw2-compressedgabi.out"]
151411f8
L
553
554 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
555 fail "$testname (reason: unexpected output)"
556 send_log $got
557 send_log "\n"
558 }
559
560 if { [regexp_diff tmpdir/libdw2-compressedgabi.out $srcdir/$subdir/libdw2-compressedgabi.out] } then {
561 fail "$testname"
562 } else {
563 pass "$testname"
564 }
565}
566
567set testname "objdump compress debug sections 3 with zlib-gabi"
568set got [remote_exec host "$OBJDUMP -W ${compressedfile3}gabi.o" "" "/dev/null" "objdump.out"]
569if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
570 fail "$testname"
571 send_log "$got\n"
572}
f6fe1ccd 573if { [regexp_diff objdump.out $srcdir/$subdir/dw2-3gabi.W] } then {
151411f8
L
574 fail "$testname"
575} else {
576 pass "$testname"
577}
88988473 578
2cac01e3
FS
579if { [binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${compressedfile}zstd.o --compress-debug-sections=zstd] } then {
580 set testname "objcopy compress debug sections with zstd"
581 set got [binutils_run $OBJCOPY "--compress-debug-sections=zstd ${testfile}.o ${copyfile}zstd.o"]
582 if ![string match "" $got] then {
583 fail "objcopy ($testname)"
584 return
585 }
586 send_log "cmp ${compressedfile}zstd.o ${copyfile}zstd.o\n"
587 verbose "cmp ${compressedfile}zstd.o ${copyfile}zstd.o"
588 set src1 ${compressedfile}zstd.o
589 set src2 ${copyfile}zstd.o
590 set status [remote_exec build cmp "${src1} ${src2}"]
591 set exec_output [lindex $status 1]
592 set exec_output [prune_warnings $exec_output]
593 if ![string match "" $exec_output] then {
594 send_log "$exec_output\n"
595 verbose "$exec_output" 1
596 fail "objcopy ($testname)"
597 } else {
598 pass "objcopy ($testname)"
599 }
600
601 set testname "objcopy decompress compressed debug sections with zstd"
602 set got [binutils_run $OBJCOPY "--decompress-debug-sections ${compressedfile}zstd.o ${copyfile}zstd.o"]
603 if ![string match "" $got] then {
604 fail "objcopy ($testname)"
605 return
606 }
607 send_log "cmp ${testfile}.o ${copyfile}zstd.o\n"
608 verbose "cmp ${testfile}.o ${copyfile}zstd.o"
609 set src1 ${testfile}.o
610 set src2 ${copyfile}zstd.o
611 set status [remote_exec build cmp "${src1} ${src2}"]
612 set exec_output [lindex $status 1]
613 set exec_output [prune_warnings $exec_output]
614 if ![string match "" $exec_output] then {
615 send_log "$exec_output\n"
616 verbose "$exec_output" 1
617 fail "objcopy ($testname)"
618 } else {
619 pass "objcopy ($testname)"
620 }
621}
622
88988473
L
623proc convert_test { testname as_flags objcop_flags } {
624 global srcdir
625 global subdir
626 global testfile3
627 global copyfile
628 global OBJCOPY
629 global OBJDUMP
630
631 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${testfile3}.o "$as_flags"] } then {
17e04eff 632 unsupported "$testname"
88988473
L
633 return
634 }
635
636 set got [binutils_run $OBJCOPY "$objcop_flags ${testfile3}.o ${copyfile}.o"]
637 if ![string match "" $got] then {
638 fail "objcopy ($testname)"
639 return
640 }
641
642 set got [remote_exec host "$OBJDUMP -W ${copyfile}.o" "" "/dev/null" "objdump.out"]
643
644 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
645 fail "$testname (reason: unexpected output)"
646 send_log $got
647 send_log "\n"
648 return
649 }
650
651 if { [regexp_diff objdump.out $srcdir/$subdir/dw2-3.W] } then {
652 fail "$testname"
653 } else {
654 pass "$testname"
655 }
656}
657
658if { ([istarget "x86_64-*-elf*"]
659 || [istarget "x86_64-*-linux*"]) } {
660 set testname "Convert x86-64 object with zlib-gabi to x32 (1)"
661 convert_test "$testname" "--compress-debug-sections=zlib-gabi --64" "-O elf32-x86-64"
662
663 set testname "Convert x86-64 object with zlib-gabi to x32 (2)"
664 convert_test "$testname" "--compress-debug-sections=zlib-gabi --64" "-O elf32-x86-64 --compress-debug-sections=zlib-gnu"
665
666 set testname "Convert x86-64 object with zlib-gabi to x32 (3)"
667 convert_test "$testname" "--compress-debug-sections=zlib-gabi --64" "-O elf32-x86-64 --decompress-debug-sections"
668
669 set testname "Convert x86-64 object with zlib-gnu to x32 (1)"
670 convert_test "$testname" "--compress-debug-sections=zlib-gnu --64" "-O elf32-x86-64"
671
672 set testname "Convert x86-64 object with zlib-gnu to x32 (2)"
673 convert_test "$testname" "--compress-debug-sections=zlib-gnu --64" "-O elf32-x86-64 --compress-debug-sections=zlib-gabi"
674
675 set testname "Convert x86-64 object with zlib-gnu to x32 (3)"
676 convert_test "$testname" "--compress-debug-sections=zlib-gnu --64" "-O elf32-x86-64 --decompress-debug-sections"
677
678 set testname "Convert x86-64 object to x32 (1)"
679 convert_test "$testname" "--nocompress-debug-sections --64" "-O elf32-x86-64"
680
681 set testname "Convert x86-64 object to x32 (2)"
682 convert_test "$testname" "--nocompress-debug-sections --64" "-O elf32-x86-64 --compress-debug-sections=zlib-gabi"
683
684 set testname "Convert x86-64 object to x32 (3)"
685 convert_test "$testname" "--nocompress-debug-sections --64" "-O elf32-x86-64 --compress-debug-sections=zlib-gnu"
686
687
688 set testname "Convert x32 object with zlib-gabi to x86-64 (1)"
689 convert_test "$testname" "--compress-debug-sections=zlib-gabi --x32" "-O elf64-x86-64"
690
691 set testname "Convert x32 object with zlib-gabi to x86-64 (2)"
692 convert_test "$testname" "--compress-debug-sections=zlib-gabi --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gnu"
693
694 set testname "Convert x32 object with zlib-gabi to x86-64 (3)"
695 convert_test "$testname" "--compress-debug-sections=zlib-gabi --x32" "-O elf64-x86-64 --decompress-debug-sections"
696
697 set testname "Convert x32 object with zlib-gnu to x86-64 (1)"
698 convert_test "$testname" "--compress-debug-sections=zlib-gnu --x32" "-O elf64-x86-64"
699
700 set testname "Convert x32 object with zlib-gnu to x86-64 (2)"
701 convert_test "$testname" "--compress-debug-sections=zlib-gnu --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gabi"
702
703 set testname "Convert x32 object with zlib-gnu to x86-64 (3)"
704 convert_test "$testname" "--compress-debug-sections=zlib-gnu --x32" "-O elf64-x86-64 --decompress-debug-sections"
705
706 set testname "Convert x32 object to x86-64 (1)"
707 convert_test "$testname" "--nocompress-debug-sections --x32" "-O elf64-x86-64"
708
709 set testname "Convert x32 object to x86-64 (2)"
710 convert_test "$testname" "--nocompress-debug-sections --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gabi"
711
712 set testname "Convert x32 object to x86-64 (3)"
713 convert_test "$testname" "--nocompress-debug-sections --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gnu"
bf150a0b
L
714}
715
716proc test_gnu_debuglink {} {
717 global srcdir
718 global subdir
719 global env
bf150a0b
L
720 global STRIP
721 global OBJCOPY
722 global OBJDUMP
ecd65684 723 global READELF
3e9373fc 724 global gcc_gas_flag
bf150a0b
L
725
726 set test "gnu-debuglink"
bf150a0b 727
3e9373fc
L
728 # Use the newly built assembler and linker.
729 set flags debug
730 if { [istarget *-*-linux*]
731 || [istarget *-*-gnu*] } {
732 foreach i $gcc_gas_flag {
733 set flags "additional_flags=$i $flags"
734 }
735 }
736 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable $flags] != "" } {
bb3b5316 737 unsupported "$test (build)"
bf150a0b
L
738 return
739 }
ca0e11aa 740 set got [remote_exec host "$OBJDUMP -d tmpdir/testprog" "" "/dev/null" "tmpdir/testprog.dump"]
bf150a0b
L
741 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
742 fail "$test (objcopy dump)"
743 return
744 }
745 if { [binutils_run $STRIP "--strip-debug --remove-section=.comment --remove-section=.note tmpdir/testprog -o tmpdir/testprog.strip"] != "" } {
746 fail "$test (strip)"
747 return
748 }
749 if { [binutils_run $OBJCOPY "--only-keep-debug --decompress-debug-sections tmpdir/testprog tmpdir/testprog.decompress"] != "" } {
750 fail "$test (objcopy decompress)"
751 return
752 }
753 if { [binutils_run $OBJCOPY "--only-keep-debug --compress-debug-sections tmpdir/testprog tmpdir/testprog.compress"] != "" } {
754 fail "$test (objcopy compress)"
755 return
756 }
757 if { [binutils_run $OBJCOPY "--add-gnu-debuglink=tmpdir/testprog.decompress tmpdir/testprog.strip tmpdir/testprog"] != "" } {
758 fail "$test (objcopy link decompress)"
759 return
760 }
ca0e11aa 761 set got [remote_exec host "$OBJDUMP -d -WK tmpdir/testprog" "" "/dev/null" "tmpdir/testprog.decompress.dump"]
bf150a0b
L
762 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
763 fail "$test (objcopy dump decompress)"
764 return
765 }
766 if { [binutils_run $OBJCOPY "--add-gnu-debuglink=tmpdir/testprog.compress tmpdir/testprog.strip tmpdir/testprog"] != "" } {
767 fail "$test (objcopy link compress)"
768 return
769 }
ca0e11aa 770 set got [remote_exec host "$OBJDUMP -d -WK tmpdir/testprog" "" "/dev/null" "tmpdir/testprog.compress.dump"]
bf150a0b
L
771 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
772 fail "$test (objcopy dump compress)"
773 return
774 }
775
776 set src1 tmpdir/testprog.dump
777 set src2 tmpdir/testprog.compress.dump
ca0e11aa
NC
778 send_log "diff ${src1} ${src2}\n"
779 verbose "diff ${src1} ${src2}"
780 set status [remote_exec build diff "${src1} ${src2}"]
bf150a0b
L
781 set exec_output [lindex $status 1]
782 set exec_output [prune_warnings $exec_output]
783 if ![string match "" $exec_output] then {
784 send_log "$exec_output\n"
785 verbose "$exec_output" 1
786 fail "$test (objdump 1)"
787 } else {
788 pass "$test (objdump 1)"
789 }
790
791 set src1 tmpdir/testprog.decompress.dump
792 set src2 tmpdir/testprog.compress.dump
ca0e11aa
NC
793 send_log "diff ${src1} ${src2}\n"
794 verbose "diff ${src1} ${src2}"
795 set status [remote_exec build diff "${src1} ${src2}"]
bf150a0b
L
796 set exec_output [lindex $status 1]
797 set exec_output [prune_warnings $exec_output]
798 if ![string match "" $exec_output] then {
799 send_log "$exec_output\n"
800 verbose "$exec_output" 1
801 fail "$test (objdump 2)"
802 } else {
803 pass "$test (objdump 2)"
804 }
ecd65684
L
805
806 remote_file host delete tmpdir/testprog.compress
807 set got [remote_exec host [concat sh -c [list "$OBJDUMP --syms tmpdir/testprog > /dev/null"]]]
808 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
809 fail "$test (objdump with missing link)"
810 } else {
811 pass "$test (objdump with missing link)"
812 }
813 set got [remote_exec host [concat sh -c [list "$READELF -S tmpdir/testprog > /dev/null"]]]
814 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
815 fail "$test (readelf with missing link)"
816 } else {
817 pass "$test (readelf with missing link)"
818 }
bf150a0b
L
819}
820
0034eed0 821if {[is_elf_format]} then {
bf150a0b
L
822 test_gnu_debuglink
823}