| 1 | # Expect script for various ELF tests. |
| 2 | # Copyright (C) 2002-2016 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 { [istarget "*-*-nacl*"] } { |
| 40 | # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64. |
| 41 | # But the target default is ELFCLASS32. So the cases explicitly use |
| 42 | # -melf_x86_64 to select that, but NaCl needs a different emulation name. |
| 43 | set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl} |
| 44 | } |
| 45 | |
| 46 | if { [istarget "*-*-solaris*"] } { |
| 47 | # Same for Solaris |
| 48 | set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2} |
| 49 | } |
| 50 | |
| 51 | if { [is_remote host] } then { |
| 52 | remote_download host merge.ld |
| 53 | } |
| 54 | |
| 55 | if { ![istarget hppa64*-hpux*] } { |
| 56 | run_ld_link_tests { |
| 57 | {"Build symbol3.a" |
| 58 | "" "" "" |
| 59 | {symbol3.s} {} "symbol3.a"} |
| 60 | {"Build symbol3w.a" |
| 61 | "" "" "" |
| 62 | {symbol3w.s} {} "symbol3w.a"} |
| 63 | } |
| 64 | |
| 65 | if { [check_shared_lib_support] } then { |
| 66 | run_ld_link_tests { |
| 67 | {"Build pr14170a.o" "" "" "" "pr14170a.s" {} "pr14170.a" } |
| 68 | } |
| 69 | setup_xfail "tic6x-*-*" |
| 70 | run_ld_link_tests { |
| 71 | {"Build shared library for pr14170" |
| 72 | "-shared" "" "" "pr14170b.s" {} "pr14170.so" } |
| 73 | } |
| 74 | # bfin does not currently support copy relocs. |
| 75 | setup_xfail "bfin-*-*" |
| 76 | run_ld_link_tests { |
| 77 | {"PR ld/14170" |
| 78 | "--no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" "" "pr14170c.s" |
| 79 | { } "pr14170" } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | # Only run these tests on targets that support creating shared libraries. |
| 85 | if { [check_shared_lib_support] } then { |
| 86 | # Run a test to check linking a shared library with a broken linker |
| 87 | # script that accidentally marks dynamic sections as notes. The |
| 88 | # resulting executable is not expected to work, but the linker |
| 89 | # should not seg-fault whilst creating the binary. |
| 90 | setup_xfail "tic6x-*-*" |
| 91 | run_ld_link_tests { |
| 92 | {"Build shared library for next test" |
| 93 | "-shared" "" "" "note-3.s" {} "note-3.so" } |
| 94 | {"Link using broken linker script" |
| 95 | "--script note-3.t tmpdir/note-3.so" "" "" "" |
| 96 | { { ld "note-3.l" } } |
| 97 | "a.out" } |
| 98 | } |
| 99 | setup_xfail "tic6x-*-*" |
| 100 | run_ld_link_tests { |
| 101 | {"Build pr17068.so" |
| 102 | "-shared" "" "" |
| 103 | {pr17068d.s} {} "pr17068.so"} |
| 104 | {"Build pr17068a.a" |
| 105 | "" "" "" |
| 106 | {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"} |
| 107 | {"Build pr17068b.a" |
| 108 | "" "" "" |
| 109 | {pr17068b.s pr17068e.s} {} "pr17068b.a"} |
| 110 | } |
| 111 | # bfin does not currently support copy relocs. |
| 112 | setup_xfail "bfin-*-*" |
| 113 | run_ld_link_tests { |
| 114 | {"pr17068 link --as-needed lib in group" |
| 115 | "--as-needed --no-dynamic-linker" "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a --end-group" "" |
| 116 | {start.s pr17068.s} {} "pr17068"} |
| 117 | } |
| 118 | # xfail on tic6x due to non-PIC/non-PID warnings |
| 119 | setup_xfail "tic6x-*-*" |
| 120 | # Fails on MIPS because ABI trickery means that a NULL reloc is also emitted. |
| 121 | setup_xfail "mips*-*-*" |
| 122 | # Fails on bfin because relocations are not created. |
| 123 | setup_xfail "bfin-*-*" |
| 124 | run_ld_link_tests { |
| 125 | {"-Bsymbolic-functions" |
| 126 | "-shared -Bsymbolic-functions" "" "" |
| 127 | {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}} |
| 128 | "symbolic-func.so"} |
| 129 | } |
| 130 | # xfail on tic6x due to non-PIC/non-PID warnings |
| 131 | setup_xfail "tic6x-*-*" |
| 132 | run_ld_link_tests { |
| 133 | {"Build pr20995.so" |
| 134 | "-shared" "" "" |
| 135 | {pr20995b.s} {} "pr20995.so"} |
| 136 | } |
| 137 | setup_xfail "tic6x-*-*" |
| 138 | run_ld_link_tests { |
| 139 | {"Build pr20995-2.so" |
| 140 | "-shared -z relro" "" "" |
| 141 | {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"} |
| 142 | } |
| 143 | # These targets don't copy dynamic variables into .bss. |
| 144 | setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" |
| 145 | run_ld_link_tests { |
| 146 | {"pr20995" |
| 147 | "" "tmpdir/pr20995.so" "" |
| 148 | {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"} |
| 149 | } |
| 150 | setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" |
| 151 | run_ld_link_tests { |
| 152 | {"pr20995-2" |
| 153 | "" "tmpdir/pr20995-2.so" "" |
| 154 | {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"} |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] |
| 159 | foreach t $test_list { |
| 160 | # We need to strip the ".d", but can leave the dirname. |
| 161 | verbose [file rootname $t] |
| 162 | run_dump_test [file rootname $t] |
| 163 | } |
| 164 | |
| 165 | # Targets using the generic linker backend don't support generating |
| 166 | # an import library. |
| 167 | set xfail_implib "" |
| 168 | if [is_generic_elf] { |
| 169 | set xfail_implib "*-*-*" |
| 170 | } |
| 171 | |
| 172 | # Check that the --out-implib option work correctly. |
| 173 | run_ld_link_tests { |
| 174 | {"Generate empty import library" |
| 175 | "--out-implib=tmpdir/implib.lib" "" |
| 176 | "--defsym NO_GLOBAL=1" |
| 177 | {implib.s} |
| 178 | {{ld empty-implib.out}} |
| 179 | "implib"} |
| 180 | {"Generate import library" |
| 181 | "--out-implib=tmpdir/implib.lib" "" |
| 182 | "" |
| 183 | {implib.s} |
| 184 | {{readelf {-s tmpdir/implib.lib} implib.rd}} |
| 185 | "implib"} |
| 186 | } $xfail_implib |
| 187 | |
| 188 | if { [istarget *-*-linux*] |
| 189 | || [istarget *-*-nacl*] |
| 190 | || [istarget *-*-gnu*] } { |
| 191 | run_ld_link_tests { |
| 192 | {"Weak symbols in dynamic objects 1 (support)" |
| 193 | "-shared" "" "" {weak-dyn-1a.s} |
| 194 | {} |
| 195 | "libweakdyn1a.so"} |
| 196 | {"Weak symbols in dynamic objects 1 (main test)" |
| 197 | "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s} |
| 198 | {{readelf {--relocs --wide} weak-dyn-1.rd}} |
| 199 | "libweakdyn1b.so"} |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | #v850 gas complains about .tbss.var section attributes. |
| 204 | if { [check_gc_sections_available] && ![istarget "v850-*-*"] } { |
| 205 | run_ld_link_tests { |
| 206 | {"--gc-sections on tls variable" |
| 207 | "--gc-section" "" "" {tls_gc.s} {} "tls_gc"} |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | if { [istarget *-*-*linux*] |
| 212 | || [istarget *-*-nacl*] |
| 213 | || [istarget *-*-gnu*] } { |
| 214 | run_ld_link_tests { |
| 215 | {"stack exec" "-z execstack" "" "" {stack.s} |
| 216 | {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"} |
| 217 | {"stack size" "-z stack-size=0x123400" "" "" {stack.s} |
| 218 | {{readelf {-Wl} stack-size.rd}} "stack-size.exe"} |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | set LDFLAGS $old_ldflags |
| 223 | |
| 224 | # The following tests require running the executable generated by ld. |
| 225 | if ![isnative] { |
| 226 | return |
| 227 | } |
| 228 | |
| 229 | if [check_gc_sections_available] { |
| 230 | run_cc_link_tests { |
| 231 | {"PR ld/13195" "-Wl,--gc-sections" "" |
| 232 | {pr13195.c} {} "pr13195"} |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | set array_tests { |
| 237 | {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"} |
| 238 | {"init array" "" "" {init.c} "init" "init.out"} |
| 239 | {"fini array" "" "" {fini.c} "fini" "fini.out"} |
| 240 | {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} |
| 241 | } |
| 242 | set array_tests_pie { |
| 243 | {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" } |
| 244 | {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"} |
| 245 | {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"} |
| 246 | {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"} |
| 247 | {"PIE PR ld/14525" "-pie" "" {pr14525.c} "pr14525" "pr14525.out" "-fPIE"} |
| 248 | } |
| 249 | set array_tests_static { |
| 250 | {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"} |
| 251 | {"static init array" "-static" "" {init.c} "init" "init.out"} |
| 252 | {"static fini array" "-static" "" {fini.c} "fini" "fini.out"} |
| 253 | {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} |
| 254 | } |
| 255 | |
| 256 | # NetBSD ELF systems do not currently support the .*_array sections. |
| 257 | set xfails "*-*-netbsdelf*" |
| 258 | run_ld_link_exec_tests $array_tests $xfails |
| 259 | |
| 260 | if { [istarget *-*-linux*] |
| 261 | || [istarget *-*-nacl*] |
| 262 | || [istarget *-*-gnu*] } { |
| 263 | run_ld_link_exec_tests $array_tests_pie $xfails |
| 264 | } |
| 265 | |
| 266 | # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static> |
| 267 | # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc. |
| 268 | switch -regexp $target_triplet { |
| 269 | ^\[^-\]*-\[^-\]*-gnu.*$ { |
| 270 | set xfails "*-*-*" |
| 271 | } |
| 272 | } |
| 273 | run_ld_link_exec_tests $array_tests_static $xfails |
| 274 | |
| 275 | catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status |