Commit | Line | Data |
---|---|---|
782c0ebf | 1 | # Expect script for various ELF tests. |
6f2750fe | 2 | # Copyright (C) 2002-2016 Free Software Foundation, Inc. |
b7b0b729 | 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 | |
b7b0b729 | 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 |
b7b0b729 HPN |
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 | |
f96b4a7b NC |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | # MA 02110-1301, USA. | |
b7b0b729 | 20 | # |
b7b0b729 HPN |
21 | |
22 | # Exclude non-ELF targets. | |
23 | ||
43f9d75b | 24 | if ![is_elf_format] { |
b7b0b729 HPN |
25 | return |
26 | } | |
27 | ||
e4970690 | 28 | set old_ldflags $LDFLAGS |
9f264ea9 AM |
29 | if { [istarget spu*-*-*] } { |
30 | set LDFLAGS "$LDFLAGS --local-store 0:0" | |
31 | } | |
991cda6c RH |
32 | if { [istarget alpha*-*-* ] } { |
33 | # The compress1 test is written expecting 32-bit addresses; force the | |
34 | # executable down into the low address space to match. | |
35 | # ??? How can we adjust just the one testcase? | |
36 | set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000" | |
37 | } | |
9f264ea9 | 38 | |
7cf492ee RM |
39 | if { [istarget "*-*-nacl*"] } { |
40 | # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64. | |
41 | # But the target default is ELFCLASS32. So the cases explicitly use | |
42 | # -melf_x86_64 to select that, but NaCl needs a different emulation name. | |
43 | set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl} | |
44 | } | |
45 | ||
5cc51864 L |
46 | if { [istarget "*-*-solaris*"] } { |
47 | # Same for Solaris | |
48 | set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2} | |
49 | } | |
50 | ||
7f6a71ff JM |
51 | if { [is_remote host] } then { |
52 | remote_download host merge.ld | |
53 | } | |
54 | ||
5daeae9b AM |
55 | if { ![istarget hppa64*-hpux*] } { |
56 | run_ld_link_tests { | |
57 | {"Build symbol3.a" | |
897aea50 | 58 | "" "" "" |
5daeae9b AM |
59 | {symbol3.s} {} "symbol3.a"} |
60 | {"Build symbol3w.a" | |
897aea50 | 61 | "" "" "" |
5daeae9b AM |
62 | {symbol3w.s} {} "symbol3w.a"} |
63 | } | |
e54e67a9 AM |
64 | |
65 | if { [check_shared_lib_support] } then { | |
66 | run_ld_link_tests { | |
897aea50 | 67 | {"Build pr14170a.o" "" "" "" "pr14170a.s" {} "pr14170.a" } |
e54e67a9 AM |
68 | } |
69 | setup_xfail "tic6x-*-*" | |
70 | run_ld_link_tests { | |
71 | {"Build shared library for pr14170" | |
897aea50 | 72 | "-shared" "" "" "pr14170b.s" {} "pr14170.so" } |
1b857aee NC |
73 | } |
74 | # bfin does not currently support copy relocs. | |
75 | setup_xfail "bfin-*-*" | |
76 | run_ld_link_tests { | |
e54e67a9 | 77 | {"PR ld/14170" |
1a9ccd70 | 78 | "--no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" "" "pr14170c.s" |
e54e67a9 AM |
79 | { } "pr14170" } |
80 | } | |
81 | } | |
83c5d36f L |
82 | } |
83 | ||
a496fbc8 | 84 | # Only run these tests on targets that support creating shared libraries. |
1d5316ab | 85 | if { [check_shared_lib_support] } then { |
d215621e AM |
86 | # Run a test to check linking a shared library with a broken linker |
87 | # script that accidentally marks dynamic sections as notes. The | |
88 | # resulting executable is not expected to work, but the linker | |
89 | # should not seg-fault whilst creating the binary. | |
e54e67a9 AM |
90 | setup_xfail "tic6x-*-*" |
91 | run_ld_link_tests { | |
92 | {"Build shared library for next test" | |
897aea50 | 93 | "-shared" "" "" "note-3.s" {} "note-3.so" } |
e54e67a9 | 94 | {"Link using broken linker script" |
897aea50 | 95 | "--script note-3.t tmpdir/note-3.so" "" "" "" |
e54e67a9 AM |
96 | { { ld "note-3.l" } } |
97 | "a.out" } | |
98 | } | |
d215621e AM |
99 | setup_xfail "tic6x-*-*" |
100 | run_ld_link_tests { | |
101 | {"Build pr17068.so" | |
102 | "-shared" "" "" | |
103 | {pr17068d.s} {} "pr17068.so"} | |
104 | {"Build pr17068a.a" | |
105 | "" "" "" | |
106 | {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"} | |
107 | {"Build pr17068b.a" | |
108 | "" "" "" | |
109 | {pr17068b.s pr17068e.s} {} "pr17068b.a"} | |
1b857aee NC |
110 | } |
111 | # bfin does not currently support copy relocs. | |
112 | setup_xfail "bfin-*-*" | |
113 | run_ld_link_tests { | |
d215621e | 114 | {"pr17068 link --as-needed lib in group" |
1a9ccd70 | 115 | "--as-needed --no-dynamic-linker" "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a --end-group" "" |
d215621e AM |
116 | {start.s pr17068.s} {} "pr17068"} |
117 | } | |
a496fbc8 AM |
118 | # xfail on tic6x due to non-PIC/non-PID warnings |
119 | setup_xfail "tic6x-*-*" | |
84054199 NC |
120 | # Fails on MIPS because ABI trickery means that a NULL reloc is also emitted. |
121 | setup_xfail "mips*-*-*" | |
1b857aee NC |
122 | # Fails on bfin because relocations are not created. |
123 | setup_xfail "bfin-*-*" | |
a496fbc8 AM |
124 | run_ld_link_tests { |
125 | {"-Bsymbolic-functions" | |
126 | "-shared -Bsymbolic-functions" "" "" | |
127 | {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}} | |
128 | "symbolic-func.so"} | |
129 | } | |
894891db NC |
130 | } |
131 | ||
782c0ebf AM |
132 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] |
133 | foreach t $test_list { | |
134 | # We need to strip the ".d", but can leave the dirname. | |
135 | verbose [file rootname $t] | |
136 | run_dump_test [file rootname $t] | |
137 | } | |
24edc24d | 138 | |
5df1bc57 AM |
139 | # Targets using the generic linker backend don't support generating |
140 | # an import library. | |
141 | set xfail_implib "" | |
b62b1f71 | 142 | if [is_generic_elf] { |
5df1bc57 AM |
143 | set xfail_implib "*-*-*" |
144 | } | |
145 | ||
76359541 TP |
146 | # Check that the --out-implib option work correctly. |
147 | run_ld_link_tests { | |
148 | {"Generate empty import library" | |
5df1bc57 AM |
149 | "--out-implib=tmpdir/implib.lib" "" |
150 | "--defsym NO_GLOBAL=1" | |
151 | {implib.s} | |
152 | {{ld empty-implib.out}} | |
153 | "implib"} | |
76359541 | 154 | {"Generate import library" |
5df1bc57 AM |
155 | "--out-implib=tmpdir/implib.lib" "" |
156 | "" | |
157 | {implib.s} | |
158 | {{readelf {-s tmpdir/implib.lib} implib.rd}} | |
159 | "implib"} | |
160 | } $xfail_implib | |
76359541 | 161 | |
5940a93c | 162 | if { [istarget *-*-linux*] |
5a68afcf | 163 | || [istarget *-*-nacl*] |
5940a93c | 164 | || [istarget *-*-gnu*] } { |
a26587ba RS |
165 | run_ld_link_tests { |
166 | {"Weak symbols in dynamic objects 1 (support)" | |
897aea50 | 167 | "-shared" "" "" {weak-dyn-1a.s} |
a26587ba RS |
168 | {} |
169 | "libweakdyn1a.so"} | |
170 | {"Weak symbols in dynamic objects 1 (main test)" | |
897aea50 | 171 | "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s} |
a26587ba RS |
172 | {{readelf {--relocs --wide} weak-dyn-1.rd}} |
173 | "libweakdyn1b.so"} | |
174 | } | |
175 | } | |
176 | ||
78336cd6 AM |
177 | #v850 gas complains about .tbss.var section attributes. |
178 | if { [check_gc_sections_available] && ![istarget "v850-*-*"] } { | |
430a16a5 NC |
179 | run_ld_link_tests { |
180 | {"--gc-sections on tls variable" | |
897aea50 | 181 | "--gc-section" "" "" {tls_gc.s} {} "tls_gc"} |
430a16a5 NC |
182 | } |
183 | } | |
184 | ||
6b00ac5a | 185 | if { [istarget *-*-*linux*] |
b3adb10f | 186 | || [istarget *-*-nacl*] |
9cc420b6 | 187 | || [istarget *-*-gnu*] } { |
04c3a755 | 188 | run_ld_link_tests { |
897aea50 | 189 | {"stack exec" "-z execstack" "" "" {stack.s} |
04c3a755 | 190 | {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"} |
897aea50 | 191 | {"stack size" "-z stack-size=0x123400" "" "" {stack.s} |
04c3a755 NS |
192 | {{readelf {-Wl} stack-size.rd}} "stack-size.exe"} |
193 | } | |
194 | } | |
195 | ||
e4970690 AM |
196 | set LDFLAGS $old_ldflags |
197 | ||
24edc24d L |
198 | # The following tests require running the executable generated by ld. |
199 | if ![isnative] { | |
200 | return | |
201 | } | |
202 | ||
a130722b L |
203 | if [check_gc_sections_available] { |
204 | run_cc_link_tests { | |
205 | {"PR ld/13195" "-Wl,--gc-sections" "" | |
206 | {pr13195.c} {} "pr13195"} | |
207 | } | |
54e8959c L |
208 | } |
209 | ||
24edc24d L |
210 | set array_tests { |
211 | {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"} | |
24edc24d | 212 | {"init array" "" "" {init.c} "init" "init.out"} |
24edc24d | 213 | {"fini array" "" "" {fini.c} "fini" "fini.out"} |
02ecc8e9 | 214 | {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} |
310fd250 L |
215 | } |
216 | set array_tests_pie { | |
217 | {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" } | |
218 | {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"} | |
219 | {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"} | |
220 | {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"} | |
11cba4ac | 221 | {"PIE PR ld/14525" "-pie" "" {pr14525.c} "pr14525" "pr14525.out" "-fPIE"} |
5940a93c TS |
222 | } |
223 | set array_tests_static { | |
224 | {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"} | |
225 | {"static init array" "-static" "" {init.c} "init" "init.out"} | |
24edc24d | 226 | {"static fini array" "-static" "" {fini.c} "fini" "fini.out"} |
310fd250 | 227 | {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} |
24edc24d L |
228 | } |
229 | ||
c8c140d9 | 230 | # NetBSD ELF systems do not currently support the .*_array sections. |
982c6f26 AM |
231 | set xfails "*-*-netbsdelf*" |
232 | run_ld_link_exec_tests $array_tests $xfails | |
310fd250 | 233 | |
3fee20ef | 234 | if { [istarget *-*-linux*] |
5a68afcf | 235 | || [istarget *-*-nacl*] |
3fee20ef | 236 | || [istarget *-*-gnu*] } { |
982c6f26 | 237 | run_ld_link_exec_tests $array_tests_pie $xfails |
310fd250 L |
238 | } |
239 | ||
982c6f26 | 240 | # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static> |
5940a93c TS |
241 | # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc. |
242 | switch -regexp $target_triplet { | |
243 | ^\[^-\]*-\[^-\]*-gnu.*$ { | |
982c6f26 | 244 | set xfails "*-*-*" |
5940a93c TS |
245 | } |
246 | } | |
982c6f26 | 247 | run_ld_link_exec_tests $array_tests_static $xfails |
9ab80182 | 248 | |
02ecc8e9 | 249 | catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status |