Commit | Line | Data |
---|---|---|
782c0ebf | 1 | # Expect script for various ELF tests. |
5a68afcf | 2 | # Copyright 2002, 2003, 2005, 2007, 2009, 2010, 2011, 2012 |
5daeae9b | 3 | # Free Software Foundation, Inc. |
b7b0b729 | 4 | # |
f96b4a7b NC |
5 | # This file is part of the GNU Binutils. |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
b7b0b729 | 8 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 9 | # the Free Software Foundation; either version 3 of the License, or |
b7b0b729 HPN |
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 | |
f96b4a7b NC |
19 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | # MA 02110-1301, USA. | |
b7b0b729 | 21 | # |
b7b0b729 HPN |
22 | |
23 | # Exclude non-ELF targets. | |
24 | ||
43f9d75b | 25 | if ![is_elf_format] { |
b7b0b729 HPN |
26 | return |
27 | } | |
28 | ||
e4970690 | 29 | set old_ldflags $LDFLAGS |
9f264ea9 AM |
30 | if { [istarget spu*-*-*] } { |
31 | set LDFLAGS "$LDFLAGS --local-store 0:0" | |
32 | } | |
991cda6c RH |
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 | } | |
9f264ea9 | 39 | |
7cf492ee RM |
40 | if { [istarget "*-*-nacl*"] } { |
41 | # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64. | |
42 | # But the target default is ELFCLASS32. So the cases explicitly use | |
43 | # -melf_x86_64 to select that, but NaCl needs a different emulation name. | |
44 | set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl} | |
45 | } | |
46 | ||
7f6a71ff JM |
47 | if { [is_remote host] } then { |
48 | remote_download host merge.ld | |
49 | } | |
50 | ||
5daeae9b AM |
51 | if { ![istarget hppa64*-hpux*] } { |
52 | run_ld_link_tests { | |
53 | {"Build symbol3.a" | |
54 | "" "" | |
55 | {symbol3.s} {} "symbol3.a"} | |
56 | {"Build symbol3w.a" | |
57 | "" "" | |
58 | {symbol3w.s} {} "symbol3w.a"} | |
59 | } | |
e54e67a9 AM |
60 | |
61 | if { [check_shared_lib_support] } then { | |
62 | run_ld_link_tests { | |
63 | {"Build pr14170a.o" "" "" "pr14170a.s" {} "pr14170.a" } | |
64 | } | |
65 | setup_xfail "tic6x-*-*" | |
66 | run_ld_link_tests { | |
67 | {"Build shared library for pr14170" | |
68 | "-shared" "" "pr14170b.s" {} "pr14170.so" } | |
69 | {"PR ld/14170" | |
70 | "tmpdir/pr14170a.o tmpdir/pr14170.so" "" "pr14170c.s" | |
71 | { } "pr14170" } | |
72 | } | |
73 | } | |
83c5d36f L |
74 | } |
75 | ||
894891db NC |
76 | # Run a test to check linking a shared library with a broken linker |
77 | # script that accidentally marks dynamic sections as notes. The | |
78 | # resulting executable is not expected to work, but the linker | |
79 | # should not seg-fault whilst creating the binary. | |
80 | # | |
81 | # Only run the test on targets thats support creating shared libraries. | |
1d5316ab | 82 | if { [check_shared_lib_support] } then { |
e54e67a9 AM |
83 | setup_xfail "tic6x-*-*" |
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 | } | |
894891db NC |
92 | } |
93 | ||
782c0ebf AM |
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 | } | |
24edc24d | 100 | |
5940a93c | 101 | if { [istarget *-*-linux*] |
5a68afcf | 102 | || [istarget *-*-nacl*] |
5940a93c | 103 | || [istarget *-*-gnu*] } { |
a26587ba RS |
104 | run_ld_link_tests { |
105 | {"Weak symbols in dynamic objects 1 (support)" | |
106 | "-shared" "" {weak-dyn-1a.s} | |
107 | {} | |
108 | "libweakdyn1a.so"} | |
109 | {"Weak symbols in dynamic objects 1 (main test)" | |
110 | "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" {weak-dyn-1b.s} | |
111 | {{readelf {--relocs --wide} weak-dyn-1.rd}} | |
112 | "libweakdyn1b.so"} | |
113 | } | |
114 | } | |
115 | ||
78336cd6 AM |
116 | #v850 gas complains about .tbss.var section attributes. |
117 | if { [check_gc_sections_available] && ![istarget "v850-*-*"] } { | |
430a16a5 NC |
118 | run_ld_link_tests { |
119 | {"--gc-sections on tls variable" | |
120 | "--gc-section" "" {tls_gc.s} {} "tls_gc"} | |
121 | } | |
122 | } | |
123 | ||
e4970690 AM |
124 | set LDFLAGS $old_ldflags |
125 | ||
24edc24d L |
126 | # The following tests require running the executable generated by ld. |
127 | if ![isnative] { | |
128 | return | |
129 | } | |
130 | ||
a130722b L |
131 | if [check_gc_sections_available] { |
132 | run_cc_link_tests { | |
133 | {"PR ld/13195" "-Wl,--gc-sections" "" | |
134 | {pr13195.c} {} "pr13195"} | |
135 | } | |
54e8959c L |
136 | } |
137 | ||
24edc24d L |
138 | set array_tests { |
139 | {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"} | |
24edc24d | 140 | {"init array" "" "" {init.c} "init" "init.out"} |
24edc24d | 141 | {"fini array" "" "" {fini.c} "fini" "fini.out"} |
02ecc8e9 | 142 | {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} |
310fd250 L |
143 | } |
144 | set array_tests_pie { | |
145 | {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" } | |
146 | {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"} | |
147 | {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"} | |
148 | {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"} | |
5940a93c TS |
149 | } |
150 | set array_tests_static { | |
151 | {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"} | |
152 | {"static init array" "-static" "" {init.c} "init" "init.out"} | |
24edc24d | 153 | {"static fini array" "-static" "" {fini.c} "fini" "fini.out"} |
310fd250 | 154 | {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} |
24edc24d L |
155 | } |
156 | ||
c8c140d9 | 157 | # NetBSD ELF systems do not currently support the .*_array sections. |
5940a93c TS |
158 | set xfails [list "*-*-netbsdelf*"] |
159 | run_ld_link_exec_tests $xfails $array_tests | |
310fd250 | 160 | |
3fee20ef | 161 | if { [istarget *-*-linux*] |
5a68afcf | 162 | || [istarget *-*-nacl*] |
3fee20ef | 163 | || [istarget *-*-gnu*] } { |
310fd250 L |
164 | run_ld_link_exec_tests $xfails $array_tests_pie |
165 | } | |
166 | ||
5940a93c TS |
167 | # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc. |
168 | switch -regexp $target_triplet { | |
169 | ^\[^-\]*-\[^-\]*-gnu.*$ { | |
43fbacde | 170 | # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static> |
5940a93c TS |
171 | lappend xfails "*-*-*" |
172 | } | |
173 | } | |
174 | run_ld_link_exec_tests $xfails $array_tests_static | |
9ab80182 | 175 | |
02ecc8e9 | 176 | catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status |