[ld, testsuite] Don't print to stdout for "readelf -w" to avoid buffer overflow
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / compress.exp
CommitLineData
4a114e3e 1# Expect script for ELF compressed debug section tests.
2571583a 2# Copyright (C) 2010-2017 Free Software Foundation, Inc.
4a114e3e
L
3#
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
20#
21
22# Exclude non-ELF targets.
23
24if ![is_elf_format] {
25 return
26}
27
47523653
AM
28# Skip targets where -shared is not supported
29
30if ![check_shared_lib_support] {
31 return
32}
33
4a114e3e
L
34# Check if compiler works
35if { [which $CC] == 0 } {
36 return
37}
38
39global as
40if { ![ld_assemble $as "--compress-debug-sections $srcdir/$subdir/empty.s" tmpdir/empty.o ] } {
dae148f3 41 fail "linker compressed debug sections"
4a114e3e
L
42}
43
151411f8
L
44if { ![ld_assemble $as "--compress-debug-sections=zlib-gabi $srcdir/$subdir/empty.s" tmpdir/emptyzlib.o ] } {
45 fail "linker compressed debug sections"
46}
47
4a114e3e
L
48set build_tests {
49 {"Build libfoo.so with compressed debug sections"
84b74b49 50 "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections"
4a114e3e
L
51 {foo.c} {} "libfoo.so"}
52 {"Build libbar.so with compressed debug sections"
0ce398f1 53 "-shared -Wl,--compress-debug-sections=none"
84b74b49 54 "-fPIC -ggdb3 -Wa,--compress-debug-sections"
4a114e3e 55 {begin.c end.c} {} "libbar.so"}
151411f8 56 {"Build libfoozlib.so with compressed debug sections with zlib-gabi"
84b74b49 57 "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
151411f8
L
58 {foo.c} {} "libfoozlib.so"}
59 {"Build libbarzlib.so with compressed debug sections with zlib-gabi"
84b74b49 60 "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
151411f8 61 {begin.c end.c} {} "libbarzlib.so"}
0ce398f1
L
62 {"Build libzlibfoo.so with zlib compressed debug sections"
63 "-shared -Wl,--compress-debug-sections=zlib"
84b74b49 64 "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib"
0ce398f1
L
65 {foo.c} {} "libzlibfoo.so"}
66 {"Build libgnufoo.so with zlib-gnu compressed debug sections"
67 "-shared -Wl,--compress-debug-sections=zlib-gnu"
84b74b49 68 "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
0ce398f1
L
69 {foo.c} {} "libgnufoo.so"}
70 {"Build libgabifoo.so with zlib-gabi compressed debug sections"
71 "-shared -Wl,--compress-debug-sections=zlib-gabi"
84b74b49 72 "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
0ce398f1
L
73 {foo.c} {} "libgabifoo.so"}
74 {"Build zlibbegin.o with zlib compressed debug sections"
75 "-r -nostdlib -Wl,--compress-debug-sections=zlib"
84b74b49 76 "-ggdb3 -Wa,--compress-debug-sections=zlib"
0ce398f1
L
77 {begin.c} {} "zlibbegin.o"}
78 {"Build gnubegin.o with zlib-gnu compressed debug sections"
79 "-r -nostdlib -Wl,--compress-debug-sections=zlib-gnu"
84b74b49 80 "-ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
0ce398f1
L
81 {begin.c} {} "gnubegin.o"}
82 {"Build gabiend.o with zlib-gabi compressed debug sections"
83 "-r -nostdlib -Wl,--compress-debug-sections=zlib-gabi"
84b74b49 84 "-ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
0ce398f1 85 {end.c} {} "gabiend.o"}
4a114e3e
L
86}
87
88set run_tests {
89 {"Run normal with libfoo.so with compressed debug sections"
151411f8
L
90 "tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" ""
91 {main.c} "normal" "normal.out" "-Wa,--compress-debug-sections"}
716f1413 92 {"Run normal with libfoozlib.so with compressed debug sections with zlib-gabi"
151411f8
L
93 "tmpdir/begin.o tmpdir/libfoozlib.so tmpdir/end.o" ""
94 {main.c} "normal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
0ce398f1 95 {"Run zlibnormal with libzlibfoo.so with zlib compressed debug sections"
d9816402 96 "tmpdir/begin.o tmpdir/libzlibfoo.so tmpdir/end.o -Wl,--compress-debug-sections=zlib" ""
0ce398f1 97 {main.c} "zlibnormal" "normal.out" "-Wa,--compress-debug-sections=zlib"}
716f1413 98 {"Run zlibnormal with libfoozlib.so with zlib compressed debug sections"
d9816402 99 "tmpdir/begin.o tmpdir/libfoozlib.so tmpdir/end.o -Wl,--compress-debug-sections=zlib" ""
716f1413 100 {main.c} "zlibnormal" "normal.out" "-Wa,--compress-debug-sections=zlib"}
0ce398f1 101 {"Run gnunormal with libgnufoo.so with zlib-gnu compressed debug sections"
d9816402 102 "tmpdir/gnubegin.o tmpdir/libgnufoo.so tmpdir/end.o -Wl,--compress-debug-sections=zlib-gnu" ""
0ce398f1 103 {main.c} "gnunormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gnu"}
716f1413 104 {"Run gnunormal with libfoozlib.so with zlib-gnu compressed debug sections"
d9816402 105 "tmpdir/gnubegin.o tmpdir/libfoozlib.so tmpdir/end.o -Wl,--compress-debug-sections=zlib-gnu" ""
716f1413 106 {main.c} "gnunormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gnu"}
0ce398f1 107 {"Run gabinormal with libgabifoo.so with zlib-gabi compressed debug sections"
d9816402 108 "tmpdir/zlibbegin.o tmpdir/libgabifoo.so tmpdir/gabiend.o -Wl,--compress-debug-sections=zlib-gabi" ""
0ce398f1 109 {main.c} "gabinormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
716f1413 110 {"Run gabinormal with libfoozlib.so with zlib-gabi compressed debug sections"
d9816402 111 "tmpdir/zlibbegin.o tmpdir/libfoozlib.so tmpdir/gabiend.o -Wl,--compress-debug-sections=zlib-gabi" ""
716f1413 112 {main.c} "gabinormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
4a114e3e
L
113}
114
115run_cc_link_tests $build_tests
982c6f26 116run_ld_link_exec_tests $run_tests
151411f8
L
117
118set test_name "Link with zlib-gabi compressed debug input"
119send_log "cmp tmpdir/libfoo.so tmpdir/libfoozlib.so\n"
120if { [catch {exec cmp tmpdir/libfoo.so tmpdir/libfoozlib.so}] } then {
121 send_log "tmpdir/libfoo.so tmpdir/libfoozlib.so differ.\n"
122 fail "$test_name"
123} else {
124 pass "$test_name"
125}
0ce398f1
L
126
127global READELF
128
129set test_name "Link -r with zlib compressed debug output"
130set test zlibbegin
131send_log "$READELF -S -W tmpdir/$test.o > tmpdir/$test.out\n"
132set got [remote_exec host "$READELF -S -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
133if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
134 send_log "$got\n"
135 unresolved "$test_name"
136}
137if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
138 fail "$test_name"
139} else {
140 pass "$test_name"
141}
142
143set test_name "Link -r with zlib-gnu compressed debug output"
144set test gnubegin
145send_log "$READELF -S -W tmpdir/$test.o > tmpdir/$test.out\n"
146set got [remote_exec host "$READELF -S -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
147if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
148 send_log "$got\n"
149 unresolved "$test_name"
150}
151if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
152 fail "$test_name"
153} else {
154 pass "$test_name"
155}
156
157set test_name "Link -r with zlib-gabi compressed debug output"
158set test gabiend
159send_log "$READELF -t -W tmpdir/$test.o > tmpdir/$test.out\n"
160set got [remote_exec host "$READELF -t -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
161if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
162 send_log "$got\n"
163 unresolved "$test_name"
164}
165if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rt] } then {
166 fail "$test_name"
167} else {
168 pass "$test_name"
169}
170
171set test_name "Link with zlib compressed debug output"
172set test normal
173send_log "$READELF -w tmpdir/$test > tmpdir/$test.out\n"
65f90e82 174set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test > tmpdir/$test.out"]] "" "/dev/null"]
0ce398f1
L
175if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
176 send_log "$got\n"
177 unresolved "$test_name"
178}
179
180set test_name "Link with zlib compressed debug output"
181set test zlibnormal
182send_log "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out\n"
65f90e82 183set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out"]] "" "/dev/null"]
0ce398f1
L
184if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
185 send_log "$got\n"
186 unresolved "$test_name"
187}
188if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
189 send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
190 fail "$test_name"
191} else {
192 pass "$test_name"
193}
194send_log "$READELF -S -W tmpdir/$test' > tmpdir/$test.out\n"
195set got [remote_exec host "$READELF -S -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
196if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
197 send_log "$got\n"
198 unresolved "$test_name"
199}
200if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
201 fail "$test_name"
202} else {
203 pass "$test_name"
204}
205
206set test_name "Link with zlib-gnu compressed debug output"
207set test gnunormal
208send_log "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out\n"
65f90e82 209set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out"]] "" "/dev/null"]
0ce398f1
L
210if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
211 send_log "$got\n"
212 unresolved "$test_name"
213}
214if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
215 send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
216 fail "$test_name"
217} else {
218 pass "$test_name"
219}
220send_log "$READELF -S -W tmpdir/$test' > tmpdir/$test.out\n"
221set got [remote_exec host "$READELF -S -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
222if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
223 send_log "$got\n"
224 unresolved "$test_name"
225}
226if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
227 fail "$test_name"
228} else {
229 pass "$test_name"
230}
231
232set test gabinormal
233set test_name "Link with zlib-gabi compressed debug output"
234send_log "$READELF -w tmpdir/$test > tmpdir/$test.out\n"
65f90e82 235set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test > tmpdir/$test.out"]] "" "/dev/null"]
0ce398f1
L
236if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
237 send_log "$got\n"
238 unresolved "$test_name"
239}
240if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
241 send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
242 fail "$test_name"
243} else {
244 pass "$test_name"
245}
246send_log "$READELF -t -W tmpdir/$test > tmpdir/$test.out\n"
247set got [remote_exec host "$READELF -t -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
248if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
249 send_log "$got\n"
250 unresolved "$test_name"
251}
252if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rt] } then {
253 fail "$test_name"
254} else {
255 pass "$test_name"
256}
This page took 0.430289 seconds and 4 git commands to generate.