61efc4a140808e6e330f0a1c040b16e4f006521a
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 # Copyright 2002, 2003, 2005, 2007, 2009, 2010 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 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 }
38
39 if { [is_remote host] } then {
40 remote_download host merge.ld
41 }
42
43 run_ld_link_tests {
44 {"Build symbol3.a"
45 "" ""
46 {symbol3.s} {} "symbol3.a"}
47 {"Build symbol3w.a"
48 "" ""
49 {symbol3w.s} {} "symbol3w.a"}
50 }
51
52 # Run a test to check linking a shared library with a broken linker
53 # script that accidentally marks dynamic sections as notes. The
54 # resulting executable is not expected to work, but the linker
55 # should not seg-fault whilst creating the binary.
56 #
57 # Only run the test on targets thats support creating shared libraries.
58 if { ! [istarget arc-*-*]
59 && ! [istarget avr-*-*]
60 && ! [istarget cr16-*-*]
61 && ! [istarget cris*-*-*]
62 && ! [istarget crx-*-*]
63 && ! [istarget d10v-*-*]
64 && ! [istarget d30v-*-*]
65 && ! [istarget dlx-*-*]
66 && ! [istarget fr30-*-*]
67 && ! [istarget frv-*-*]
68 && ! [istarget h8300-*-*]
69 && ! [istarget ip2k-*-*]
70 && ! [istarget m32r-*-*]
71 && ! [istarget mcore*-*-*]
72 && ! [istarget mn10200-*-*]
73 && ! [istarget msp430-*-*]
74 && ! [istarget openrisc-*-*]
75 && ! [istarget or32-*-*]
76 && ! [istarget pj-*-*]
77 && ! [istarget rx-*-*]
78 && ! [istarget v850-*-*]
79 && ! [istarget *-*-irix*]
80 && ! [istarget *-*-rtems] } {
81 run_ld_link_tests {
82 {"Build shared library for next test"
83 "-shared" "" "note-3.s" {} "note-3.so" }
84 {"Link using broken linker script"
85 "--script note-3.t tmpdir/note-3.so" "" ""
86 { { ld "note-3.l" } }
87 "a.out" }
88 }
89 }
90
91 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
92 foreach t $test_list {
93 # We need to strip the ".d", but can leave the dirname.
94 verbose [file rootname $t]
95 run_dump_test [file rootname $t]
96 }
97
98 if { [istarget *-*-linux*]
99 || [istarget *-*-gnu*] } {
100 run_ld_link_tests {
101 {"Weak symbols in dynamic objects 1 (support)"
102 "-shared" "" {weak-dyn-1a.s}
103 {}
104 "libweakdyn1a.so"}
105 {"Weak symbols in dynamic objects 1 (main test)"
106 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" {weak-dyn-1b.s}
107 {{readelf {--relocs --wide} weak-dyn-1.rd}}
108 "libweakdyn1b.so"}
109 }
110 }
111
112 #v850 gas complains about .tbss.var section attributes.
113 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
114 run_ld_link_tests {
115 {"--gc-sections on tls variable"
116 "--gc-section" "" {tls_gc.s} {} "tls_gc"}
117 }
118 }
119
120 set LDFLAGS $old_ldflags
121
122 # The following tests require running the executable generated by ld.
123 if ![isnative] {
124 return
125 }
126
127 set array_tests {
128 {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"}
129 {"init array" "" "" {init.c} "init" "init.out"}
130 {"fini array" "" "" {fini.c} "fini" "fini.out"}
131 {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
132 }
133 set array_tests_pie {
134 {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" }
135 {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"}
136 {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"}
137 {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
138 }
139 set array_tests_static {
140 {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"}
141 {"static init array" "-static" "" {init.c} "init" "init.out"}
142 {"static fini array" "-static" "" {fini.c} "fini" "fini.out"}
143 {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
144 }
145
146 # NetBSD ELF systems do not currently support the .*_array sections.
147 set xfails [list "*-*-netbsdelf*"]
148 run_ld_link_exec_tests $xfails $array_tests
149
150 # Run PIE tests only on Linux.
151 if { [istarget "*-*-linux*"] } {
152 run_ld_link_exec_tests $xfails $array_tests_pie
153 }
154
155 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
156 switch -regexp $target_triplet {
157 ^\[^-\]*-\[^-\]*-gnu.*$ {
158 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
159 lappend xfails "*-*-*"
160 }
161 }
162 run_ld_link_exec_tests $xfails $array_tests_static
163
164 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.032556 seconds and 3 git commands to generate.