summaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-elf/compress.exp
blob: cfdd767b8abf7e3b74d4040cd93761b92eacdf5a (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
256
# Expect script for ELF compressed debug section tests.
#   Copyright (C) 2010-2022 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils.
#
# This program 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.
#
# This program 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
#

# Exclude non-ELF targets.

if ![is_elf_format] {
    return
}

# Skip targets where -shared is not supported

if ![check_shared_lib_support] {
    return
}

# Check if compiler works
if { ![check_compiler_available] } {
    return
}

if { ![ld_assemble $as "--compress-debug-sections $srcdir/$subdir/empty.s" tmpdir/empty.o ] } {
    fail "linker compressed debug sections"
}

if { ![ld_assemble $as "--compress-debug-sections=zlib-gabi $srcdir/$subdir/empty.s" tmpdir/emptyzlib.o ] } {
    fail "linker compressed debug sections"
}

set build_tests {
  {"Build libfoo.so with compressed debug sections"
   "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections"
   {foo.c} {} "libfoo.so"}
  {"Build libbar.so with compressed debug sections"
   "-shared -Wl,--compress-debug-sections=none"
   "-fPIC -ggdb3 -Wa,--compress-debug-sections"
   {begin.c end.c} {} "libbar.so"}
  {"Build libfoozlib.so with compressed debug sections with zlib-gabi"
   "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
   {foo.c} {} "libfoozlib.so"}
  {"Build libbarzlib.so with compressed debug sections with zlib-gabi"
   "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
   {begin.c end.c} {} "libbarzlib.so"}
  {"Build libzlibfoo.so with zlib compressed debug sections"
   "-shared -Wl,--compress-debug-sections=zlib"
   "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib"
   {foo.c} {} "libzlibfoo.so"}
  {"Build libgnufoo.so with zlib-gnu compressed debug sections"
   "-shared -Wl,--compress-debug-sections=zlib-gnu"
   "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
   {foo.c} {} "libgnufoo.so"}
  {"Build libgabifoo.so with zlib-gabi compressed debug sections"
   "-shared -Wl,--compress-debug-sections=zlib-gabi"
   "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
   {foo.c} {} "libgabifoo.so"}
  {"Build zlibbegin.o with zlib compressed debug sections"
   "-r -nostdlib -Wl,--compress-debug-sections=zlib"
   "-ggdb3 -Wa,--compress-debug-sections=zlib"
   {begin.c} {} "zlibbegin.o"}
  {"Build gnubegin.o with zlib-gnu compressed debug sections"
   "-r -nostdlib -Wl,--compress-debug-sections=zlib-gnu"
   "-ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
   {begin.c} {} "gnubegin.o"}
  {"Build gabiend.o with zlib-gabi compressed debug sections"
   "-r -nostdlib -Wl,--compress-debug-sections=zlib-gabi"
   "-ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
   {end.c} {} "gabiend.o"}
}

set run_tests {
    {"Run normal with libfoo.so with compressed debug sections"
     "tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" ""
     {main.c} "normal" "normal.out" "-Wa,--compress-debug-sections"}
    {"Run normal with libfoozlib.so with compressed debug sections with zlib-gabi"
     "tmpdir/begin.o tmpdir/libfoozlib.so tmpdir/end.o" ""
     {main.c} "normal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
    {"Run zlibnormal with libzlibfoo.so with zlib compressed debug sections"
     "tmpdir/begin.o tmpdir/libzlibfoo.so tmpdir/end.o -Wl,--compress-debug-sections=zlib" ""
     {main.c} "zlibnormal" "normal.out" "-Wa,--compress-debug-sections=zlib"}
    {"Run zlibnormal with libfoozlib.so with zlib compressed debug sections"
     "tmpdir/begin.o tmpdir/libfoozlib.so tmpdir/end.o -Wl,--compress-debug-sections=zlib" ""
     {main.c} "zlibnormal" "normal.out" "-Wa,--compress-debug-sections=zlib"}
    {"Run gnunormal with libgnufoo.so with zlib-gnu compressed debug sections"
     "tmpdir/gnubegin.o tmpdir/libgnufoo.so tmpdir/end.o -Wl,--compress-debug-sections=zlib-gnu" ""
     {main.c} "gnunormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gnu"}
    {"Run gnunormal with libfoozlib.so with zlib-gnu compressed debug sections"
     "tmpdir/gnubegin.o tmpdir/libfoozlib.so tmpdir/end.o -Wl,--compress-debug-sections=zlib-gnu" ""
     {main.c} "gnunormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gnu"}
    {"Run gabinormal with libgabifoo.so with zlib-gabi compressed debug sections"
     "tmpdir/zlibbegin.o tmpdir/libgabifoo.so tmpdir/gabiend.o -Wl,--compress-debug-sections=zlib-gabi" ""
     {main.c} "gabinormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
    {"Run gabinormal with libfoozlib.so with zlib-gabi compressed debug sections"
     "tmpdir/zlibbegin.o tmpdir/libfoozlib.so tmpdir/gabiend.o -Wl,--compress-debug-sections=zlib-gabi" ""
     {main.c} "gabinormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
}

run_cc_link_tests $build_tests
run_ld_link_exec_tests $run_tests

set test_name "Link with zlib-gabi compressed debug input"
send_log "cmp tmpdir/libfoo.so tmpdir/libfoozlib.so\n"
if { [catch {exec cmp tmpdir/libfoo.so tmpdir/libfoozlib.so}] } then {
    send_log "tmpdir/libfoo.so tmpdir/libfoozlib.so differ.\n"
    fail "$test_name"
} else {
    pass "$test_name"
}

set test_name "Link -r with zlib compressed debug output"
set test zlibbegin
send_log "$READELF -S -W tmpdir/$test.o > tmpdir/$test.out\n"
set got [remote_exec host "$READELF -S -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
    fail "$test_name"
} else {
    pass "$test_name"
}

set test_name "Link -r with zlib-gnu compressed debug output"
set test gnubegin
send_log "$READELF -S -W tmpdir/$test.o > tmpdir/$test.out\n"
set got [remote_exec host "$READELF -S -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
    fail "$test_name"
} else {
    pass "$test_name"
}

set test_name "Link -r with zlib-gabi compressed debug output"
set test gabiend
send_log "$READELF -t -W tmpdir/$test.o > tmpdir/$test.out\n"
set got [remote_exec host "$READELF -t -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rt] } then {
    fail "$test_name"
} else {
    pass "$test_name"
}

set test_name "Link with zlib compressed debug output 1"
set test normal
send_log "$READELF -w tmpdir/$test > tmpdir/$test.out\n"
set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test > tmpdir/$test.out"]] "" "/dev/null"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}

set test_name "Link with zlib compressed debug output 2"
set test zlibnormal
send_log "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out\n"
set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out"]] "" "/dev/null"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
    send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
    fail "$test_name"
} else {
    pass "$test_name"
}
set test_name "Link with zlib compressed debug output 3"
send_log "$READELF -S -W tmpdir/$test' > tmpdir/$test.out\n"
set got [remote_exec host "$READELF -S -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
    fail "$test_name"
} else {
    pass "$test_name"
}

set test_name "Link with zlib-gnu compressed debug output 1"
set test gnunormal
send_log "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out\n"
set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out"]] "" "/dev/null"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
    send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
    fail "$test_name"
} else {
    pass "$test_name"
}
set test_name "Link with zlib-gnu compressed debug output 2"
send_log "$READELF -S -W tmpdir/$test' > tmpdir/$test.out\n"
set got [remote_exec host "$READELF -S -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
    fail "$test_name"
} else {
    pass "$test_name"
}

set test gabinormal
set test_name "Link with zlib-gabi compressed debug output 1"
send_log "$READELF -w tmpdir/$test > tmpdir/$test.out\n"
set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test > tmpdir/$test.out"]] "" "/dev/null"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
    send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
    fail "$test_name"
} else {
    pass "$test_name"
}
set test_name "Link with zlib-gabi compressed debug output 2"
send_log "$READELF -t -W tmpdir/$test > tmpdir/$test.out\n"
set got [remote_exec host "$READELF -t -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    send_log "$got\n"
    fail "$test_name"
}
if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rt] } then {
    fail "$test_name"
} else {
    pass "$test_name"
}