1# Expect script for linker support of size relocations. 2# 3# Copyright (C) 2013-2016 Free Software Foundation, Inc. 4# 5# This file is part of the GNU Binutils. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 3 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 20# MA 02110-1301, USA. 21# 22 23 24# Size relications have only been implemented for the ix86 and x86_64, 25# so far. 26if {!(([istarget "i?86-*-*"] 27 || [istarget "x86_64-*-*"]) 28 && ([istarget "*-*-elf*"] 29 || [istarget "*-*-nacl*"] 30 || (([istarget "*-*-linux*"] 31 || [istarget "*-*-gnu*"]) 32 && ![istarget "*-*-*aout*"] 33 && ![istarget "*-*-*oldld*"]))) } { 34 verbose "Size relocations tests not run - no target support" 35 return 36} 37 38# So as to avoid rewriting every last test case here in a nacl variant, 39# we use black magic to massage the generic cases into nacl-variant cases. 40if [istarget "*-*-nacl*"] { 41 # Change all the -melf_i386 to -melf_i386_nacl so linking can succeed. 42 set options_regsub(ld) {-m(\\S+) -m\\1_nacl} 43} 44 45set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] 46foreach t $test_list { 47 # We need to strip the ".d", but can leave the dirname. 48 verbose [file rootname $t] 49 run_dump_test [file rootname $t] 50} 51 52# We need a native system. 53if ![isnative] { 54 verbose "Native size relocation tests not run - not a native toolchain" 55 return 56} 57 58# We need a working compiler. 59if { [which $CC] == 0 } { 60 verbose "Native size relocation tests not run - no compiler available" 61 return 62} 63 64# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required. 65global NOPIE_CFLAGS NOPIE_LDFLAGS 66 67run_cc_link_tests [list \ 68 [list \ 69 "Build libsize-1.so" \ 70 "-shared" \ 71 "-fPIC" \ 72 {size-1a.c size-1b.c} \ 73 {} \ 74 "libsize-1.so" \ 75 ] \ 76 [list \ 77 "Build libsize-2.so" \ 78 "-shared" \ 79 "-fPIC" \ 80 {size-2a.c size-2b.c} \ 81 {} \ 82 "libsize-2.so" \ 83 ] \ 84 [list \ 85 "Build libsize-3a.so" \ 86 "-shared" "-fPIC" \ 87 {size-3a.c} \ 88 {} \ 89 "libsize-3a.so" \ 90 ] \ 91 [list \ 92 "Build libsize-3b.so" \ 93 "-shared" \ 94 "-fPIC" \ 95 {size-3b.c} \ 96 {} \ 97 "libsize-3b.so" \ 98 ] \ 99 [list \ 100 "Build libsize-3c.so" \ 101 "-shared" \ 102 "-fPIC" \ 103 {size-3c.c} \ 104 {} \ 105 "libsize-3c.so" \ 106 ] \ 107 [list \ 108 "Build libsize-6b.so" \ 109 "-shared" \ 110 "-fPIC" \ 111 {size-6b.c} \ 112 {} \ 113 "libsize-6b.so" \ 114 ] \ 115 [list \ 116 "Build libsize-7.so" \ 117 "-shared" \ 118 "-fPIC" \ 119 {size-7b.c} \ 120 {} \ 121 "libsize-7.so" \ 122 ] \ 123 [list \ 124 "Build size-7" \ 125 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-7.so" \ 126 "$NOPIE_CFLAGS" \ 127 {size-7a.c} \ 128 {{readelf -rW size-7.rd}} \ 129 "size-7.exe" \ 130 ] \ 131 [list \ 132 "Build libsize-8.so" \ 133 "-shared" "-fPIC" \ 134 {size-8b.c} \ 135 {} \ 136 "libsize-8.so" \ 137 ] \ 138 [list \ 139 "Build size-8" \ 140 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-8.so" \ 141 "$NOPIE_CFLAGS" \ 142 {size-8a.c} \ 143 {{readelf -rW size-8.rd}} \ 144 "size-8.exe" \ 145 ] \ 146 [list \ 147 "Build libsize-9.so" \ 148 "-shared" \ 149 "-fPIC" \ 150 {size-9b.c} \ 151 {{readelf -rW size-9.rd}} \ 152 "libsize-9.so" \ 153 ] \ 154 [list \ 155 "Build libsize-10.so" \ 156 "-shared" \ 157 "-fPIC" \ 158 {size-10b.c} \ 159 {{readelf -rW size-10.rd}} \ 160 "libsize-10.so" \ 161 ] \ 162] 163 164# Check if size relocation works at run-time. 165catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output 166if ![string match "" $exec_output] then { 167 send_log "No run-time size relocation support: $exec_output\n" 168 verbose "No run-time size relocation support: $exec_output" 1 169 return 170} 171 172if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then { 173 verbose "output is [file_contents "tmpdir/dump.out"]" 2 174 fail "Run-time size relocation" 175 return 176} 177 178# Run-time size relocation tests. 179run_ld_link_exec_tests [] [list \ 180 [list \ 181 "Run size-1" \ 182 "tmpdir/libsize-1.so" \ 183 "" \ 184 {size-1.c} \ 185 "size-1" \ 186 "size-1.out" \ 187 ] \ 188 [list \ 189 "Run size-2" \ 190 "tmpdir/libsize-2.so" \ 191 "" \ 192 {size-2.c} \ 193 "size-2" \ 194 "size-2.out" \ 195 ] \ 196 [list \ 197 "Run size-3a" \ 198 "" \ 199 "" \ 200 {size-3.c size-3a.c} \ 201 "size-3a" \ 202 "size-3.out" \ 203 ] \ 204 [list \ 205 "Run size-3b" \ 206 "tmpdir/libsize-3a.so" \ 207 "" \ 208 {size-3.c} \ 209 "size-3b" \ 210 "size-3.out" \ 211 ] \ 212 [list \ 213 "Run size-3c" \ 214 "" \ 215 "" \ 216 {size-3.c size-3b.c} \ 217 "size-3c" \ 218 "size-3.out" \ 219 ] \ 220 [list \ 221 "Run size-3d (1)" \ 222 "tmpdir/libsize-3b.so" \ 223 "" \ 224 {size-3.c} \ 225 "size-3d1" \ 226 "size-3.out" \ 227 ] \ 228 [list \ 229 "Run size-3d (2)" \ 230 "" \ 231 "" \ 232 {size-3.c size-3c.c} \ 233 "size-3d2" \ 234 "size-3.out" \ 235 ] \ 236 [list \ 237 {"Run size-3e" 238 "tmpdir/libsize-3c.so" "" 239 {size-3.c} "size-3e" "size-3.out"} 240 ] \ 241 [list \ 242 "Run size-4a" \ 243 "" \ 244 "" \ 245 {size-4a.c size-4b.c} \ 246 "size-4a" \ 247 "size-4.out" \ 248 "$NOPIE_CFLAGS" \ 249 ] \ 250 [list \ 251 "Run size-4b" \ 252 "" \ 253 "" \ 254 {size-4b.c size-4a.c} \ 255 "size-4b" \ 256 "size-4.out" \ 257 "$NOPIE_CFLAGS" \ 258 ] \ 259 [list \ 260 "Run size-5a" \ 261 "" \ 262 "" \ 263 {size-5a.c size-5b.c} \ 264 "size-5a" \ 265 "size-5.out" \ 266 "$NOPIE_CFLAGS" \ 267 ] \ 268 [list \ 269 "Run size-5b" \ 270 "" \ 271 "" \ 272 {size-5b.c size-5a.c} \ 273 "size-5b" \ 274 "size-5.out" \ 275 "$NOPIE_CFLAGS" \ 276 ] \ 277 [list \ 278 "Run size-6" \ 279 "tmpdir/libsize-6b.so" \ 280 "" \ 281 {size-6a.c} \ 282 "size-6" \ 283 "size-6.out" \ 284 "$NOPIE_CFLAGS" \ 285 ] \ 286 [list \ 287 "Run size-8" \ 288 "tmpdir/libsize-8.so --hash-styl=gnu" \ 289 "" \ 290 {size-8a.c} \ 291 "size-8" \ 292 "size-8.out" \ 293 "$NOPIE_CFLAGS" \ 294 ] \ 295 [list \ 296 "Run size-9" \ 297 "tmpdir/libsize-9.so" \ 298 "" \ 299 {size-9a.c} \ 300 "size-9" \ 301 "size-9.out" \ 302 ] \ 303 [list \ 304 "Run size-10" \ 305 "tmpdir/libsize-10.so" \ 306 "" \ 307 {size-10a.c} \ 308 "size-10" \ 309 "size-10.out" \ 310 ] \ 311] 312