Revert "Use offsets instead of addresses in ELF_SECTION_IN_SEGMENT for non SHT_NOBITS"
[deliverable/binutils-gdb.git] / ld / testsuite / ld-bootstrap / bootstrap.exp
CommitLineData
252b5132 1# Expect script for LD Bootstrap Tests
219d1afa 2# Copyright (C) 1993-2018 Free Software Foundation, Inc.
252b5132 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
252b5132 7# it under the terms of the GNU General Public License as published by
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
252b5132 9# (at your option) any later version.
f96b4a7b 10#
252b5132
RH
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.
f96b4a7b 15#
252b5132
RH
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
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
252b5132
RH
20#
21# Written by Jeffrey Wheat (cassidy@cygnus.com)
22# Rewritten by Ian Lance Taylor (ian@cygnus.com)
23#
24
25# Make sure that ld can bootstrap itself.
26
27# This test can only be run if ld generates native executables.
28if ![isnative] {
29 return
30}
31
98d72909
L
32global STATIC_LDFLAGS
33
ed948520
NC
34# Determine if plugin support is present.
35remote_exec host "$nm --help" "" "/dev/null" "plugin-support"
36set tmp [file_contents "plugin-support"]
37regexp ".*\(--plugin\).*\n" $tmp foo plugins
38if [info exists plugins] then {
39 set plugins "yes"
40} else {
41 set plugins "no"
42}
43
5d3236ee
DK
44# LD can have plugin support even if BFD does not.
45if [check_plugin_api_available] {
46 set plugins "yes"
47}
48
252b5132
RH
49# Bootstrap ld. First link the object files together using -r, in
50# order to test -r. Then link the result into an executable, ld1, to
51# really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
52# new ld, ld3. ld2 and ld3 should be identical.
d9816402
AM
53set test_flags {"" "strip" "--static" "-Wl,--traditional-format"
54 "-Wl,--no-keep-memory" "-Wl,--relax"}
a97726da 55if { [istarget "powerpc-*-*"] } {
d9816402
AM
56 lappend test_flags "-Wl,--ppc476-workaround"
57}
58
59set gcc_B_opt_save $gcc_B_opt
60
61foreach ldexe {ld1 ld2 ld3} {
62 if {![file isdirectory tmpdir/gcc$ldexe]} then {
63 catch "exec mkdir tmpdir/gcc$ldexe" status
64 catch "exec ln -s ../$ldexe tmpdir/gcc$ldexe/ld" status
65 catch "exec ln -s ld tmpdir/gcc$ldexe/collect-ld" status
66 catch "exec ln -s ../../../gas/as-new tmpdir/gcc$ldexe/as" status
67 }
a97726da 68}
252b5132 69
a97726da 70foreach flags $test_flags {
d9816402 71 set gcc_B_opt $gcc_B_opt_save
e1753d2c
L
72 set do_strip "no"
73 if {"$flags" == "strip"} {
74 set testname "bootstrap with $flags"
75 set flags ""
76 set do_strip "yes"
77 } else { if {"$flags" != ""} {
252b5132
RH
78 set testname "bootstrap with $flags"
79 } else {
80 set testname "bootstrap"
e1753d2c 81 }}
252b5132 82
0085b5a8 83 # --static is meaningless and --relax is incompatible with -r.
d9816402
AM
84 regsub -- "-Wl," $flags "" partial_flags
85 if { "$partial_flags" == "--static" || "$partial_flags" == "--relax" } {
0085b5a8
RH
86 set partial_flags ""
87 }
88
a97726da
AM
89 if { $partial_flags == "--ppc476-workaround" } {
90 append partial_flags " -T $srcdir/$subdir/ppc476.t"
91 }
92
252b5132
RH
93 # This test can only be run if we have the ld build directory,
94 # since we need the object files.
95 if {$ld != "$objdir/ld-new"} {
96 untested $testname
97 continue
98 }
99
98d72909
L
100 # If -static doesn't work, these tests will fail.
101 if { $flags == "--static" && [string match "" $STATIC_LDFLAGS] } then {
102 untested $testname
103 continue
104 }
105
ed948520 106 # Plugin support requires linking with a dynamic library which
66a3cb9c 107 # means that these tests will fail.
ed948520
NC
108 if { $flags == "--static" && $plugins == "yes" } then {
109 untested $testname
110 continue
111 }
112
252b5132 113 # If we only have a shared libbfd, we probably can't run the
66a3cb9c 114 # --static test.
252b5132
RH
115 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
116 untested $testname
117 continue
118 }
119
0085b5a8 120 if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
252b5132
RH
121 fail $testname
122 continue
123 }
124
125 # On AIX, you need to specify an import list when using --static.
126 # You only want the import list when creating the final
127 # executable.
41c49998
TW
128 if { [istarget "*-*-aix*"]
129 && ![istarget "ia64-*-aix*"]} {
252b5132
RH
130 if {"$flags" == "--static"} {
131 set flags "--static -bI:/lib/syscalls.exp"
132 }
133 }
134
9b3ea03b
DK
135 # On Cygwin, -lintl may require -liconv when linking statically.
136 set extralibs ""
137 if { [istarget "*-*-cygwin*"]} {
138 if {"$flags" == "--static"} {
139 set extralibs "-liconv"
140 }
141 }
142
f24173eb
L
143 # Check if the system's zlib library is used.
144 if {[file exists ../zlib/Makefile ]} then {
145 set extralibs "$extralibs -L../zlib -lz"
146 } else {
147 set extralibs "$extralibs -lz"
148 }
149
ed948520
NC
150 # Plugin support requires linking with libdl.
151 if { $plugins == "yes" } {
fb2c6e43
AT
152 if { ![istarget "*-*-freebsd*"]} {
153 set extralibs "$extralibs -ldl"
154 }
ed948520
NC
155 }
156
252b5132
RH
157 # On Irix 5, linking with --static only works if all the files are
158 # compiled using -non_shared.
159 if {"$flags" == "--static"} {
160 setup_xfail "mips*-*-irix5*"
161 }
162
d9816402 163 if ![ld_link $CC tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
164 fail $testname
165 continue
166 }
167
e1753d2c
L
168 if {"$do_strip" == "yes"} {
169 verbose -log "$strip tmpdir/ld1"
170 catch "exec $strip tmpdir/ld1" exec_output
171 if ![string match "" $exec_output] then {
172 verbose -log "$exec_output"
173 fail $testname
174 continue
175 }
176 }
177
d9816402
AM
178 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld1/ gcc_B_opt
179 if ![ld_link $CC tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
180 fail $testname
181 continue
182 }
183
d9816402
AM
184 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld2/ gcc_B_opt
185 if ![ld_link $CC tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
186 fail $testname
187 continue
188 }
189
d9816402
AM
190 if { "$flags" == "--static" && { [istarget ia64-*-elf*] || [istarget ia64-*-linux*] }
191 || [istarget mips*-*-linux*] } {
192 # On ia64 and mips, tmpdir/ld2 != tmpdir/ld3 is normal since they are
193 # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
194 # So we rebuild tmpdir/ld2 with tmpdir/ld3.
195 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld3/ gcc_B_opt
196 if ![ld_link $CC tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
197 fail $testname
198 continue
66517a2f 199 }
ad995491
L
200 }
201
86017ce9 202 if {[istarget "*-*-pe"]
336d6a64
AM
203 || [istarget "*-*-wince"]
204 || [istarget "*-*-cygwin*"]
205 || [istarget "*-*-winnt*"]
99ad8390 206 || [istarget "*-*-mingw*"]
336d6a64
AM
207 || [istarget "*-*-interix*"]
208 || [istarget "*-*-beospe*"]
209 || [istarget "*-*-netbsdpe*"]} {
eccbf555
AM
210 # Trim off the date present in PE binaries by only looking
211 # at the ends of the files
212 # Although this works, a way to set the date would be better.
213 # Removing or zeroing the date stamp in the binary produced by
214 # the linker is not possible as it is required by the target OS.
215 set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
216 send_log "$do_compare\n"
217 verbose "$do_compare"
218 catch "exec sh -c [list $do_compare]" exec_output
86017ce9 219 } else {
eccbf555
AM
220 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
221 verbose "cmp tmpdir/ld2 tmpdir/ld3"
222 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
86017ce9 223 }
252b5132
RH
224 set exec_output [prune_warnings $exec_output]
225
226 if [string match "" $exec_output] then {
227 pass $testname
228 } else {
229 send_log "$exec_output\n"
230 verbose "$exec_output" 1
231
232 fail $testname
233 }
234}
9ab80182 235
d9816402 236set gcc_B_opt $gcc_B_opt_save
9ab80182 237catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
eccbf555 238catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status
This page took 0.810366 seconds and 4 git commands to generate.