| 1 | # Expect script for ELF compressed debug section tests. |
| 2 | # Copyright (C) 2010-2018 Free Software Foundation, Inc. |
| 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 | |
| 24 | if ![is_elf_format] { |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | # Skip targets where -shared is not supported |
| 29 | |
| 30 | if ![check_shared_lib_support] { |
| 31 | return |
| 32 | } |
| 33 | |
| 34 | # Check if compiler works |
| 35 | if { [which $CC] == 0 } { |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | global as |
| 40 | if { ![ld_assemble $as "--compress-debug-sections $srcdir/$subdir/empty.s" tmpdir/empty.o ] } { |
| 41 | fail "linker compressed debug sections" |
| 42 | } |
| 43 | |
| 44 | if { ![ld_assemble $as "--compress-debug-sections=zlib-gabi $srcdir/$subdir/empty.s" tmpdir/emptyzlib.o ] } { |
| 45 | fail "linker compressed debug sections" |
| 46 | } |
| 47 | |
| 48 | set build_tests { |
| 49 | {"Build libfoo.so with compressed debug sections" |
| 50 | "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections" |
| 51 | {foo.c} {} "libfoo.so"} |
| 52 | {"Build libbar.so with compressed debug sections" |
| 53 | "-shared -Wl,--compress-debug-sections=none" |
| 54 | "-fPIC -ggdb3 -Wa,--compress-debug-sections" |
| 55 | {begin.c end.c} {} "libbar.so"} |
| 56 | {"Build libfoozlib.so with compressed debug sections with zlib-gabi" |
| 57 | "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi" |
| 58 | {foo.c} {} "libfoozlib.so"} |
| 59 | {"Build libbarzlib.so with compressed debug sections with zlib-gabi" |
| 60 | "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi" |
| 61 | {begin.c end.c} {} "libbarzlib.so"} |
| 62 | {"Build libzlibfoo.so with zlib compressed debug sections" |
| 63 | "-shared -Wl,--compress-debug-sections=zlib" |
| 64 | "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib" |
| 65 | {foo.c} {} "libzlibfoo.so"} |
| 66 | {"Build libgnufoo.so with zlib-gnu compressed debug sections" |
| 67 | "-shared -Wl,--compress-debug-sections=zlib-gnu" |
| 68 | "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gnu" |
| 69 | {foo.c} {} "libgnufoo.so"} |
| 70 | {"Build libgabifoo.so with zlib-gabi compressed debug sections" |
| 71 | "-shared -Wl,--compress-debug-sections=zlib-gabi" |
| 72 | "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi" |
| 73 | {foo.c} {} "libgabifoo.so"} |
| 74 | {"Build zlibbegin.o with zlib compressed debug sections" |
| 75 | "-r -nostdlib -Wl,--compress-debug-sections=zlib" |
| 76 | "-ggdb3 -Wa,--compress-debug-sections=zlib" |
| 77 | {begin.c} {} "zlibbegin.o"} |
| 78 | {"Build gnubegin.o with zlib-gnu compressed debug sections" |
| 79 | "-r -nostdlib -Wl,--compress-debug-sections=zlib-gnu" |
| 80 | "-ggdb3 -Wa,--compress-debug-sections=zlib-gnu" |
| 81 | {begin.c} {} "gnubegin.o"} |
| 82 | {"Build gabiend.o with zlib-gabi compressed debug sections" |
| 83 | "-r -nostdlib -Wl,--compress-debug-sections=zlib-gabi" |
| 84 | "-ggdb3 -Wa,--compress-debug-sections=zlib-gnu" |
| 85 | {end.c} {} "gabiend.o"} |
| 86 | } |
| 87 | |
| 88 | set run_tests { |
| 89 | {"Run normal with libfoo.so with compressed debug sections" |
| 90 | "tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" |
| 91 | {main.c} "normal" "normal.out" "-Wa,--compress-debug-sections"} |
| 92 | {"Run normal with libfoozlib.so with compressed debug sections with zlib-gabi" |
| 93 | "tmpdir/begin.o tmpdir/libfoozlib.so tmpdir/end.o" "" |
| 94 | {main.c} "normal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"} |
| 95 | {"Run zlibnormal with libzlibfoo.so with zlib compressed debug sections" |
| 96 | "tmpdir/begin.o tmpdir/libzlibfoo.so tmpdir/end.o -Wl,--compress-debug-sections=zlib" "" |
| 97 | {main.c} "zlibnormal" "normal.out" "-Wa,--compress-debug-sections=zlib"} |
| 98 | {"Run zlibnormal with libfoozlib.so with zlib compressed debug sections" |
| 99 | "tmpdir/begin.o tmpdir/libfoozlib.so tmpdir/end.o -Wl,--compress-debug-sections=zlib" "" |
| 100 | {main.c} "zlibnormal" "normal.out" "-Wa,--compress-debug-sections=zlib"} |
| 101 | {"Run gnunormal with libgnufoo.so with zlib-gnu compressed debug sections" |
| 102 | "tmpdir/gnubegin.o tmpdir/libgnufoo.so tmpdir/end.o -Wl,--compress-debug-sections=zlib-gnu" "" |
| 103 | {main.c} "gnunormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gnu"} |
| 104 | {"Run gnunormal with libfoozlib.so with zlib-gnu compressed debug sections" |
| 105 | "tmpdir/gnubegin.o tmpdir/libfoozlib.so tmpdir/end.o -Wl,--compress-debug-sections=zlib-gnu" "" |
| 106 | {main.c} "gnunormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gnu"} |
| 107 | {"Run gabinormal with libgabifoo.so with zlib-gabi compressed debug sections" |
| 108 | "tmpdir/zlibbegin.o tmpdir/libgabifoo.so tmpdir/gabiend.o -Wl,--compress-debug-sections=zlib-gabi" "" |
| 109 | {main.c} "gabinormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"} |
| 110 | {"Run gabinormal with libfoozlib.so with zlib-gabi compressed debug sections" |
| 111 | "tmpdir/zlibbegin.o tmpdir/libfoozlib.so tmpdir/gabiend.o -Wl,--compress-debug-sections=zlib-gabi" "" |
| 112 | {main.c} "gabinormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"} |
| 113 | } |
| 114 | |
| 115 | run_cc_link_tests $build_tests |
| 116 | run_ld_link_exec_tests $run_tests |
| 117 | |
| 118 | set test_name "Link with zlib-gabi compressed debug input" |
| 119 | send_log "cmp tmpdir/libfoo.so tmpdir/libfoozlib.so\n" |
| 120 | if { [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 | } |
| 126 | |
| 127 | global READELF |
| 128 | |
| 129 | set test_name "Link -r with zlib compressed debug output" |
| 130 | set test zlibbegin |
| 131 | send_log "$READELF -S -W tmpdir/$test.o > tmpdir/$test.out\n" |
| 132 | set got [remote_exec host "$READELF -S -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"] |
| 133 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 134 | send_log "$got\n" |
| 135 | unresolved "$test_name" |
| 136 | } |
| 137 | if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then { |
| 138 | fail "$test_name" |
| 139 | } else { |
| 140 | pass "$test_name" |
| 141 | } |
| 142 | |
| 143 | set test_name "Link -r with zlib-gnu compressed debug output" |
| 144 | set test gnubegin |
| 145 | send_log "$READELF -S -W tmpdir/$test.o > tmpdir/$test.out\n" |
| 146 | set got [remote_exec host "$READELF -S -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"] |
| 147 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 148 | send_log "$got\n" |
| 149 | unresolved "$test_name" |
| 150 | } |
| 151 | if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then { |
| 152 | fail "$test_name" |
| 153 | } else { |
| 154 | pass "$test_name" |
| 155 | } |
| 156 | |
| 157 | set test_name "Link -r with zlib-gabi compressed debug output" |
| 158 | set test gabiend |
| 159 | send_log "$READELF -t -W tmpdir/$test.o > tmpdir/$test.out\n" |
| 160 | set got [remote_exec host "$READELF -t -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"] |
| 161 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 162 | send_log "$got\n" |
| 163 | unresolved "$test_name" |
| 164 | } |
| 165 | if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rt] } then { |
| 166 | fail "$test_name" |
| 167 | } else { |
| 168 | pass "$test_name" |
| 169 | } |
| 170 | |
| 171 | set test_name "Link with zlib compressed debug output 1" |
| 172 | set test normal |
| 173 | send_log "$READELF -w tmpdir/$test > tmpdir/$test.out\n" |
| 174 | set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test > tmpdir/$test.out"]] "" "/dev/null"] |
| 175 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 176 | send_log "$got\n" |
| 177 | unresolved "$test_name" |
| 178 | } |
| 179 | |
| 180 | set test_name "Link with zlib compressed debug output 2" |
| 181 | set test zlibnormal |
| 182 | send_log "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out\n" |
| 183 | set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out"]] "" "/dev/null"] |
| 184 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 185 | send_log "$got\n" |
| 186 | unresolved "$test_name" |
| 187 | } |
| 188 | if { [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 | } |
| 194 | set test_name "Link with zlib compressed debug output 3" |
| 195 | send_log "$READELF -S -W tmpdir/$test' > tmpdir/$test.out\n" |
| 196 | set got [remote_exec host "$READELF -S -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"] |
| 197 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 198 | send_log "$got\n" |
| 199 | unresolved "$test_name" |
| 200 | } |
| 201 | if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then { |
| 202 | fail "$test_name" |
| 203 | } else { |
| 204 | pass "$test_name" |
| 205 | } |
| 206 | |
| 207 | set test_name "Link with zlib-gnu compressed debug output 1" |
| 208 | set test gnunormal |
| 209 | send_log "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out\n" |
| 210 | set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out"]] "" "/dev/null"] |
| 211 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 212 | send_log "$got\n" |
| 213 | unresolved "$test_name" |
| 214 | } |
| 215 | if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then { |
| 216 | send_log "tmpdir/normal.out tmpdir/$test.out differ.\n" |
| 217 | fail "$test_name" |
| 218 | } else { |
| 219 | pass "$test_name" |
| 220 | } |
| 221 | set test_name "Link with zlib-gnu compressed debug output 2" |
| 222 | send_log "$READELF -S -W tmpdir/$test' > tmpdir/$test.out\n" |
| 223 | set got [remote_exec host "$READELF -S -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"] |
| 224 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 225 | send_log "$got\n" |
| 226 | unresolved "$test_name" |
| 227 | } |
| 228 | if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then { |
| 229 | fail "$test_name" |
| 230 | } else { |
| 231 | pass "$test_name" |
| 232 | } |
| 233 | |
| 234 | set test gabinormal |
| 235 | set test_name "Link with zlib-gabi compressed debug output 1" |
| 236 | send_log "$READELF -w tmpdir/$test > tmpdir/$test.out\n" |
| 237 | set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test > tmpdir/$test.out"]] "" "/dev/null"] |
| 238 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 239 | send_log "$got\n" |
| 240 | unresolved "$test_name" |
| 241 | } |
| 242 | if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then { |
| 243 | send_log "tmpdir/normal.out tmpdir/$test.out differ.\n" |
| 244 | fail "$test_name" |
| 245 | } else { |
| 246 | pass "$test_name" |
| 247 | } |
| 248 | set test_name "Link with zlib-gabi compressed debug output 2" |
| 249 | send_log "$READELF -t -W tmpdir/$test > tmpdir/$test.out\n" |
| 250 | set got [remote_exec host "$READELF -t -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"] |
| 251 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 252 | send_log "$got\n" |
| 253 | unresolved "$test_name" |
| 254 | } |
| 255 | if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rt] } then { |
| 256 | fail "$test_name" |
| 257 | } else { |
| 258 | pass "$test_name" |
| 259 | } |