1 # Expect script for linker support of size relocations.
3 # Copyright (C) 2013-2024 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 # Skip when -shared is not supported
37 if { ![check_shared_lib_support] } {
38 verbose "Size relocation tests not run - shared support disabled"
42 # So as to avoid rewriting every last test case here in a nacl variant,
43 # we use black magic to massage the generic cases into nacl-variant cases.
44 if [istarget "*-*-nacl*"] {
45 # Change all the -melf_i386 to -melf_i386_nacl so linking can succeed.
46 set options_regsub(ld) {-m(\\S+) -m\\1_nacl}
49 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
50 foreach t $test_list {
51 # We need to strip the ".d", but can leave the dirname.
52 verbose [file rootname $t]
53 run_dump_test [file rootname $t]
56 # We need a working compiler.
57 if { ![check_compiler_available] } {
58 verbose "Native size relocation tests not run - no compiler available"
62 run_cc_link_tests [list \
64 "Build libsize-1.so" \
67 {size-1a.c size-1b.c} \
72 "Build libsize-2.so" \
75 {size-2a.c size-2b.c} \
80 "Build libsize-3a.so" \
87 "Build libsize-3b.so" \
95 "Build libsize-3c.so" \
103 "Build libsize-6b.so" \
111 "Build libsize-7.so" \
120 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/libsize-7.so" \
123 {{readelf -rW size-7.rd}} \
127 "Build libsize-8.so" \
135 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/libsize-8.so" \
138 {{readelf -rW size-8.rd}} \
142 "Build libsize-9.so" \
143 "-shared $NOSANITIZE_CFLAGS" \
144 "-fPIC $NOSANITIZE_CFLAGS" \
146 {{readelf -rW size-9.rd}} \
150 "Build libsize-10.so" \
154 {{readelf -rW size-10.rd}} \
159 # Check if size relocation works at run-time.
160 catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output
161 if ![string match "" $exec_output] then {
162 send_log "No run-time size relocation support: $exec_output\n"
163 verbose "No run-time size relocation support: $exec_output" 1
167 if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then {
168 verbose "output is [file_contents "tmpdir/dump.out"]" 2
169 fail "Run-time size relocation"
173 # Run-time size relocation tests.
174 run_ld_link_exec_tests [list \
177 "-Wl,--no-as-needed tmpdir/libsize-1.so" \
185 "-Wl,--no-as-needed tmpdir/libsize-2.so" \
195 {size-3.c size-3a.c} \
201 "-Wl,--no-as-needed tmpdir/libsize-3a.so" \
211 {size-3.c size-3b.c} \
217 "-Wl,--no-as-needed tmpdir/libsize-3b.so" \
227 {size-3.c size-3c.c} \
233 "-Wl,--no-as-needed tmpdir/libsize-3c.so" "" \
234 {size-3.c} "size-3e" "size-3.out"} \
240 {size-4a.c size-4b.c} \
249 {size-4b.c size-4a.c} \
258 {size-5a.c size-5b.c} \
267 {size-5b.c size-5a.c} \
274 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-6b.so" \
283 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-style=gnu,-z,notext \
284 tmpdir/libsize-8.so" \
293 "-Wl,--no-as-needed tmpdir/libsize-9.so $NOSANITIZE_CFLAGS" \
298 "$NOSANITIZE_CFLAGS" \
302 "-Wl,--no-as-needed tmpdir/libsize-10.so" \