Add a test for PR ld/14170
[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, 2012
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 { [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
47 if { [is_remote host] } then {
48     remote_download host merge.ld
49 }
50
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     }
60 }
61
62 # Run a test to check linking a shared library with a broken linker
63 # script that accidentally marks dynamic sections as notes.  The
64 # resulting executable is not expected to work, but the linker
65 # should not seg-fault whilst creating the binary.
66 #
67 # Only run the test on targets thats support creating shared libraries.
68 if { [check_shared_lib_support] } then {
69   run_ld_link_tests {
70       {"Build pr14170a.o" "" "" "pr14170a.s" {} "pr14170.a" }
71       {"Build shared library for pr14170"
72        "-shared" "" "pr14170b.s" {} "pr14170.so" }
73       {"PR ld/14170"
74         "tmpdir/pr14170a.o tmpdir/pr14170.so" "" "pr14170c.s"
75           { } "a.out" }
76   }
77   setup_xfail "tic6x-*-*"
78   run_ld_link_tests {
79       {"Build shared library for next test"
80        "-shared" "" "note-3.s" {} "note-3.so" }
81       {"Link using broken linker script"
82         "--script note-3.t tmpdir/note-3.so" "" ""
83           { { ld "note-3.l" } }
84           "a.out" }
85   }
86 }
87
88 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
89 foreach t $test_list {
90     # We need to strip the ".d", but can leave the dirname.
91     verbose [file rootname $t]
92     run_dump_test [file rootname $t]
93 }
94
95 if { [istarget *-*-linux*]
96      || [istarget *-*-nacl*]
97      || [istarget *-*-gnu*] } {
98     run_ld_link_tests {
99         {"Weak symbols in dynamic objects 1 (support)"
100             "-shared" "" {weak-dyn-1a.s}
101             {}
102             "libweakdyn1a.so"}
103         {"Weak symbols in dynamic objects 1 (main test)"
104             "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" {weak-dyn-1b.s}
105             {{readelf {--relocs --wide} weak-dyn-1.rd}}
106             "libweakdyn1b.so"}
107     }
108 }
109
110 #v850 gas complains about .tbss.var section attributes.
111 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
112     run_ld_link_tests {
113         {"--gc-sections on tls variable"
114             "--gc-section" "" {tls_gc.s} {} "tls_gc"}
115     }
116 }
117
118 set LDFLAGS $old_ldflags
119
120 # The following tests require running the executable generated by ld.
121 if ![isnative] {
122     return
123 }
124
125 if [check_gc_sections_available] {
126     run_cc_link_tests {
127         {"PR ld/13195" "-Wl,--gc-sections" ""
128          {pr13195.c} {} "pr13195"}
129     }
130 }
131
132 set array_tests {
133     {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"}
134     {"init array" "" "" {init.c} "init" "init.out"}
135     {"fini array" "" "" {fini.c} "fini" "fini.out"}
136     {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
137 }
138 set array_tests_pie {
139     {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" }
140     {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"}
141     {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"}
142     {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
143 }
144 set array_tests_static {
145     {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"}
146     {"static init array" "-static" "" {init.c} "init" "init.out"}
147     {"static fini array" "-static" "" {fini.c} "fini" "fini.out"}
148     {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
149 }
150
151 # NetBSD ELF systems do not currently support the .*_array sections.
152 set xfails [list "*-*-netbsdelf*"]
153 run_ld_link_exec_tests $xfails $array_tests
154
155 if { [istarget *-*-linux*]
156      || [istarget *-*-nacl*]
157      || [istarget *-*-gnu*] } {
158     run_ld_link_exec_tests $xfails $array_tests_pie
159 }
160
161 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
162 switch -regexp $target_triplet {
163     ^\[^-\]*-\[^-\]*-gnu.*$ {
164         # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
165         lappend xfails "*-*-*"
166     }
167 }
168 run_ld_link_exec_tests $xfails $array_tests_static
169
170 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status