| 1 | # Expect script for ld-x86_64 tests |
| 2 | # Copyright (C) 2002, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
| 3 | # Free Software Foundation |
| 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 | # Test x86_64 linking; all types of relocs. This tests the assembler and |
| 24 | # tools like objdump as well as the linker. |
| 25 | |
| 26 | if { !([istarget "x86_64-*-elf*"] |
| 27 | || [istarget "x86_64-*-nacl*"] |
| 28 | || [istarget "x86_64-*-linux*"]) } { |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | if [istarget "*-*-nacl*"] { |
| 33 | set emul "elf_x86_64_nacl" |
| 34 | } else { |
| 35 | set emul "elf_x86_64" |
| 36 | } |
| 37 | |
| 38 | # List contains test-items with 3 items followed by 2 lists: |
| 39 | # 0:name 1:ld options 2:assembler options |
| 40 | # 3:filenames of assembler files 4: action and options. 5: name of output file |
| 41 | |
| 42 | # Actions: |
| 43 | # objdump: Apply objdump options on result. Compare with regex (last arg). |
| 44 | # nm: Apply nm options on result. Compare with regex (last arg). |
| 45 | # readelf: Apply readelf options on result. Compare with regex (last arg). |
| 46 | |
| 47 | set x86_64tests { |
| 48 | {"Helper shared library (basic PLT test)" |
| 49 | "-shared -melf_x86_64" "--64" {pltlib.s} {} "libpltlib.so"} |
| 50 | {"basic PLT generation" |
| 51 | "-melf_x86_64 tmpdir/libpltlib.so" "--64" {plt.s} |
| 52 | {{objdump -drj.plt plt.pd}} "plt"} |
| 53 | {"TLS -fpic -shared transitions" |
| 54 | "-shared -melf_x86_64 --no-ld-generated-unwind-info" |
| 55 | "--64" {tlspic1.s tlspic2.s} |
| 56 | {{readelf -WSsrl tlspic.rd} {objdump -drj.text tlspic.dd} |
| 57 | {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}} |
| 58 | "libtlspic.so"} |
| 59 | {"TLS descriptor -fpic -shared transitions" |
| 60 | "-shared -melf_x86_64 --no-ld-generated-unwind-info" |
| 61 | "--64" {tlsdesc.s tlspic2.s} |
| 62 | {{readelf -WSsrld tlsdesc.rd} {objdump -drj.text tlsdesc.dd} |
| 63 | {objdump "-s -j.got -j.got.plt" tlsdesc.sd} {objdump -sj.tdata tlsdesc.td} |
| 64 | {objdump -drj.plt tlsdesc.pd}} "libtlsdesc.so"} |
| 65 | {"Helper shared library" "-shared -melf_x86_64" |
| 66 | "--64" {tlslib.s} {} "libtlslib.so"} |
| 67 | {"TLS -fpic and -fno-pic exec transitions" |
| 68 | "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info" |
| 69 | "--64" {tlsbinpic.s tlsbin.s} |
| 70 | {{readelf -WSsrl tlsbin.rd} {objdump -drj.text tlsbin.dd} |
| 71 | {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}} |
| 72 | "tlsbin"} |
| 73 | {"TLS descriptor -fpic and -fno-pic exec transitions" |
| 74 | "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info" |
| 75 | "--64" {tlsbindesc.s tlsbin.s} |
| 76 | {{readelf -WSsrl tlsbindesc.rd} {objdump -drj.text tlsbindesc.dd} |
| 77 | {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}} |
| 78 | "tlsbindesc"} |
| 79 | {"TLS with global dynamic and descriptors" |
| 80 | "-shared -melf_x86_64 --no-ld-generated-unwind-info" |
| 81 | "--64" {tlsgdesc.s} |
| 82 | {{readelf -WSsrl tlsgdesc.rd} {objdump -drj.text tlsgdesc.dd}} |
| 83 | "libtlsgdesc.so"} |
| 84 | {"TLS in debug sections" "-melf_x86_64" |
| 85 | "--64" {tlsg.s} |
| 86 | {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"} |
| 87 | {"TLS GD->LE transition" "-melf_x86_64" |
| 88 | "--64" {tlsgd1.s} |
| 89 | {{objdump -dwr tlsgd1.dd}} "tlsgd1"} |
| 90 | {"TLS LD->LE transition" "-melf_x86_64" |
| 91 | "--64" {tlsld1.s} |
| 92 | {{objdump -dwr tlsld1.dd}} "tlsld1"} |
| 93 | {"TLS IE->LE transition" "-melf_x86_64" |
| 94 | "--64" {tlsie1.s} |
| 95 | {{objdump -dwr tlsie1.dd}} "tlsie1"} |
| 96 | {"Helper 64bit object 1" "-r -melf_x86_64" |
| 97 | "--64" {mixed1a.s} {} "libmixe1a.o"} |
| 98 | {"Helper 32bit object 1" "-r -melf_i386" |
| 99 | "--32" {mixed1b.s} {} "libmixe1b.o"} |
| 100 | {"Helper 64bit object 2" "-r -melf_x86_64" |
| 101 | "--64" {mixed2a.s} {} "libmixe2a.o"} |
| 102 | {"Helper 32bit object 2" "-r -melf_i386" |
| 103 | "--32" {mixed2b.s} {} "libmixe2b.o"} |
| 104 | {"Split by file with 'l' flag on section." "-split-by-file -r -melf_x86_64" |
| 105 | "--64" {split-by-file1.s split-by-file2.s} |
| 106 | {{readelf -SW split-by-file.rd}} "split-by-file.o"} |
| 107 | {"TLS X32 IE->LE transition" "-melf32_x86_64" |
| 108 | "--x32" {tlsie4.s} |
| 109 | {{objdump -dwr tlsie4.dd}} "tlsie4"} |
| 110 | {"TLS X32 GD->LE transition" "-melf32_x86_64" |
| 111 | "--x32" {tlsgd4.s} |
| 112 | {{objdump -dwr tlsgd4.dd}} "tlsgd4"} |
| 113 | {"Helper TLS GD->IE transition DSO" "-shared -melf_x86_64" |
| 114 | "--64" {tlsgd5b.s} {} "libtlsgd5.so"} |
| 115 | {"TLS GD->IE transition" "-melf_x86_64 tmpdir/libtlsgd5.so" |
| 116 | "--64" {tlsgd5a.s} |
| 117 | {{objdump -dwr tlsgd5.dd}} "tlsgd5"} |
| 118 | {"Helper TLS X32 GD->IE transition DSO" "-shared -melf32_x86_64" |
| 119 | "--x32" {tlsgd6b.s} {} "libtlsgd6.so"} |
| 120 | {"TLS X32 GD->IE transition" "-melf32_x86_64 tmpdir/libtlsgd6.so" |
| 121 | "--x32" {tlsgd6a.s} |
| 122 | {{objdump -dwr tlsgd6.dd}} "tlsgd6"} |
| 123 | {"TLS X32 LD->LE transition" "-melf32_x86_64" |
| 124 | "--x32" {tlsld2.s} |
| 125 | {{objdump -dwr tlsld2.dd}} "tlsld2"} |
| 126 | |
| 127 | {"build 32-bit object with 33 locals" "-melf_x86_64 -e 0" "--32" {32bit.s} {{ ld incompatible.l }} "dummy" } |
| 128 | {"build 64-bit object" "-melf_x86_64 -e 0 --defsym foo=1" "--64" {64bit.s} {} "dummy" } |
| 129 | {"link mixed objects" "-melf_x86_64 -e 0 tmpdir/32bit.o tmpdir/64bit.o" "" {} { { ld incompatible.l } } "mixed"} |
| 130 | } |
| 131 | |
| 132 | # So as to avoid rewriting every last test case here in a nacl variant, |
| 133 | # we use black magic to massage the generic cases into nacl-variant cases. |
| 134 | if [istarget "*-*-nacl*"] { |
| 135 | set emul elf_x86_64_nacl |
| 136 | |
| 137 | set lhs {elf(32)?_(i386|x86_64)[[:>:]]} |
| 138 | set rhs {&_nacl} |
| 139 | |
| 140 | # Change all the -melf_x86_64 to -melf_x86_64_nacl so linking can succeed. |
| 141 | regsub -all -- $lhs $x86_64tests $rhs x86_64tests |
| 142 | |
| 143 | # Same, applied to all the run_dump_test cases. |
| 144 | set options_regsub(ld) [list $lhs $rhs] |
| 145 | |
| 146 | # The section/segment layout differs too much for the vanilla |
| 147 | # readelf output files to match. So massage the cases so that |
| 148 | # they refer to a foo-nacl.rd file instead of a foo.rd file. |
| 149 | regsub -all -- {([a-z0-9]+)\.rd} $x86_64tests {\1-nacl.rd} x86_64tests |
| 150 | |
| 151 | # Likewise for PLTs. |
| 152 | regsub -all -- {([a-z0-9]+)\.pd} $x86_64tests {\1-nacl.pd} x86_64tests |
| 153 | } else { |
| 154 | set emul elf_x86_64 |
| 155 | } |
| 156 | |
| 157 | run_ld_link_tests $x86_64tests |
| 158 | |
| 159 | global link_output |
| 160 | global ld |
| 161 | |
| 162 | set test_name "Mixed x86_64 and i386 input test 1" |
| 163 | set test mixed1 |
| 164 | if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o tmpdir/${test}b.o"] } { |
| 165 | if [string match "*i386 architecture of input file `tmpdir/${test}b.o' is incompatible with i386:x86-64 output*" $link_output] { |
| 166 | pass "$test_name" |
| 167 | } { |
| 168 | fail "$test_name" |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | set test_name "Mixed x86_64 and i386 input test 2" |
| 173 | set test mixed2 |
| 174 | if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o tmpdir/${test}b.o"] } { |
| 175 | if [string match "*i386 architecture of input file `tmpdir/${test}b.o' is incompatible with i386:x86-64 output*" $link_output] { |
| 176 | pass "$test_name" |
| 177 | } { |
| 178 | fail "$test_name" |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | run_dump_test "abs" |
| 183 | run_dump_test "abs-l1om" |
| 184 | run_dump_test "pcrel8" |
| 185 | run_dump_test "pcrel16" |
| 186 | run_dump_test "tlsgd2" |
| 187 | run_dump_test "tlsgd3" |
| 188 | run_dump_test "tlsie2" |
| 189 | run_dump_test "tlsie3" |
| 190 | run_dump_test "hidden1" |
| 191 | run_dump_test "hidden2" |
| 192 | run_dump_test "hidden3" |
| 193 | run_dump_test "protected1" |
| 194 | run_dump_test "protected2" |
| 195 | run_dump_test "protected2-l1om" |
| 196 | run_dump_test "protected3" |
| 197 | run_dump_test "protected3-l1om" |
| 198 | run_dump_test "protected4" |
| 199 | run_dump_test "protected5" |
| 200 | run_dump_test "tlsle1" |
| 201 | run_dump_test "tlspie1" |
| 202 | run_dump_test "unique1" |
| 203 | run_dump_test "nogot1" |
| 204 | run_dump_test "nogot2" |
| 205 | run_dump_test "discarded1" |
| 206 | run_dump_test "pr12718" |
| 207 | run_dump_test "pr12921" |
| 208 | run_dump_test "pr13947" |
| 209 | |
| 210 | if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} { |
| 211 | return |
| 212 | } |
| 213 | |
| 214 | if ![ld_assemble $as "--x32 $srcdir/$subdir/start.s" tmpdir/startx32.o] { |
| 215 | unresolved "Build ILP32 start.o" |
| 216 | return |
| 217 | } |
| 218 | |
| 219 | if ![ld_assemble $as "--32 $srcdir/$subdir/start.s" tmpdir/start32.o] { |
| 220 | unresolved "Build ia32 start.o" |
| 221 | return |
| 222 | } |
| 223 | |
| 224 | if ![ld_assemble $as "--64 $srcdir/$subdir/start.s" tmpdir/start64.o] { |
| 225 | unresolved "Build LP64 start.o" |
| 226 | return |
| 227 | } |
| 228 | |
| 229 | if ![ld_assemble $as "--x32 $srcdir/$subdir/foo.s" tmpdir/foox32.o] { |
| 230 | unresolved "Build ILP32 foo.o" |
| 231 | return |
| 232 | } |
| 233 | |
| 234 | if ![ld_assemble $as "--32 $srcdir/$subdir/foo.s" tmpdir/foo32.o] { |
| 235 | unresolved "Build ia32 foo.o" |
| 236 | return |
| 237 | } |
| 238 | |
| 239 | if ![ld_assemble $as "--64 $srcdir/$subdir/foo.s" tmpdir/foo64.o] { |
| 240 | unresolved "Build LP64 foo.o" |
| 241 | return |
| 242 | } |
| 243 | |
| 244 | run_dump_test "compressed1" |
| 245 | run_dump_test "ilp32-1" |
| 246 | run_dump_test "ilp32-2" |
| 247 | run_dump_test "ilp32-3" |
| 248 | run_dump_test "ilp32-4" |
| 249 | run_dump_test "ilp32-4-nacl" |
| 250 | run_dump_test "ilp32-5" |
| 251 | run_dump_test "ilp32-6" |
| 252 | run_dump_test "ilp32-7" |
| 253 | run_dump_test "ilp32-8" |
| 254 | run_dump_test "ilp32-9" |
| 255 | run_dump_test "ilp32-10" |
| 256 | run_dump_test "ilp32-11" |
| 257 | run_dump_test "ia32-1" |
| 258 | run_dump_test "ia32-2" |
| 259 | run_dump_test "ia32-3" |
| 260 | run_dump_test "lp64-1" |
| 261 | run_dump_test "lp64-2" |
| 262 | run_dump_test "lp64-3" |
| 263 | run_dump_test "pr13082-1a" |
| 264 | run_dump_test "pr13082-1b" |
| 265 | run_dump_test "pr13082-2a" |
| 266 | run_dump_test "pr13082-2b" |
| 267 | run_dump_test "pr13082-3a" |
| 268 | run_dump_test "pr13082-3b" |
| 269 | run_dump_test "pr13082-4a" |
| 270 | run_dump_test "pr13082-4b" |
| 271 | run_dump_test "pr13082-5a" |
| 272 | run_dump_test "pr13082-5b" |
| 273 | run_dump_test "pr13082-6a" |
| 274 | run_dump_test "pr13082-6b" |
| 275 | |
| 276 | # Must be native with the C compiler |
| 277 | if { [isnative] && [which $CC] != 0 } { |
| 278 | run_cc_link_tests { |
| 279 | {"Helper X32 DSO from x86-64 object" "" "-m64 -fPIC -g" |
| 280 | {simple.c} {} "libsimple.a"} |
| 281 | } |
| 282 | |
| 283 | set convertx32 "$objcopy -O elf32-x86-64 tmpdir/simple.o tmpdir/simple-x32.o" |
| 284 | send_log "$convertx32\n" |
| 285 | set got [remote_exec host "$convertx32"] |
| 286 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 287 | send_log "$got\n" |
| 288 | fail "Convert x86-64 object to x32" |
| 289 | return |
| 290 | } |
| 291 | |
| 292 | run_ld_link_tests { |
| 293 | {"X32 DSO from x86-64 object" |
| 294 | "-shared -melf32_x86_64 tmpdir/simple-x32.o" "--x32" |
| 295 | {dummy.s} {{readelf {-s --wide} x86-64-x32.rd}} "x86-64-x32"} |
| 296 | } |
| 297 | } |