LD/testsuite: Move ELF shared library tests from elf.exp to shared.exp
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2018 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
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.
15 #
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
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 # Exclude non-ELF targets.
23
24 if ![is_elf_format] {
25 return
26 }
27
28 set old_ldflags $LDFLAGS
29 if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
31 }
32
33 # hpux .comm differs from everyone else
34 set hpux ""
35 set old_asflags $ASFLAGS
36 if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
39 }
40
41 if { [istarget alpha*-*-* ] } {
42 # The compress1 test is written expecting 32-bit addresses; force the
43 # executable down into the low address space to match.
44 # ??? How can we adjust just the one testcase?
45 set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000"
46 }
47
48 if { [istarget "*-*-nacl*"] } {
49 # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64.
50 # But the target default is ELFCLASS32. So the cases explicitly use
51 # -melf_x86_64 to select that, but NaCl needs a different emulation name.
52 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl}
53 }
54
55 if { [istarget "*-*-solaris*"] } {
56 # Same for Solaris
57 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
58 }
59
60 if { [is_remote host] } then {
61 remote_download host merge.ld
62 }
63
64 # Note - the output file from the second test (symbol3w.a) is
65 # used in the proc is_elf64 test below...
66 run_ld_link_tests [list \
67 [list "Build symbol3.a" \
68 "" "" $hpux \
69 {symbol3.s} {} "symbol3.a" ] \
70 [list "Build symbol3w.a" \
71 "" "" "" \
72 {symbol3w.s} {} "symbol3w.a" ] \
73 ]
74
75
76 # True if the object format is known to be 64-bit ELF.
77 #
78 proc is_elf64 { binary_file } {
79 global READELF
80 global READELFFLAGS
81
82 set readelf_size ""
83 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
84
85 if ![string match "" $got] then {
86 return 0
87 }
88
89 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
90 [file_contents readelf.out] nil readelf_size] } {
91 verbose "FAILED to determine ELF size"
92 return 0
93 }
94
95 if { $readelf_size == "64" } {
96 return 1
97 }
98
99 return 0
100 }
101
102 if [is_elf64 tmpdir/symbol3w.a] {
103 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
104 } else {
105 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
106 }
107
108
109
110 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
111 run_ld_link_tests {
112 {"PR ld/21703"
113 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
114 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
115 {"PR ld/21703 -r"
116 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
117 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
118 } "d30v-*-*" "dlx-*-*" "pj-*-*"
119
120 if [is_underscore_target] {
121 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
122 }
123
124 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
125 foreach t $test_list {
126 # We need to strip the ".d", but can leave the dirname.
127 verbose [file rootname $t]
128 run_dump_test [file rootname $t]
129 }
130
131 # Targets using the generic linker backend don't support generating
132 # an import library.
133 set xfail_implib ""
134 if [is_generic_elf] {
135 set xfail_implib "*-*-*"
136 }
137
138 # Check that the --out-implib option work correctly.
139 run_ld_link_tests [list \
140 [list "Generate empty import library" \
141 "--out-implib=tmpdir/implib.lib" "" \
142 [concat "--defsym NO_GLOBAL=1" $hpux] \
143 {implib.s} \
144 {{ld empty-implib.out}} \
145 "implib" ] \
146 [list "Generate import library" \
147 "--out-implib=tmpdir/implib.lib" "" \
148 $hpux \
149 {implib.s} \
150 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
151 "implib" ] \
152 ] $xfail_implib
153
154 #v850 gas complains about .tbss.var section attributes.
155 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
156 run_ld_link_tests {
157 {"--gc-sections on tls variable"
158 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
159 }
160 }
161
162 if { [istarget *-*-*linux*]
163 || [istarget *-*-nacl*]
164 || [istarget *-*-gnu*] } {
165 run_ld_link_tests {
166 {"stack exec" "-z execstack" "" "" {stack.s}
167 {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
168 {"stack size" "-z stack-size=0x123400" "" "" {stack.s}
169 {{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
170 }
171 }
172
173 set LDFLAGS $old_ldflags
174 set ASFLAGS $old_asflags
175
176 # Check to see if the C compiler works
177 if { [which $CC] == 0 } {
178 return
179 }
180
181 if [check_gc_sections_available] {
182 run_cc_link_tests {
183 {"PR ld/13195" "-Wl,--gc-sections" ""
184 {pr13195.c} {} "pr13195"}
185 }
186 }
187
188 set array_tests {
189 {"preinit array" "" ""
190 {preinit.c} "preinit" "preinit.out"}
191 {"init array" "" ""
192 {init.c} "init" "init.out"}
193 {"fini array" "" ""
194 {fini.c} "fini" "fini.out"}
195 {"init array mixed" "" ""
196 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
197 }
198 set array_tests_pie {
199 {"PIE preinit array" "-pie" ""
200 {preinit.c} "preinit" "preinit.out" "-fPIE"}
201 {"PIE init array" "-pie" ""
202 {init.c} "init" "init.out" "-fPIE"}
203 {"PIE fini array" "-pie" ""
204 {fini.c} "fini" "fini.out" "-fPIE"}
205 {"PIE init array mixed" "-pie" ""
206 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
207 {"PIE PR ld/14525" "-pie" ""
208 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
209 }
210 set array_tests_static {
211 {"static preinit array" "-static" ""
212 {preinit.c} "preinit" "preinit.out"}
213 {"static init array" "-static" ""
214 {init.c} "init" "init.out"}
215 {"static fini array" "-static" ""
216 {fini.c} "fini" "fini.out"}
217 {"static init array mixed" "-static" ""
218 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
219 }
220
221 # NetBSD ELF systems do not currently support the .*_array sections.
222 set xfails "*-*-netbsdelf*"
223 run_ld_link_exec_tests $array_tests $xfails
224
225 if { [istarget *-*-linux*]
226 || [istarget *-*-nacl*]
227 || [istarget *-*-gnu*] } {
228 run_ld_link_exec_tests $array_tests_pie $xfails
229
230 run_ld_link_exec_tests [list \
231 [list \
232 "Run mbind2a" \
233 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
234 "" \
235 { mbind2a.s mbind2b.c } \
236 "mbind2a" \
237 "pass.out" \
238 "-O2 -I../bfd" \
239 ] \
240 [list \
241 "Run mbind2b" \
242 "-static -Wl,-z,common-page-size=0x4000" \
243 "" \
244 { mbind2a.s mbind2b.c } \
245 "mbind2b" \
246 "pass.out" \
247 "-O2 -I../bfd" \
248 ] \
249 ]
250 }
251
252 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
253 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
254 switch -regexp $target_triplet {
255 ^\[^-\]*-\[^-\]*-gnu.*$ {
256 set xfails "*-*-*"
257 }
258 }
259 run_ld_link_exec_tests $array_tests_static $xfails
260
261 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.045214 seconds and 5 git commands to generate.