Commit | Line | Data |
---|---|---|
782c0ebf | 1 | # Expect script for various ELF tests. |
219d1afa | 2 | # Copyright (C) 2002-2018 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 | } | |
dd803a24 AM |
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 | ||
991cda6c RH |
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 | } | |
9f264ea9 | 47 | |
7cf492ee RM |
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 | ||
5cc51864 L |
55 | if { [istarget "*-*-solaris*"] } { |
56 | # Same for Solaris | |
57 | set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2} | |
58 | } | |
59 | ||
7f6a71ff JM |
60 | if { [is_remote host] } then { |
61 | remote_download host merge.ld | |
62 | } | |
63 | ||
b77db948 NC |
64 | # Note - the output file from the second test (symbol3w.a) is |
65 | # used in the proc is_elf64 test below... | |
dd803a24 AM |
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 | ||
b77db948 | 75 | |
b77db948 NC |
76 | if [is_elf64 tmpdir/symbol3w.a] { |
77 | set ASFLAGS "$ASFLAGS --defsym ALIGN=3" | |
78 | } else { | |
79 | set ASFLAGS "$ASFLAGS --defsym ALIGN=2" | |
80 | } | |
81 | ||
82 | ||
83 | ||
46b06a98 | 84 | # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests |
506981af RL |
85 | run_ld_link_tests { |
86 | {"PR ld/21703" | |
93f4de39 | 87 | "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \ |
506981af | 88 | {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" } |
506981af | 89 | {"PR ld/21703 -r" |
93f4de39 | 90 | "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \ |
506981af | 91 | {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" } |
be570f06 | 92 | } "d30v-*-*" "dlx-*-*" "pj-*-*" "xgate-*-*" |
93f4de39 | 93 | |
bdd32e03 AM |
94 | if [is_underscore_target] { |
95 | set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1" | |
96 | } | |
97 | ||
782c0ebf AM |
98 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] |
99 | foreach t $test_list { | |
100 | # We need to strip the ".d", but can leave the dirname. | |
101 | verbose [file rootname $t] | |
102 | run_dump_test [file rootname $t] | |
103 | } | |
24edc24d | 104 | |
5df1bc57 AM |
105 | # Targets using the generic linker backend don't support generating |
106 | # an import library. | |
107 | set xfail_implib "" | |
b62b1f71 | 108 | if [is_generic_elf] { |
5df1bc57 AM |
109 | set xfail_implib "*-*-*" |
110 | } | |
111 | ||
76359541 | 112 | # Check that the --out-implib option work correctly. |
dd803a24 AM |
113 | run_ld_link_tests [list \ |
114 | [list "Generate empty import library" \ | |
115 | "--out-implib=tmpdir/implib.lib" "" \ | |
116 | [concat "--defsym NO_GLOBAL=1" $hpux] \ | |
117 | {implib.s} \ | |
118 | {{ld empty-implib.out}} \ | |
119 | "implib" ] \ | |
120 | [list "Generate import library" \ | |
121 | "--out-implib=tmpdir/implib.lib" "" \ | |
122 | $hpux \ | |
123 | {implib.s} \ | |
124 | {{readelf {-s tmpdir/implib.lib} implib.rd}} \ | |
125 | "implib" ] \ | |
126 | ] $xfail_implib | |
76359541 | 127 | |
78336cd6 AM |
128 | #v850 gas complains about .tbss.var section attributes. |
129 | if { [check_gc_sections_available] && ![istarget "v850-*-*"] } { | |
430a16a5 NC |
130 | run_ld_link_tests { |
131 | {"--gc-sections on tls variable" | |
897aea50 | 132 | "--gc-section" "" "" {tls_gc.s} {} "tls_gc"} |
430a16a5 NC |
133 | } |
134 | } | |
135 | ||
6b00ac5a | 136 | if { [istarget *-*-*linux*] |
b3adb10f | 137 | || [istarget *-*-nacl*] |
9cc420b6 | 138 | || [istarget *-*-gnu*] } { |
04c3a755 | 139 | run_ld_link_tests { |
897aea50 | 140 | {"stack exec" "-z execstack" "" "" {stack.s} |
04c3a755 | 141 | {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"} |
112ba867 FC |
142 | {"stack noexec" "-z noexecstack" "" "" {stack.s} |
143 | {{readelf {-Wl} stack-noexec.rd}} "stack-noexec.exe"} | |
897aea50 | 144 | {"stack size" "-z stack-size=0x123400" "" "" {stack.s} |
04c3a755 NS |
145 | {{readelf {-Wl} stack-size.rd}} "stack-size.exe"} |
146 | } | |
147 | } | |
148 | ||
e4970690 | 149 | set LDFLAGS $old_ldflags |
dd803a24 | 150 | set ASFLAGS $old_asflags |
e4970690 | 151 | |
4ce6ca2c AM |
152 | # Check to see if the C compiler works |
153 | if { [which $CC] == 0 } { | |
154 | return | |
155 | } | |
156 | ||
a130722b L |
157 | if [check_gc_sections_available] { |
158 | run_cc_link_tests { | |
159 | {"PR ld/13195" "-Wl,--gc-sections" "" | |
160 | {pr13195.c} {} "pr13195"} | |
161 | } | |
54e8959c L |
162 | } |
163 | ||
24edc24d | 164 | set array_tests { |
d9816402 AM |
165 | {"preinit array" "" "" |
166 | {preinit.c} "preinit" "preinit.out"} | |
167 | {"init array" "" "" | |
168 | {init.c} "init" "init.out"} | |
169 | {"fini array" "" "" | |
170 | {fini.c} "fini" "fini.out"} | |
171 | {"init array mixed" "" "" | |
172 | {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} | |
310fd250 L |
173 | } |
174 | set array_tests_pie { | |
d9816402 AM |
175 | {"PIE preinit array" "-pie" "" |
176 | {preinit.c} "preinit" "preinit.out" "-fPIE"} | |
177 | {"PIE init array" "-pie" "" | |
178 | {init.c} "init" "init.out" "-fPIE"} | |
179 | {"PIE fini array" "-pie" "" | |
180 | {fini.c} "fini" "fini.out" "-fPIE"} | |
181 | {"PIE init array mixed" "-pie" "" | |
182 | {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"} | |
183 | {"PIE PR ld/14525" "-pie" "" | |
184 | {pr14525.c} "pr14525" "pr14525.out" "-fPIE"} | |
5940a93c TS |
185 | } |
186 | set array_tests_static { | |
d9816402 AM |
187 | {"static preinit array" "-static" "" |
188 | {preinit.c} "preinit" "preinit.out"} | |
189 | {"static init array" "-static" "" | |
190 | {init.c} "init" "init.out"} | |
191 | {"static fini array" "-static" "" | |
192 | {fini.c} "fini" "fini.out"} | |
193 | {"static init array mixed" "-static" "" | |
194 | {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} | |
24edc24d L |
195 | } |
196 | ||
c8c140d9 | 197 | # NetBSD ELF systems do not currently support the .*_array sections. |
982c6f26 AM |
198 | set xfails "*-*-netbsdelf*" |
199 | run_ld_link_exec_tests $array_tests $xfails | |
310fd250 | 200 | |
3fee20ef | 201 | if { [istarget *-*-linux*] |
5a68afcf | 202 | || [istarget *-*-nacl*] |
3fee20ef | 203 | || [istarget *-*-gnu*] } { |
982c6f26 | 204 | run_ld_link_exec_tests $array_tests_pie $xfails |
a91e1603 L |
205 | |
206 | run_ld_link_exec_tests [list \ | |
207 | [list \ | |
208 | "Run mbind2a" \ | |
209 | "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \ | |
210 | "" \ | |
211 | { mbind2a.s mbind2b.c } \ | |
212 | "mbind2a" \ | |
213 | "pass.out" \ | |
214 | "-O2 -I../bfd" \ | |
215 | ] \ | |
216 | [list \ | |
217 | "Run mbind2b" \ | |
218 | "-static -Wl,-z,common-page-size=0x4000" \ | |
219 | "" \ | |
220 | { mbind2a.s mbind2b.c } \ | |
221 | "mbind2b" \ | |
222 | "pass.out" \ | |
223 | "-O2 -I../bfd" \ | |
224 | ] \ | |
225 | ] | |
310fd250 L |
226 | } |
227 | ||
982c6f26 | 228 | # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static> |
5940a93c TS |
229 | # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc. |
230 | switch -regexp $target_triplet { | |
231 | ^\[^-\]*-\[^-\]*-gnu.*$ { | |
982c6f26 | 232 | set xfails "*-*-*" |
5940a93c TS |
233 | } |
234 | } | |
982c6f26 | 235 | run_ld_link_exec_tests $array_tests_static $xfails |
9ab80182 | 236 | |
02ecc8e9 | 237 | catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status |