* ld/testsuite/ld-elf/elf.exp: Execute array_tests_pie tests on *-*-gnu*, too.
[external/binutils.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 #   Copyright 2002, 2003, 2005, 2007, 2009, 2010, 2011
3 #   Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21 #
22
23 # Exclude non-ELF targets.
24
25 if ![is_elf_format] {
26     return
27 }
28
29 set old_ldflags $LDFLAGS
30 if { [istarget spu*-*-*] } {
31     set LDFLAGS "$LDFLAGS --local-store 0:0"
32 }
33 if { [istarget alpha*-*-* ] } {
34     # The compress1 test is written expecting 32-bit addresses; force the
35     # executable down into the low address space to match.
36     # ??? How can we adjust just the one testcase?
37     set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000"
38 }
39
40 if { [is_remote host] } then {
41     remote_download host merge.ld
42 }
43
44 if { ![istarget hppa64*-hpux*] } {
45     run_ld_link_tests {
46         {"Build symbol3.a"
47             "" ""
48             {symbol3.s} {} "symbol3.a"}
49         {"Build symbol3w.a"
50             "" ""
51             {symbol3w.s} {} "symbol3w.a"}
52     }
53 }
54
55 # Run a test to check linking a shared library with a broken linker
56 # script that accidentally marks dynamic sections as notes.  The
57 # resulting executable is not expected to work, but the linker
58 # should not seg-fault whilst creating the binary.
59 #
60 # Only run the test on targets thats support creating shared libraries.
61 if {    ! [istarget arc-*-*]
62      && ! [istarget avr-*-*]
63      && ! [istarget cr16-*-*]
64      && ! [istarget cris*-*-*]
65      && ! [istarget crx-*-*]
66      && ! [istarget d10v-*-*]
67      && ! [istarget d30v-*-*]
68      && ! [istarget dlx-*-*]
69      && ! [istarget fr30-*-*]
70      && ! [istarget frv-*-*]
71      && ! [istarget h8300-*-*]
72      && ! [istarget ip2k-*-*]
73      && ! [istarget m32r-*-*]
74      && ! [istarget mcore*-*-*]
75      && ! [istarget mn10200-*-*]
76      && ! [istarget msp430-*-*]
77      && ! [istarget openrisc-*-*]
78      && ! [istarget or32-*-*]
79      && ! [istarget pj-*-*]
80      && ! [istarget rx-*-*]
81      && ! [istarget v850-*-*]
82      && ! [istarget *-*-irix*]
83      && ! [istarget *-*-rtems] } {
84   run_ld_link_tests {
85       {"Build shared library for next test"
86        "-shared" "" "note-3.s" {} "note-3.so" }
87       {"Link using broken linker script"
88         "--script note-3.t tmpdir/note-3.so" "" ""
89           { { ld "note-3.l" } }
90           "a.out" }
91   }
92 }
93
94 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
95 foreach t $test_list {
96     # We need to strip the ".d", but can leave the dirname.
97     verbose [file rootname $t]
98     run_dump_test [file rootname $t]
99 }
100
101 if { [istarget *-*-linux*]
102      || [istarget *-*-gnu*] } {
103     run_ld_link_tests {
104         {"Weak symbols in dynamic objects 1 (support)"
105             "-shared" "" {weak-dyn-1a.s}
106             {}
107             "libweakdyn1a.so"}
108         {"Weak symbols in dynamic objects 1 (main test)"
109             "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" {weak-dyn-1b.s}
110             {{readelf {--relocs --wide} weak-dyn-1.rd}}
111             "libweakdyn1b.so"}
112     }
113 }
114
115 #v850 gas complains about .tbss.var section attributes.
116 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
117     run_ld_link_tests {
118         {"--gc-sections on tls variable"
119             "--gc-section" "" {tls_gc.s} {} "tls_gc"}
120     }
121 }
122
123 set LDFLAGS $old_ldflags
124
125 # The following tests require running the executable generated by ld.
126 if ![isnative] {
127     return
128 }
129
130 set array_tests {
131     {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"}
132     {"init array" "" "" {init.c} "init" "init.out"}
133     {"fini array" "" "" {fini.c} "fini" "fini.out"}
134     {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
135 }
136 set array_tests_pie {
137     {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" }
138     {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"}
139     {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"}
140     {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
141 }
142 set array_tests_static {
143     {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"}
144     {"static init array" "-static" "" {init.c} "init" "init.out"}
145     {"static fini array" "-static" "" {fini.c} "fini" "fini.out"}
146     {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
147 }
148
149 # NetBSD ELF systems do not currently support the .*_array sections.
150 set xfails [list "*-*-netbsdelf*"]
151 run_ld_link_exec_tests $xfails $array_tests
152
153 if { [istarget *-*-linux*]
154      || [istarget *-*-gnu*] } {
155     run_ld_link_exec_tests $xfails $array_tests_pie
156 }
157
158 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
159 switch -regexp $target_triplet {
160     ^\[^-\]*-\[^-\]*-gnu.*$ {
161         # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
162         lappend xfails "*-*-*"
163     }
164 }
165 run_ld_link_exec_tests $xfails $array_tests_static
166
167 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status