1 # Expect script for linker support of size relocations.
3 # Copyright (C) 2013-2017 Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
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.
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.
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,
24 # Size relications have only been implemented for the ix86 and x86_64,
26 if {!(([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"
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.
40 if [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}
45 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
46 foreach 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]
52 # We need a working compiler.
53 if { [which $CC] == 0 } {
54 verbose "Native size relocation tests not run - no compiler available"
58 # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
59 global NOPIE_CFLAGS NOPIE_LDFLAGS
61 run_cc_link_tests [list \
63 "Build libsize-1.so" \
66 {size-1a.c size-1b.c} \
71 "Build libsize-2.so" \
74 {size-2a.c size-2b.c} \
79 "Build libsize-3a.so" \
86 "Build libsize-3b.so" \
94 "Build libsize-3c.so" \
102 "Build libsize-6b.so" \
110 "Build libsize-7.so" \
119 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-7.so" \
122 {{readelf -rW size-7.rd}} \
126 "Build libsize-8.so" \
134 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-8.so" \
137 {{readelf -rW size-8.rd}} \
141 "Build libsize-9.so" \
145 {{readelf -rW size-9.rd}} \
149 "Build libsize-10.so" \
153 {{readelf -rW size-10.rd}} \
158 # Check if size relocation works at run-time.
159 catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output
160 if ![string match "" $exec_output] then {
161 send_log "No run-time size relocation support: $exec_output\n"
162 verbose "No run-time size relocation support: $exec_output" 1
166 if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then {
167 verbose "output is [file_contents "tmpdir/dump.out"]" 2
168 fail "Run-time size relocation"
172 # Run-time size relocation tests.
173 run_ld_link_exec_tests [list \
176 "-Wl,--no-as-needed tmpdir/libsize-1.so" \
184 "-Wl,--no-as-needed tmpdir/libsize-2.so" \
194 {size-3.c size-3a.c} \
200 "-Wl,--no-as-needed tmpdir/libsize-3a.so" \
210 {size-3.c size-3b.c} \
216 "-Wl,--no-as-needed tmpdir/libsize-3b.so" \
226 {size-3.c size-3c.c} \
232 "-Wl,--no-as-needed tmpdir/libsize-3c.so" ""
233 {size-3.c} "size-3e" "size-3.out"}
239 {size-4a.c size-4b.c} \
248 {size-4b.c size-4a.c} \
257 {size-5a.c size-5b.c} \
266 {size-5b.c size-5a.c} \
273 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-6b.so" \
282 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu \
283 tmpdir/libsize-8.so" \
292 "-Wl,--no-as-needed tmpdir/libsize-9.so" \
300 "-Wl,--no-as-needed tmpdir/libsize-10.so" \