1 # Copyright (C) 2010-2015 Free Software Foundation, Inc.
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.
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.
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.
17 # Test compressed .debug section.
19 if { [is_remote host] || ![is_elf_format] || ![is_zlib_supported] } then {
23 set testfile tmpdir/dw2-1
24 set compressedfile tmpdir/dw2-1-compressed
25 set copyfile tmpdir/dw2-copy
26 set compressedfile2 tmpdir/dw2-2-compressed
27 set libfile tmpdir/libdw2
28 set compressedcopyfile tmpdir/dw2-copy-compressed
29 set testfile3 tmpdir/dw2-3
30 set compressedfile3 tmpdir/dw2-3-compressed
32 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${testfile}.o --nocompress-debug-sections] } then {
33 unsupported "compressed debug sections"
37 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${compressedfile}.o --compress-debug-sections] } then {
38 unsupported "compressed debug sections"
42 set got [remote_exec host "cmp ${testfile}.o ${compressedfile}.o" "" "/dev/null"]
43 # Use it to set up xfail.
44 set exec_output [lindex $got 1]
45 if [string match "" $exec_output] then {
46 set compression_used ""
48 set compression_used "yes"
51 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-2.S ${compressedfile2}.o --compress-debug-sections] } then {
52 unsupported "compressed debug sections"
56 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${testfile3}.o --nocompress-debug-sections] } then {
57 unsupported "compressed debug sections"
61 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${compressedfile3}.o --compress-debug-sections] } then {
62 unsupported "compressed debug sections"
66 remote_file host delete ${libfile}.a
67 set got [binutils_run $AR "rc ${libfile}.a ${compressedfile}.o ${compressedfile2}.o ${compressedfile3}.o"]
68 if ![string match "" $got] then {
69 fail "compressed debug sections"
73 set testname "objcopy compress debug sections"
74 set got [binutils_run $OBJCOPY "--compress-debug-sections ${testfile}.o ${copyfile}.o"]
75 if ![string match "" $got] then {
76 fail "objcopy ($testname)"
78 send_log "cmp ${compressedfile}.o ${copyfile}.o\n"
79 verbose "cmp ${compressedfile}.o ${copyfile}.o"
80 set src1 ${compressedfile}.o
81 set src2 ${copyfile}.o
82 set status [remote_exec build cmp "${src1} ${src2}"]
83 set exec_output [lindex $status 1]
84 set exec_output [prune_warnings $exec_output]
86 if [string match "" $exec_output] then {
87 pass "objcopy ($testname)"
89 send_log "$exec_output\n"
90 verbose "$exec_output" 1
91 fail "objcopy ($testname)"
95 set testname "objcopy decompress compressed debug sections"
96 set got [binutils_run $OBJCOPY "--decompress-debug-sections ${compressedfile}.o ${copyfile}.o"]
97 if ![string match "" $got] then {
98 fail "objcopy ($testname)"
100 send_log "cmp ${testfile}.o ${copyfile}.o\n"
101 verbose "cmp ${testfile}.o ${copyfile}.o"
102 set src1 ${testfile}.o
103 set src2 ${copyfile}.o
104 set status [remote_exec build cmp "${src1} ${src2}"]
105 set exec_output [lindex $status 1]
106 set exec_output [prune_warnings $exec_output]
108 if [string match "" $exec_output] then {
109 pass "objcopy ($testname)"
111 send_log "$exec_output\n"
112 verbose "$exec_output" 1
113 fail "objcopy ($testname)"
117 set testname "objcopy decompress debug sections in archive"
118 set got [binutils_run $OBJCOPY "--decompress-debug-sections ${libfile}.a ${copyfile}.a"]
119 if ![string match "" $got] then {
120 fail "objcopy ($testname)"
122 set got [remote_exec host "$READELF -S --wide ${copyfile}.a" "" "/dev/null" "tmpdir/libdw2.out"]
124 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
125 fail "$testname (reason: unexpected output)"
130 if { [regexp_diff tmpdir/libdw2.out $srcdir/$subdir/libdw2.out] } then {
137 # Xfail this test if there are no compressed sections.
138 setup_xfail "$compression_used$target_triplet"
139 set testname "objcopy compress debug sections in archive"
140 set got [binutils_run $OBJCOPY "--compress-debug-sections ${copyfile}.a ${compressedcopyfile}.a"]
141 if ![string match "" $got] then {
142 fail "objcopy ($testname)"
144 set got [remote_exec host "$OBJDUMP -s -j .zdebug_line ${compressedcopyfile}.a" "" "/dev/null" "tmpdir/libdw2-compressed.out"]
146 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
147 fail "$testname (reason: unexpected output)"
152 setup_xfail "$compression_used$target_triplet"
153 if { [regexp_diff tmpdir/libdw2-compressed.out $srcdir/$subdir/libdw2-compressed.out] } then {
160 set testname "objdump compress debug sections"
161 set got [remote_exec host "$OBJDUMP -W ${compressedfile}.o" "" "/dev/null" "objdump.out"]
162 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
166 if { [regexp_diff objdump.out $srcdir/$subdir/dw2-1.W] } then {
172 set testname "objdump compress debug sections 3"
173 set got [remote_exec host "$OBJDUMP -W ${compressedfile3}.o" "" "/dev/null" "objdump.out"]
174 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
178 if { [regexp_diff objdump.out $srcdir/$subdir/dw2-3.W] } then {
184 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-empty.S ${testfile}empty.o --nocompress-debug-sections] } then {
185 unsupported "compressed debug sections"
189 set testname "objcopy compress empty debug sections"
190 set got [binutils_run $OBJCOPY "--compress-debug-sections ${testfile}empty.o ${copyfile}empty.o"]
191 if ![string match "" $got] then {
192 fail "objcopy ($testname)"
194 send_log "cmp ${testfile}empty.o ${copyfile}empty.o\n"
195 verbose "cmp ${testfile}empty.o ${copyfile}empty.o"
196 set src1 ${testfile}empty.o
197 set src2 ${copyfile}empty.o
198 set status [remote_exec build cmp "${src1} ${src2}"]
199 set exec_output [lindex $status 1]
200 set exec_output [prune_warnings $exec_output]
202 if [string match "" $exec_output] then {
203 pass "objcopy ($testname)"
205 send_log "$exec_output\n"
206 verbose "$exec_output" 1
207 fail "objcopy ($testname)"
211 if ![is_remote host] {
212 set tempfile tmpdir/debug_str.o
213 set copyfile tmpdir/debug_str.copy
215 set tempfile [remote_download host tmpdir/debug_str.o]
216 set copyfile debug_str.copy
219 run_dump_test "debug_str"