1 # Expect script for linker support of size relocations.
3 # Copyright (C) 2013-2020 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 relocations 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 verbose "Size relocations tests not run - no target support"
36 # So as to avoid rewriting every last test case here in a nacl variant,
37 # we use black magic to massage the generic cases into nacl-variant cases.
38 if [istarget "*-*-nacl*"] {
39 # Change all the -melf_i386 to -melf_i386_nacl so linking can succeed.
40 set options_regsub(ld) {-m(\\S+) -m\\1_nacl}
43 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
44 foreach t $test_list {
45 # We need to strip the ".d", but can leave the dirname.
46 verbose [file rootname $t]
47 run_dump_test [file rootname $t]
50 # We need a working compiler.
51 if { ![check_compiler_available] } {
52 verbose "Native size relocation tests not run - no compiler available"
56 run_cc_link_tests [list \
58 "Build libsize-1.so" \
61 {size-1a.c size-1b.c} \
66 "Build libsize-2.so" \
69 {size-2a.c size-2b.c} \
74 "Build libsize-3a.so" \
81 "Build libsize-3b.so" \
89 "Build libsize-3c.so" \
97 "Build libsize-6b.so" \
105 "Build libsize-7.so" \
114 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/libsize-7.so" \
117 {{readelf -rW size-7.rd}} \
121 "Build libsize-8.so" \
129 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/libsize-8.so" \
132 {{readelf -rW size-8.rd}} \
136 "Build libsize-9.so" \
140 {{readelf -rW size-9.rd}} \
144 "Build libsize-10.so" \
148 {{readelf -rW size-10.rd}} \
153 # Check if size relocation works at run-time.
154 catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output
155 if ![string match "" $exec_output] then {
156 send_log "No run-time size relocation support: $exec_output\n"
157 verbose "No run-time size relocation support: $exec_output" 1
161 if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then {
162 verbose "output is [file_contents "tmpdir/dump.out"]" 2
163 fail "Run-time size relocation"
167 # Run-time size relocation tests.
168 run_ld_link_exec_tests [list \
171 "-Wl,--no-as-needed tmpdir/libsize-1.so" \
179 "-Wl,--no-as-needed tmpdir/libsize-2.so" \
189 {size-3.c size-3a.c} \
195 "-Wl,--no-as-needed tmpdir/libsize-3a.so" \
205 {size-3.c size-3b.c} \
211 "-Wl,--no-as-needed tmpdir/libsize-3b.so" \
221 {size-3.c size-3c.c} \
227 "-Wl,--no-as-needed tmpdir/libsize-3c.so" "" \
228 {size-3.c} "size-3e" "size-3.out"} \
234 {size-4a.c size-4b.c} \
243 {size-4b.c size-4a.c} \
252 {size-5a.c size-5b.c} \
261 {size-5b.c size-5a.c} \
268 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-6b.so" \
277 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu,-z,notext \
278 tmpdir/libsize-8.so" \
287 "-Wl,--no-as-needed tmpdir/libsize-9.so" \
295 "-Wl,--no-as-needed tmpdir/libsize-10.so" \