1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2018 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
22 # Exclude non-ELF targets.
28 set old_ldflags $LDFLAGS
29 if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
33 # hpux .comm differs from everyone else
35 set old_asflags $ASFLAGS
36 if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
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"
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}
55 if { [istarget "*-*-solaris*"] } {
57 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
60 if { [is_remote host] } then {
61 remote_download host merge.ld
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" \
69 {symbol3.s} {} "symbol3.a" ] \
70 [list "Build symbol3w.a" \
72 {symbol3w.s} {} "symbol3w.a" ] \
76 if [is_elf64 tmpdir/symbol3w.a] {
77 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
78 set pr23900_1_exp "pr23900-1-64.rd"
80 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
81 set pr23900_1_exp "pr23900-1-32.rd"
86 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
89 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
90 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
92 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
93 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
94 } "d30v-*-*" "dlx-*-*" "pj-*-*" "xgate-*-*"
96 if [is_underscore_target] {
97 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
101 set saved_ASFLAGS "$ASFLAGS"
102 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
103 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
106 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
107 foreach t $test_list {
108 # We need to strip the ".d", but can leave the dirname.
109 verbose [file rootname $t]
110 run_dump_test [file rootname $t]
113 set ASFLAGS "$saved_ASFLAGS"
115 # Targets using the generic linker backend don't support generating
118 if [is_generic_elf] {
119 set xfail_implib "*-*-*"
122 # Check that the --out-implib option work correctly.
123 run_ld_link_tests [list \
124 [list "Generate empty import library" \
125 "--out-implib=tmpdir/implib.lib" "" \
126 [concat "--defsym NO_GLOBAL=1" $hpux] \
128 {{ld empty-implib.out}} \
130 [list "Generate import library" \
131 "--out-implib=tmpdir/implib.lib" "" \
134 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
138 #v850 gas complains about .tbss.var section attributes.
139 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
141 {"--gc-sections on tls variable"
142 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
146 if { [istarget *-*-*linux*]
147 || [istarget *-*-nacl*]
148 || [istarget *-*-gnu*] } {
149 run_ld_link_tests [list \
155 {{readelf {-Wl} stack-exec.rd}} \
157 [list "stack noexec" \
162 {{readelf {-Wl} stack-noexec.rd}} \
163 "stack-noexec.exe"] \
165 "-z stack-size=0x123400" \
169 {{readelf {-Wl} stack-size.rd}} \
171 [list "PT_GNU_PROPERTY alignment" \
176 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
181 set LDFLAGS $old_ldflags
182 set ASFLAGS $old_asflags
184 # Check to see if the C compiler works
185 if { [which $CC] == 0 } {
189 if [check_gc_sections_available] {
191 {"PR ld/13195" "-Wl,--gc-sections" ""
192 {pr13195.c} {} "pr13195"}
197 {"preinit array" "" ""
198 {preinit.c} "preinit" "preinit.out"}
200 {init.c} "init" "init.out"}
202 {fini.c} "fini" "fini.out"}
203 {"init array mixed" "" ""
204 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
206 set array_tests_pie {
207 {"PIE preinit array" "-pie" ""
208 {preinit.c} "preinit" "preinit.out" "-fPIE"}
209 {"PIE init array" "-pie" ""
210 {init.c} "init" "init.out" "-fPIE"}
211 {"PIE fini array" "-pie" ""
212 {fini.c} "fini" "fini.out" "-fPIE"}
213 {"PIE init array mixed" "-pie" ""
214 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
215 {"PIE PR ld/14525" "-pie" ""
216 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
218 set array_tests_static {
219 {"static preinit array" "-static" ""
220 {preinit.c} "preinit" "preinit.out"}
221 {"static init array" "-static" ""
222 {init.c} "init" "init.out"}
223 {"static fini array" "-static" ""
224 {fini.c} "fini" "fini.out"}
225 {"static init array mixed" "-static" ""
226 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
229 # NetBSD ELF systems do not currently support the .*_array sections.
230 set xfails "*-*-netbsdelf*"
231 run_ld_link_exec_tests $array_tests $xfails
233 if { [istarget *-*-linux*]
234 || [istarget *-*-nacl*]
235 || [istarget *-*-gnu*] } {
236 run_ld_link_exec_tests $array_tests_pie $xfails
238 run_ld_link_exec_tests [list \
241 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
243 { mbind2a.s mbind2b.c } \
250 "-static -Wl,-z,common-page-size=0x4000" \
252 { mbind2a.s mbind2b.c } \
260 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
261 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
262 switch -regexp $target_triplet {
263 ^\[^-\]*-\[^-\]*-gnu.*$ {
267 run_ld_link_exec_tests $array_tests_static $xfails
269 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status