| 1 | # Expect script for various ELF tests. |
| 2 | # Copyright (C) 2006-2018 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 | # Skip targets where -shared is not supported |
| 29 | |
| 30 | if ![check_shared_lib_support] { |
| 31 | return |
| 32 | } |
| 33 | |
| 34 | # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required. |
| 35 | global NOPIE_CFLAGS NOPIE_LDFLAGS |
| 36 | |
| 37 | set old_ASFLAGS $ASFLAGS |
| 38 | |
| 39 | # This target requires extra GAS options when building code for shared |
| 40 | # libraries. |
| 41 | set AFLAGS_PIC "" |
| 42 | if [istarget "tic6x-*-*"] { |
| 43 | append AFLAGS_PIC " -mpic -mpid=near" |
| 44 | } |
| 45 | if [istarget "sparc*-*-*"] { |
| 46 | append AFLAGS_PIC " -K PIC" |
| 47 | } |
| 48 | |
| 49 | # This target requires a non-default emulation for successful shared |
| 50 | # library/executable builds. |
| 51 | set LFLAGS "" |
| 52 | if [istarget "tic6x-*-*"] { |
| 53 | append LFLAGS " -melf32_tic6x_le" |
| 54 | } |
| 55 | |
| 56 | if [is_underscore_target] { |
| 57 | set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1" |
| 58 | } |
| 59 | |
| 60 | run_ld_link_tests [list \ |
| 61 | [list \ |
| 62 | "Build pr22471a.so" \ |
| 63 | "$LFLAGS -shared" \ |
| 64 | "" \ |
| 65 | "$AFLAGS_PIC" \ |
| 66 | {pr22471a.s} \ |
| 67 | {} \ |
| 68 | "pr22471a.so" \ |
| 69 | ] \ |
| 70 | [list \ |
| 71 | "Build pr22471b.so" \ |
| 72 | "$LFLAGS -shared --version-script pr22471.t" \ |
| 73 | "tmpdir/pr22471a.so" \ |
| 74 | "$AFLAGS_PIC" \ |
| 75 | {pr22471a.s} \ |
| 76 | {} \ |
| 77 | "pr22471b.so" \ |
| 78 | ] \ |
| 79 | [list \ |
| 80 | "Build pr22471" \ |
| 81 | "$LFLAGS -rpath-link ." \ |
| 82 | "tmpdir/pr22471b.so" \ |
| 83 | "" \ |
| 84 | {pr22471b.s} \ |
| 85 | {} \ |
| 86 | "pr22471" \ |
| 87 | ] \ |
| 88 | [list \ |
| 89 | "Build pr22649-1.so" \ |
| 90 | "$LFLAGS -shared" \ |
| 91 | "" \ |
| 92 | "$AFLAGS_PIC" \ |
| 93 | {pr22649-1.s} \ |
| 94 | {} \ |
| 95 | "pr22649-1.so" \ |
| 96 | ] \ |
| 97 | ] |
| 98 | |
| 99 | if { [check_gc_sections_available] } { |
| 100 | run_ld_link_tests [list \ |
| 101 | [list \ |
| 102 | "Build pr22649-2a.so" \ |
| 103 | "$LFLAGS -shared -gc-sections -print-gc-sections" \ |
| 104 | "" \ |
| 105 | "$AFLAGS_PIC" \ |
| 106 | {pr22649-2a.s} \ |
| 107 | {{ld pr22649.msg}} \ |
| 108 | "pr22649-2a.so" \ |
| 109 | ] \ |
| 110 | [list \ |
| 111 | "Build pr22649-2b.so" \ |
| 112 | "$LFLAGS -shared -gc-sections -print-gc-sections" \ |
| 113 | "tmpdir/pr22649-1.so" \ |
| 114 | "$AFLAGS_PIC" \ |
| 115 | {pr22649-2a.s} \ |
| 116 | {{ld pr22649.msg}} \ |
| 117 | "pr22649-2b.so" \ |
| 118 | ] \ |
| 119 | [list \ |
| 120 | "Build pr22649-2c.so" \ |
| 121 | "$LFLAGS -shared -gc-sections -print-gc-sections" \ |
| 122 | "" \ |
| 123 | "$AFLAGS_PIC" \ |
| 124 | {pr22649-2b.s} \ |
| 125 | {} \ |
| 126 | "pr22649-2b.so" \ |
| 127 | ] \ |
| 128 | [list \ |
| 129 | "Build pr22649-2d.so" \ |
| 130 | "$LFLAGS -shared -gc-sections -print-gc-sections" \ |
| 131 | "tmpdir/pr22649-1.so" \ |
| 132 | "$AFLAGS_PIC" \ |
| 133 | {pr22649-2b.s} \ |
| 134 | {} \ |
| 135 | "pr22649-2b.so" \ |
| 136 | ] \ |
| 137 | ] |
| 138 | } |
| 139 | |
| 140 | run_ld_link_tests [list \ |
| 141 | [list \ |
| 142 | "DT_TEXTREL in shared lib" \ |
| 143 | "$LFLAGS -shared --warn-shared-textrel" \ |
| 144 | "" \ |
| 145 | "$AFLAGS_PIC" \ |
| 146 | {textrel.s} \ |
| 147 | {{ld textrel.warn} \ |
| 148 | {readelf {-d --wide} textrel.rd}} \ |
| 149 | "textrel.so" \ |
| 150 | ] \ |
| 151 | ] "xtensa-*-*" |
| 152 | |
| 153 | run_ld_link_tests [list \ |
| 154 | [list \ |
| 155 | "DT_TEXTREL map file warning" \ |
| 156 | "$LFLAGS -shared -M" \ |
| 157 | "" \ |
| 158 | "$AFLAGS_PIC" \ |
| 159 | {textrel.s} \ |
| 160 | {{ld textrel.map}} \ |
| 161 | "textrel.so" \ |
| 162 | ] \ |
| 163 | ] "cris*-*-*" |
| 164 | |
| 165 | # PR ld/20828 check for correct dynamic symbol table entries where: |
| 166 | # - symbols have been defined with a linker script, |
| 167 | # - the same symbols have been seen in shared library used in the link, |
| 168 | # - the shared library symbols have been swept in section garbage collection. |
| 169 | # Verify that the symbols are global rather than local and that a version |
| 170 | # script adjusts them accordingly. |
| 171 | # Also verify that a version definition supplied by an object rather than |
| 172 | # a version script and forcibly exported is unaffected by section GC. |
| 173 | if { [check_gc_sections_available] } { |
| 174 | run_ld_link_tests [list \ |
| 175 | [list \ |
| 176 | "PR ld/20828 dynamic symbols with section GC\ |
| 177 | (auxiliary shared library)" \ |
| 178 | "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \ |
| 179 | {pr20828.s} \ |
| 180 | {{readelf --dyn-syms pr20828-a.sd} \ |
| 181 | {readelf --dyn-syms pr20828-b.sd}} \ |
| 182 | "libpr20828.so"] \ |
| 183 | [list \ |
| 184 | "PR ld/20828 dynamic symbols with section GC (plain)" \ |
| 185 | "$LFLAGS -shared --gc-sections -T pr20828.ld" \ |
| 186 | "tmpdir/libpr20828.so" "$AFLAGS_PIC" \ |
| 187 | {pr20828.s} \ |
| 188 | {{readelf --dyn-syms pr20828-a.sd} \ |
| 189 | {readelf --dyn-syms pr20828-b.sd}} \ |
| 190 | "pr20828-1.so"] \ |
| 191 | [list \ |
| 192 | "PR ld/20828 dynamic symbols with section GC (version script)" \ |
| 193 | "$LFLAGS -shared --gc-sections -T pr20828.ld\ |
| 194 | --version-script=pr20828.ver" \ |
| 195 | "tmpdir/libpr20828.so" \ |
| 196 | "$AFLAGS_PIC" \ |
| 197 | {pr20828.s} \ |
| 198 | {{readelf --dyn-syms pr20828-b.sd} \ |
| 199 | {readelf --dyn-syms pr20828-c.sd}} \ |
| 200 | "pr20828-2.so"] \ |
| 201 | [list \ |
| 202 | "PR ld/20828 dynamic symbols with section GC\ |
| 203 | (versioned shared library)" \ |
| 204 | "$LFLAGS -shared --gc-sections -T pr20828.ld\ |
| 205 | --version-script=pr20828-v.ver" \ |
| 206 | "" "$AFLAGS_PIC" \ |
| 207 | {pr20828.s} \ |
| 208 | {{readelf --dyn-syms pr20828-c.sd} \ |
| 209 | {readelf --dyn-syms pr20828-d.sd} \ |
| 210 | {readelf --dyn-syms pr20828-e.sd}} \ |
| 211 | "libpr20828-v.so"] \ |
| 212 | [list \ |
| 213 | "PR ld/20828 dynamic symbols with section GC (versioned)" \ |
| 214 | "$LFLAGS -shared --gc-sections -T pr20828.ld\ |
| 215 | --version-script=pr20828-v.ver" \ |
| 216 | "tmpdir/libpr20828-v.so" \ |
| 217 | "$AFLAGS_PIC" \ |
| 218 | {pr20828.s} \ |
| 219 | {{readelf --dyn-syms pr20828-c.sd} \ |
| 220 | {readelf --dyn-syms pr20828-d.sd} \ |
| 221 | {readelf --dyn-syms pr20828-e.sd}} \ |
| 222 | "pr20828-v.so"] \ |
| 223 | [list \ |
| 224 | "PR ld/20828 forcibly exported symbol version without section GC" \ |
| 225 | "$LFLAGS --no-dynamic-linker -e foo -E -T pr20828-v.ld" "" "" \ |
| 226 | {pr20828-v.s} \ |
| 227 | {{objdump -p pr20828-v.od}} \ |
| 228 | "pr20828-v-1"] \ |
| 229 | [list \ |
| 230 | "PR ld/20828 forcibly exported symbol version with section GC" \ |
| 231 | "$LFLAGS --no-dynamic-linker -e foo --gc-sections -E -T pr20828-v.ld" "" "" \ |
| 232 | {pr20828-v.s} \ |
| 233 | {{objdump -p pr20828-v.od}} \ |
| 234 | "pr20828-v-2"]] |
| 235 | } |
| 236 | # PR ld/21233 check for correct dynamic symbol table entries where: |
| 237 | # - a symbol has been defined in a shared library used in the link, |
| 238 | # - the symbol has been referenced from a section swept in garbage collection, |
| 239 | # - the symbol has also been forced to be entered in the output file as an |
| 240 | # undefined symbol, either with a command-line option or a linker script |
| 241 | # command. |
| 242 | # Verify that the undefined symbol is global rather than local. |
| 243 | if { [check_gc_sections_available] } { |
| 244 | run_ld_link_tests [list \ |
| 245 | [list \ |
| 246 | "PR ld/21233 dynamic symbols with section GC\ |
| 247 | (auxiliary shared library)" \ |
| 248 | "$LFLAGS -shared -T pr21233.ld" "" "$AFLAGS_PIC" \ |
| 249 | {pr21233-l.s} \ |
| 250 | {{readelf --dyn-syms pr21233-l.sd}} \ |
| 251 | "libpr21233.so"]] |
| 252 | |
| 253 | run_ld_link_tests [list \ |
| 254 | [list \ |
| 255 | "PR ld/21233 dynamic symbols with section GC (--undefined)" \ |
| 256 | "$LFLAGS --gc-sections -e foo --undefined=bar -T pr21233.ld" \ |
| 257 | "tmpdir/libpr21233.so" "" \ |
| 258 | {pr21233.s} \ |
| 259 | {{readelf --dyn-syms pr21233.sd}} \ |
| 260 | "pr21233-1"]] |
| 261 | |
| 262 | run_ld_link_tests [list \ |
| 263 | [list \ |
| 264 | "PR ld/21233 dynamic symbols with section GC (--require-defined)" \ |
| 265 | "$LFLAGS --gc-sections -e foo --require-defined=bar\ |
| 266 | -T pr21233.ld" \ |
| 267 | "tmpdir/libpr21233.so" "" \ |
| 268 | {pr21233.s} \ |
| 269 | {{readelf --dyn-syms pr21233.sd}} \ |
| 270 | "pr21233-2"]] |
| 271 | |
| 272 | run_ld_link_tests [list \ |
| 273 | [list \ |
| 274 | "PR ld/21233 dynamic symbols with section GC (EXTERN)" \ |
| 275 | "$LFLAGS --gc-sections -e foo -T pr21233-e.ld" \ |
| 276 | "tmpdir/libpr21233.so" "" \ |
| 277 | {pr21233.s} \ |
| 278 | {{readelf --dyn-syms pr21233.sd}} \ |
| 279 | "pr21233-3"]] |
| 280 | } |
| 281 | |
| 282 | if { [check_gc_sections_available] } { |
| 283 | run_ld_link_tests [list \ |
| 284 | [list \ |
| 285 | "Build pr22150.so" \ |
| 286 | "$LFLAGS -shared --version-script pr22150.ver" \ |
| 287 | "" \ |
| 288 | "$AFLAGS_PIC" \ |
| 289 | {pr22150a.s} \ |
| 290 | {} \ |
| 291 | "pr22150.so" \ |
| 292 | ] \ |
| 293 | [list \ |
| 294 | "Build pr22150" \ |
| 295 | "$LFLAGS -e _start --gc-sections" \ |
| 296 | "tmpdir/pr22150.so" \ |
| 297 | "" \ |
| 298 | {pr22150b.s} \ |
| 299 | {{readelf -V pr22150.vd}} \ |
| 300 | "pr22150" \ |
| 301 | ] \ |
| 302 | ] |
| 303 | } |
| 304 | |
| 305 | set ASFLAGS $old_ASFLAGS |
| 306 | |
| 307 | # Check to see if the C compiler works |
| 308 | if { [which $CC] == 0 } { |
| 309 | return |
| 310 | } |
| 311 | |
| 312 | # Add -ldl to extralibs if needed |
| 313 | set extralibs "" |
| 314 | if { ![istarget *-*-freebsd*]} { |
| 315 | set extralibs "-ldl" |
| 316 | } |
| 317 | |
| 318 | set build_tests { |
| 319 | {"Build libfoo.so" |
| 320 | "-shared" "-fPIC" |
| 321 | {foo.c} {} "libfoo.so"} |
| 322 | {"Build versioned libfoo.so" |
| 323 | "-shared -Wl,--version-script=foo.map" "-fPIC" |
| 324 | {foo.c} {} "libfoov.so"} |
| 325 | {"Build libbar.so" |
| 326 | "-shared" "-fPIC" |
| 327 | {begin.c end.c} {} "libbar.so"} |
| 328 | {"Build warn libbar.so" |
| 329 | "-shared" "-fPIC" |
| 330 | {beginwarn.c end.c} |
| 331 | {{readelf {-S --wide} libbarw.rd} |
| 332 | {warning "^.*beginwarn.c:7: warning: function foo is deprecated$"}} |
| 333 | "libbarw.so" "c"} |
| 334 | {"Build hidden libbar.so" |
| 335 | "-shared" "-fPIC" |
| 336 | {begin.c endhidden.c} {} "libbarh.so"} |
| 337 | {"Build protected libbar.so" |
| 338 | "-shared" "-fPIC" |
| 339 | {begin.c endprotected.c} {} "libbarp.so"} |
| 340 | {"Build libbar.so with libfoo.so" |
| 341 | "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" |
| 342 | {end.c} {} "libbarfoo.so"} |
| 343 | {"Build libar.so with versioned libfoo.so" |
| 344 | "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" |
| 345 | {end.c} {} "libbarfoov.so"} |
| 346 | {"Build hidden libbar.so with libfoo.so" |
| 347 | "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" |
| 348 | {endhidden.c} {} "libbarhfoo.so"} |
| 349 | {"Build hidden libar.so with versioned libfoo.so" |
| 350 | "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" |
| 351 | {endhidden.c} {} "libbarhfoov.so"} |
| 352 | {"Build protected libbar.so with libfoo.so" |
| 353 | "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" |
| 354 | {endprotected.c} {} "libbarpfoo.so"} |
| 355 | {"Build protected libbar.so with versioned libfoo.so" |
| 356 | "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" |
| 357 | {endprotected.c} {} "libbarpfoov.so"} |
| 358 | {"Build libdl1.so" |
| 359 | "-shared" "-fPIC" |
| 360 | {dl1.c} {} "libdl1.so"} |
| 361 | {"Build libdl2a.so with --dynamic-list=dl2.list" |
| 362 | "-shared -Wl,--dynamic-list=dl2.list" "-fPIC" |
| 363 | {dl2.c dl2xxx.c} {} "libdl2a.so"} |
| 364 | {"Build libdl2a.so with --dynamic-list=dl2a.list" |
| 365 | "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC" |
| 366 | {dl2.c dl2xxx.c} {} "libdl2a.so"} |
| 367 | {"Build libdl2a.so with --dynamic-list-data" |
| 368 | "-shared -Wl,--dynamic-list-data" "-fPIC" |
| 369 | {dl2.c dl2xxx.c} {} "libdl2a.so"} |
| 370 | {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list" |
| 371 | "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC" |
| 372 | {dl2.c dl2xxx.c} {} "libdl2b.so"} |
| 373 | {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list" |
| 374 | "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC" |
| 375 | {dl2.c dl2xxx.c} {} "libdl2c.so"} |
| 376 | {"Build libdl4a.so with --dynamic-list=dl4.list" |
| 377 | "-shared -Wl,--dynamic-list=dl4.list" "-fPIC" |
| 378 | {dl4.c dl4xxx.c} {} "libdl4a.so"} |
| 379 | {"Build libdl4b.so with --dynamic-list-data" |
| 380 | "-shared -Wl,--dynamic-list-data" "-fPIC" |
| 381 | {dl4.c dl4xxx.c} {} "libdl4b.so"} |
| 382 | {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list" |
| 383 | "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC" |
| 384 | {dl4.c dl4xxx.c} {} "libdl4c.so"} |
| 385 | {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list" |
| 386 | "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC" |
| 387 | {dl4.c dl4xxx.c} {} "libdl4d.so"} |
| 388 | {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new" |
| 389 | "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC" |
| 390 | {dl4.c dl4xxx.c} {} "libdl4e.so"} |
| 391 | {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions" |
| 392 | "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC" |
| 393 | {dl4.c dl4xxx.c} {} "libdl4f.so"} |
| 394 | {"Build libdl6a.so" |
| 395 | "-shared" "-fPIC" |
| 396 | {dl6.c} {} "libdl6a.so"} |
| 397 | {"Build libdl6b.so with -Bsymbolic --dynamic-list-data" |
| 398 | "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC" |
| 399 | {dl6.c} {} "libdl6b.so"} |
| 400 | {"Build libdl6c.so with -Bsymbolic" |
| 401 | "-shared -Wl,-Bsymbolic" "-fPIC" |
| 402 | {dl6.c} {} "libdl6c.so"} |
| 403 | {"Build libdl6d.so with --dynamic-list-data -Bsymbolic" |
| 404 | "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC" |
| 405 | {dl6.c} {} "libdl6d.so"} |
| 406 | {"Build libdata1.so" |
| 407 | "-shared" "-fPIC" |
| 408 | {data1.c} {} "libdata1.so"} |
| 409 | {"Build libdata2.so" |
| 410 | "-shared" "-fPIC" |
| 411 | {data2.c} {} "libdata2.so"} |
| 412 | {"Build libcomm1.o" |
| 413 | "-r -nostdlib" "" |
| 414 | {comm1.c} {} "libcomm1.o"} |
| 415 | {"Build libfunc1.so" |
| 416 | "-shared" "-fPIC" |
| 417 | {func1.c} {} "libfunc1.so"} |
| 418 | {"Build libpr9676-1.a" |
| 419 | "" "-fPIC" |
| 420 | {pr9676-1.c} {} "libpr9676-1.a"} |
| 421 | {"Build libpr9676-2.a" |
| 422 | "" "-fPIC" |
| 423 | {pr9676-2.c} {} "libpr9676-2.a"} |
| 424 | {"Build libpr9676-3.so" |
| 425 | "-shared" "-fPIC" |
| 426 | {pr9676-3.c} {} "libpr9676-3.so"} |
| 427 | {"Build libpr9676-4.so" |
| 428 | "-shared" "-fPIC" |
| 429 | {pr9676-4.c} {} "libpr9676-4.so"} |
| 430 | {"Build libpr9676-4a.so" |
| 431 | "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group" |
| 432 | "-fPIC" |
| 433 | {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"} |
| 434 | {"Build libpr9679.so" |
| 435 | "-shared" "-fPIC -O0" |
| 436 | {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"} |
| 437 | {"Build libpr11138-1.so" |
| 438 | "-shared -Wl,--version-script=pr11138-1.map" "-fPIC" |
| 439 | {pr11138-1.c} {} "libpr11138-1.so"} |
| 440 | {"Build libpr11138-2.o" |
| 441 | "-r -nostdlib" "" |
| 442 | {pr11138-2.c} {} "libpr11138-2.o"} |
| 443 | {"Build pr13250-1.so" |
| 444 | "-shared" "-fPIC" |
| 445 | {pr13250-1.c} {} "libpr13250-1.so"} |
| 446 | {"Build pr13250-2.so with libpr13250-1.so" |
| 447 | "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC" |
| 448 | {pr13250-2.c} {} "libpr13250-2.so"} |
| 449 | {"Build libpr13250-3.o" |
| 450 | "-r -nostdlib" "" |
| 451 | {pr13250-3.c} {} "libpr13250-3.o"} |
| 452 | {"Build libpr14323-2.so" |
| 453 | "-shared" "-fPIC" |
| 454 | {pr14323-2.c} {} "libpr14323-2.so"} |
| 455 | {"Build pr14862-1.o" |
| 456 | "-r -nostdlib" "" |
| 457 | {pr14862-1.c} {} "libpr14862-1.o"} |
| 458 | {"Build libpr14862.so" |
| 459 | "-shared -Wl,--version-script=pr11138-1.map" "-fPIC" |
| 460 | {pr14862-2.c} {} "libpr14862.so"} |
| 461 | {"Build libneeded1b.so" |
| 462 | "-shared" "-fPIC" |
| 463 | {needed1b.c} {} "libneeded1b.so"} |
| 464 | {"Build libneeded1a.so" |
| 465 | "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC" |
| 466 | {needed1a.c} {} "libneeded1a.so"} |
| 467 | {"Build libneeded1c.o" |
| 468 | "-r -nostdlib" "" |
| 469 | {needed1c.c} {} "libneeded1c.o"} |
| 470 | {"Build libneeded1pic.o" |
| 471 | "-r -nostdlib" "-fPIC" |
| 472 | {needed1c.c} {} "libneeded1pic.o"} |
| 473 | {"Build needed1a.so with --add-needed" |
| 474 | "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" "" |
| 475 | {dummy.c} {} "needed1a.so"} |
| 476 | {"Build needed1b.so with --copy-dt-needed-entries" |
| 477 | "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" "" |
| 478 | {dummy.c} {} "needed1b.so"} |
| 479 | {"Build needed1a.so with --no-add-needed" |
| 480 | "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" "" |
| 481 | {dummy.c} {} "needed1c.so"} |
| 482 | {"Build needed1b.so with --no-copy-dt-needed-entries" |
| 483 | "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" "" |
| 484 | {dummy.c} {} "needed1d.so"} |
| 485 | {"Build librel.so" |
| 486 | "-shared" "-fPIC" |
| 487 | {rel.c} {} "librel.so"} |
| 488 | {"Build libneeded2a.so" |
| 489 | "-shared" "-fPIC" |
| 490 | {needed2a.c} {} "libneeded2a.so"} |
| 491 | {"Build libneeded2b.so" |
| 492 | "-shared -Wl,--version-script,needed2.ver" "-fPIC" |
| 493 | {needed2b.c} {} "libneeded2b.so"} |
| 494 | {"Build libneeded2c.o" |
| 495 | "-r -nostdlib" "" |
| 496 | {needed2c.c} {} "libneeded2c.o"} |
| 497 | {"Build needed2" |
| 498 | "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" "" |
| 499 | {dummy.c} {} "needed2"} |
| 500 | {"Build libneeded3a.so" |
| 501 | "-shared -Wl,--no-add-needed" "-fPIC" |
| 502 | {needed1a.c} {} "libneeded3a.so"} |
| 503 | {"Build libneeded3b.so" |
| 504 | "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC" |
| 505 | {dummy.c} {} "libneeded3b.so"} |
| 506 | {"Build needed3.o" |
| 507 | "-r -nostdlib" "" |
| 508 | {needed3.c} {} "libneeded3.so"} |
| 509 | {"Build needed3" |
| 510 | "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" "" |
| 511 | {dummy.c} {} "needed3"} |
| 512 | {"Build libpr2404a.so" |
| 513 | "-shared" "-fPIC" |
| 514 | {pr2404a.c} {} "libpr2404a.so"} |
| 515 | {"Build libpr2404n.so" |
| 516 | "-shared -Wl,-z,now" "-fPIC" |
| 517 | {pr2404a.c} {} "libpr2404n.so"} |
| 518 | {"Build libpr2404b.a" |
| 519 | "" "" |
| 520 | {pr2404b.c} {} "libpr2404b.a"} |
| 521 | {"Build rdynamic-1" |
| 522 | "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections" |
| 523 | {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"} |
| 524 | {"Build dynamic-1" |
| 525 | "-Wl,--no-dynamic-linker,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections" |
| 526 | {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"} |
| 527 | {"Build libpr16496a.so" |
| 528 | "-shared -Wl,--version-script=pr16496a.map" "-fPIC" |
| 529 | {pr16496a.c} {} "libpr16496a.so"} |
| 530 | {"Build libpr16496b.a" |
| 531 | "" "-fPIC" |
| 532 | {pr16496b.c} {} "libpr16496b.a"} |
| 533 | {"Build libpr16496b.so" |
| 534 | "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" "" |
| 535 | {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"} |
| 536 | {"Build libpr16452a.so" |
| 537 | "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC" |
| 538 | {pr16452a.c} {} "libpr16452a.so"} |
| 539 | {"Build libpr16452b.so" |
| 540 | "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC" |
| 541 | {dummy.c} {} "libpr16452b.so"} |
| 542 | {"Build pr16452" |
| 543 | "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" "" |
| 544 | {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"} |
| 545 | {"Build pr16457" |
| 546 | "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" "" |
| 547 | {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"} |
| 548 | {"Build libpr18458a.so" |
| 549 | "-shared -Wl,-z,now" "-fPIC" |
| 550 | {pr18458a.c} {} "libpr18458a.so"} |
| 551 | {"Build libpr18458b.so" |
| 552 | "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC" |
| 553 | {pr18458b.c} {} "libpr18458b.so"} |
| 554 | {"Build pr19073a.o" |
| 555 | "-r -nostdlib" "" |
| 556 | {pr19073.s} {} "pr19073a.o"} |
| 557 | {"Build libpr19073.so" |
| 558 | "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC" |
| 559 | {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"} |
| 560 | {"Build pr21964-1a.so" |
| 561 | "-shared" "-fPIC" |
| 562 | {pr21964-1a.c} {} "pr21964-1a.so"} |
| 563 | {"Build pr21964-1b.so" |
| 564 | "-shared" "-fPIC" |
| 565 | {pr21964-1b.c} {} "pr21964-1b.so"} |
| 566 | {"Build pr21964-2a.so" |
| 567 | "-shared" "-fPIC" |
| 568 | {pr21964-2a.c} {} "pr21964-2a.so"} |
| 569 | {"Build pr21964-2b.so" |
| 570 | "-shared" "-fPIC" |
| 571 | {pr21964-2b.c} {} "pr21964-2b.so"} |
| 572 | {"Dump pr21978.so" |
| 573 | "-shared" "-fPIC -g -O2" |
| 574 | {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"} |
| 575 | } |
| 576 | |
| 577 | run_cc_link_tests $build_tests |
| 578 | |
| 579 | run_ld_link_tests [list \ |
| 580 | [list \ |
| 581 | "Build pr22269-1" \ |
| 582 | "-pie -e _start --no-dynamic-linker -z text" \ |
| 583 | "" \ |
| 584 | "$AFLAGS_PIC" \ |
| 585 | { pr22269-1.c } \ |
| 586 | {{readelf -rW pr22269-1.rd}} \ |
| 587 | "pr22269-1" \ |
| 588 | "-fPIE -O2" \ |
| 589 | ] \ |
| 590 | ] |
| 591 | |
| 592 | set run_tests [list \ |
| 593 | [list "Run normal with libfoo.so" \ |
| 594 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \ |
| 595 | {main.c} "normal" "normal.out" ] \ |
| 596 | [list "Run protected with libfoo.so" \ |
| 597 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \ |
| 598 | {main.c} "protected" "normal.out" ] \ |
| 599 | [list "Run hidden with libfoo.so" \ |
| 600 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \ |
| 601 | {main.c} "hidden" "hidden.out" ] \ |
| 602 | [list "Run normal with versioned libfoo.so" \ |
| 603 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \ |
| 604 | {main.c} "normalv" "normal.out" ] \ |
| 605 | [list "Run warn with versioned libfoo.so" \ |
| 606 | "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \ |
| 607 | {main.c} "warn" "warn.out" \ |
| 608 | "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated$} ] \ |
| 609 | [list "Run protected with versioned libfoo.so" \ |
| 610 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \ |
| 611 | {main.c} "protected" "normal.out" ] \ |
| 612 | [list "Run hidden with versioned libfoo.so" \ |
| 613 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \ |
| 614 | {main.c} "hiddenv" "hidden.out" ] \ |
| 615 | [list "Run normal libbar.so with libfoo.so" \ |
| 616 | "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \ |
| 617 | {main.c} "normal" "normal.out" ] \ |
| 618 | [list "Run protected libbar.so with libfoo.so" \ |
| 619 | "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \ |
| 620 | {main.c} "protected" "normal.out" ] \ |
| 621 | [list "Run hidden libbar.so with libfoo.so" \ |
| 622 | "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \ |
| 623 | {main.c} "hidden" "hidden.out" ] \ |
| 624 | [list "Run normal libbar.so with versioned libfoo.so" \ |
| 625 | "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \ |
| 626 | {main.c} "normal" "normal.out" ] \ |
| 627 | [list "Run protected libbar.so with versioned libfoo.so" \ |
| 628 | "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \ |
| 629 | {main.c} "protected" "normal.out" ] \ |
| 630 | [list "Run hidden libbar.so with versioned libfoo.so" \ |
| 631 | "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \ |
| 632 | {main.c} "hidden" "hidden.out" ] \ |
| 633 | [list "Run with libdl2a.so" \ |
| 634 | "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \ |
| 635 | {dl2main.c} "dl2a" "dl2a.out" ] \ |
| 636 | [list "Run with libdl2b.so" \ |
| 637 | "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \ |
| 638 | {dl2main.c} "dl2b" "dl2b.out" ] \ |
| 639 | [list "Run with libdl2c.so" \ |
| 640 | "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \ |
| 641 | {dl2main.c} "dl2c" "dl2b.out" ] \ |
| 642 | [list "Run with libdl4a.so" \ |
| 643 | "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \ |
| 644 | {dl4main.c} "dl4a" "dl4a.out" ] \ |
| 645 | [list "Run with libdl4b.so" \ |
| 646 | "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \ |
| 647 | {dl4main.c} "dl4b" "dl4a.out" ] \ |
| 648 | [list "Run with libdl4c.so" \ |
| 649 | "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \ |
| 650 | {dl4main.c} "dl4c" "dl4b.out" ] \ |
| 651 | [list "Run with libdl4d.so" \ |
| 652 | "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \ |
| 653 | {dl4main.c} "dl4d" "dl4b.out" ] \ |
| 654 | [list "Run with libdl4e.so" \ |
| 655 | "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \ |
| 656 | {dl4main.c} "dl4e" "dl4a.out" ] \ |
| 657 | [list "Run with libdl4f.so" \ |
| 658 | "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \ |
| 659 | {dl4main.c} "dl4f" "dl4a.out" ] \ |
| 660 | [list "Run with libdata1.so" \ |
| 661 | "-Wl,--no-as-needed tmpdir/libdata1.so" "" \ |
| 662 | {dynbss1.c} "dynbss1" "pass.out" ] \ |
| 663 | [list "Run with libdata2.so" \ |
| 664 | "-Wl,--no-as-needed tmpdir/libdata2.so" "" \ |
| 665 | {weakdef1.c} "weakdef1" "pass.out" ] \ |
| 666 | [list "Run with libfunc1.so comm1.o" \ |
| 667 | "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \ |
| 668 | {dummy.c} "comm1" "pass.out" ] \ |
| 669 | [list "Run with comm1.o libfunc1.so" \ |
| 670 | "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \ |
| 671 | {dummy.c} "comm1" "pass.out" ] \ |
| 672 | [list "Run with pr11138-2.c libpr11138-1.so" \ |
| 673 | "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \ |
| 674 | {dummy.c} "pr11138a" "pr11138.out" ] \ |
| 675 | [list "Run with libpr11138-1.so pr11138-2.c" \ |
| 676 | "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \ |
| 677 | {dummy.c} "pr11138b" "pr11138.out" ] \ |
| 678 | [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \ |
| 679 | "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "" \ |
| 680 | {dummy.c} "pr13250" "pass.out" ] \ |
| 681 | [list "Run with pr14323-1.c pr14323-2.so" \ |
| 682 | "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \ |
| 683 | {pr14323-1.c} "pr14323" "pass.out" ] \ |
| 684 | [list "Run with pr14862-1.c libpr14862.so" \ |
| 685 | "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \ |
| 686 | {dummy.c} "pr14862" "pr14862.out" ] \ |
| 687 | [list "Link with --add-needed" \ |
| 688 | "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \ |
| 689 | {dummy.c} "needed1a" "needed1.out" ] \ |
| 690 | [list "Link with --copy-dt-needed-entries" \ |
| 691 | "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \ |
| 692 | {dummy.c} "needed1b" "needed1.out" ] \ |
| 693 | [list "Run relmain" \ |
| 694 | "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \ |
| 695 | {relmain.c} "relmain" "relmain.out" ] \ |
| 696 | [list "Run pr2404" \ |
| 697 | "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \ |
| 698 | {dummy.c} "pr2404" "pr2404.out" ] \ |
| 699 | [list "Run pr2404n" \ |
| 700 | "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \ |
| 701 | {dummy.c} "pr2404n" "pr2404.out" ] \ |
| 702 | [list "Run pr18458" \ |
| 703 | "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \ |
| 704 | {pr18458c.c} "pr18458" "pass.out" ] \ |
| 705 | [list "Run pr21964-1" \ |
| 706 | "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so" "" \ |
| 707 | {pr21964-1c.c} "pr21964-1" "pass.out" ] \ |
| 708 | ] |
| 709 | |
| 710 | # NetBSD ELF systems do not currently support the .*_array sections. |
| 711 | run_ld_link_exec_tests $run_tests "*-*-netbsdelf*" |
| 712 | |
| 713 | # These tests require dlopen support. |
| 714 | set dlopen_run_tests [list \ |
| 715 | [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \ |
| 716 | "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \ |
| 717 | {dl1main.c} "dl1a" "dl1.out" ] \ |
| 718 | [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \ |
| 719 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ |
| 720 | {dl1main.c} "dl1b" "dl1.out" ] \ |
| 721 | [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \ |
| 722 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ |
| 723 | {dl6amain.c} "dl6a1" "dl6a.out" ] \ |
| 724 | [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \ |
| 725 | "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \ |
| 726 | {dl6amain.c} "dl6a2" "dl6b.out" "$NOPIE_CFLAGS" ] \ |
| 727 | [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \ |
| 728 | "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \ |
| 729 | {dl6amain.c} "dl6a3" "dl6b.out" ] \ |
| 730 | [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \ |
| 731 | "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \ |
| 732 | {dl6amain.c} "dl6a4" "dl6a.out" ] \ |
| 733 | [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \ |
| 734 | "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \ |
| 735 | {dl6amain.c} "dl6a5" "dl6b.out" "$NOPIE_CFLAGS" ] \ |
| 736 | [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \ |
| 737 | "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \ |
| 738 | {dl6amain.c} "dl6a6" "dl6b.out" "$NOPIE_CFLAGS" ] \ |
| 739 | [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \ |
| 740 | "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \ |
| 741 | {dl6amain.c} "dl6a7" "dl6a.out" "$NOPIE_CFLAGS" ] \ |
| 742 | [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \ |
| 743 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ |
| 744 | {dl6bmain.c} "dl6b1" "dl6a.out" ] \ |
| 745 | [list "Run dl6b2 with dlopen on libdl6b.so" \ |
| 746 | "-Wl,--no-as-needed $extralibs" "" \ |
| 747 | {dl6bmain.c} "dl6b2" "dl6b.out" ] \ |
| 748 | [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \ |
| 749 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ |
| 750 | {dl6cmain.c} "dl6c1" "dl6b.out" ] \ |
| 751 | [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \ |
| 752 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ |
| 753 | {dl6dmain.c} "dl6d1" "dl6b.out" ] \ |
| 754 | [list "Run pr21964-2" \ |
| 755 | "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \ |
| 756 | {pr21964-2c.c} "pr21964-2" "pass.out" ] \ |
| 757 | ] |
| 758 | |
| 759 | # Only run them when libdl is available. |
| 760 | if [check_libdl_available] { |
| 761 | # XFAIL on NetBSD ELF systems as they do not currently support the .*_array |
| 762 | # sections. |
| 763 | run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsdelf*" |
| 764 | } |
| 765 | |
| 766 | # Check --no-add-needed and --no-copy-dt-needed-entries |
| 767 | set testname "--no-add-needed" |
| 768 | set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"] |
| 769 | if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } { |
| 770 | pass $testname |
| 771 | } { |
| 772 | fail $testname |
| 773 | } |
| 774 | set testname "--no-copy-dt-needed-entries" |
| 775 | set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"] |
| 776 | if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } { |
| 777 | pass $testname |
| 778 | } { |
| 779 | fail $testname |
| 780 | } |
| 781 | set testname "--no-add-needed -shared" |
| 782 | set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"] |
| 783 | if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } { |
| 784 | pass $testname |
| 785 | } { |
| 786 | fail $testname |
| 787 | } |
| 788 | set testname "--no-copy-dt-needed-entries -shared" |
| 789 | set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"] |
| 790 | if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } { |
| 791 | pass $testname |
| 792 | } { |
| 793 | fail $testname |
| 794 | } |
| 795 | |
| 796 | # Check to see if the C++ compiler works |
| 797 | if { [which $CXX] == 0 } { |
| 798 | return |
| 799 | } |
| 800 | |
| 801 | set build_cxx_tests { |
| 802 | {"Build libdl3a.so with --dynamic-list=dl3.list" |
| 803 | "-shared -Wl,--dynamic-list=dl3.list" "-fPIC" |
| 804 | {dl3.cc} {} "libdl3a.so" "c++"} |
| 805 | {"Build libdl3b.so with -Bsymbolic" |
| 806 | "-shared -Wl,-Bsymbolic" "-fPIC" |
| 807 | {dl3.cc} {} "libdl3b.so" "c++"} |
| 808 | {"Build libdl3a.so with --dynamic-list-cpp-typeinfo" |
| 809 | "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC" |
| 810 | {dl3.cc} {} "libdl3c.so" "c++"} |
| 811 | {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new" |
| 812 | "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC -ansi" |
| 813 | {del.cc new.cc} {} "libnew1a.so" "c++"} |
| 814 | {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new" |
| 815 | "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC -ansi" |
| 816 | {del.cc new.cc} {} "libnew1b.so" "c++"} |
| 817 | } |
| 818 | |
| 819 | # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer. |
| 820 | # {"Run with libdl3b.so" |
| 821 | # "tmpdir/libdl3b.so" "" |
| 822 | # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"} |
| 823 | set run_cxx_tests { |
| 824 | {"Run with libdl3a.so" |
| 825 | "-Wl,--no-as-needed tmpdir/libdl3a.so" "" |
| 826 | {dl3main.cc} "dl3a" "dl3a.out" "" "c++"} |
| 827 | {"Run with libdl3c.so" |
| 828 | "-Wl,--no-as-needed tmpdir/libdl3c.so" "" |
| 829 | {dl3main.cc} "dl3c" "dl3a.out" "" "c++"} |
| 830 | {"Run with libnew1a.so" |
| 831 | "-Wl,--no-as-needed tmpdir/libnew1a.so" "" |
| 832 | {dl5.cc} "dl5a" "dl5.out" "-ansi" "c++"} |
| 833 | {"Run with libnew1b.so" |
| 834 | "-Wl,--no-as-needed tmpdir/libnew1b.so" "" |
| 835 | {dl5.cc} "dl5b" "dl5.out" "-ansi" "c++"} |
| 836 | } |
| 837 | |
| 838 | run_cc_link_tests $build_cxx_tests |
| 839 | run_ld_link_exec_tests $run_cxx_tests |
| 840 | |
| 841 | if { [istarget *-*-linux*] |
| 842 | || [istarget *-*-nacl*] |
| 843 | || [istarget *-*-gnu*] } { |
| 844 | run_cc_link_tests [list \ |
| 845 | [list \ |
| 846 | "Build libpr2404b.a with PIE" \ |
| 847 | "" \ |
| 848 | "-fPIE" \ |
| 849 | { pr2404b.c } \ |
| 850 | {} \ |
| 851 | "libpr2404b.a" \ |
| 852 | ] \ |
| 853 | [list \ |
| 854 | "Build pr19579a.o" \ |
| 855 | "" "-fPIE" \ |
| 856 | {pr19579a.c} \ |
| 857 | {} \ |
| 858 | "libpr19579a.a" \ |
| 859 | ] \ |
| 860 | [list \ |
| 861 | "Build libpr19579.so" \ |
| 862 | "-shared" \ |
| 863 | "-fPIC" \ |
| 864 | {pr19579b.c} \ |
| 865 | {} \ |
| 866 | "libpr19579.so" \ |
| 867 | ] \ |
| 868 | [list \ |
| 869 | "Build libpr19579now.so" \ |
| 870 | "-shared -Wl,-z,now" \ |
| 871 | "-fPIC" \ |
| 872 | {pr19579b.c} \ |
| 873 | {} \ |
| 874 | "libpr19579.so" \ |
| 875 | ] \ |
| 876 | [list \ |
| 877 | "Build pr22393-2a.so" \ |
| 878 | "-shared -Wl,-z,separate-code" \ |
| 879 | "-fPIC" \ |
| 880 | {pr22393-2a.c} \ |
| 881 | {{readelf -lW pr22393-2a.rd} \ |
| 882 | {readelf -lW pr22393-2b.rd}} \ |
| 883 | "pr22393-2a.so" \ |
| 884 | ] \ |
| 885 | [list \ |
| 886 | "Build pr22393-2a-now.so" \ |
| 887 | "-shared -Wl,-z,separate-code,-z,now" \ |
| 888 | "-fPIC" \ |
| 889 | {pr22393-2a.c} \ |
| 890 | {{readelf -lW pr22393-2a.rd} \ |
| 891 | {readelf -lW pr22393-2b.rd}} \ |
| 892 | "pr22393-2a-now.so" \ |
| 893 | ] \ |
| 894 | [list \ |
| 895 | "Build pr22393-2" \ |
| 896 | "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \ |
| 897 | "$NOPIE_CFLAGS" \ |
| 898 | {pr22393-2b.c} \ |
| 899 | {{readelf -lW pr22393-2a.rd} \ |
| 900 | {readelf -lW pr22393-2b.rd}} \ |
| 901 | "pr22393-2" \ |
| 902 | ] \ |
| 903 | [list \ |
| 904 | "Build pr22393-2 (PIE)" \ |
| 905 | "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \ |
| 906 | "-fPIE" \ |
| 907 | {pr22393-2b.c} \ |
| 908 | {{readelf -lW pr22393-2a.rd} \ |
| 909 | {readelf -lW pr22393-2b.rd}} \ |
| 910 | "pr22393-2-pie" \ |
| 911 | ] \ |
| 912 | [list \ |
| 913 | "Build pr22393-2 (static)" \ |
| 914 | "-static -Wl,-z,separate-code" \ |
| 915 | "" \ |
| 916 | {pr22393-2a.c pr22393-2b.c} \ |
| 917 | {{readelf -lW pr22393-2a.rd} \ |
| 918 | {readelf -lW pr22393-2b.rd}} \ |
| 919 | "pr22393-2-static" \ |
| 920 | ] \ |
| 921 | ] |
| 922 | run_ld_link_exec_tests [list \ |
| 923 | [list \ |
| 924 | "Run pr18458 with PIE" \ |
| 925 | "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" \ |
| 926 | "" \ |
| 927 | {pr18458c.c} \ |
| 928 | "pr18458p" \ |
| 929 | "pass.out" \ |
| 930 | "-fPIE" \ |
| 931 | ] \ |
| 932 | [list \ |
| 933 | "Run pr2404 with PIE" \ |
| 934 | "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \ |
| 935 | "" \ |
| 936 | { dummy.c } \ |
| 937 | "pr2404pie" \ |
| 938 | "pr2404.out" \ |
| 939 | "-fPIE" \ |
| 940 | ] \ |
| 941 | [list \ |
| 942 | "Run pr2404 with PIE (-z now)" \ |
| 943 | "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \ |
| 944 | "" \ |
| 945 | { dummy.c } \ |
| 946 | "pr2404pien" \ |
| 947 | "pr2404.out" \ |
| 948 | "-fPIE" \ |
| 949 | ] \ |
| 950 | [list \ |
| 951 | "Run pr18718" \ |
| 952 | "" \ |
| 953 | "" \ |
| 954 | { pr18718.c check-ptr-eq.c } \ |
| 955 | "pr18718" \ |
| 956 | "pass.out" \ |
| 957 | "-O2 -I../bfd" \ |
| 958 | ] \ |
| 959 | [list \ |
| 960 | "Run pr18718 (-z now)" \ |
| 961 | "-Wl,-z,now" \ |
| 962 | "" \ |
| 963 | { pr18718.c check-ptr-eq.c } \ |
| 964 | "pr18718" \ |
| 965 | "pass.out" \ |
| 966 | "-O2 -I../bfd" \ |
| 967 | ] \ |
| 968 | [list \ |
| 969 | "Run pr18718 with PIE (1)" \ |
| 970 | "-pie" \ |
| 971 | "" \ |
| 972 | { pr18718.c check-ptr-eq.c } \ |
| 973 | "pr18718pie1" \ |
| 974 | "pass.out" \ |
| 975 | "-O2 -fPIE -I../bfd" \ |
| 976 | ] \ |
| 977 | [list \ |
| 978 | "Run pr18718 with PIE (2)" \ |
| 979 | "" \ |
| 980 | "" \ |
| 981 | { pr18718.c check-ptr-eq.c } \ |
| 982 | "pr18718pie2" \ |
| 983 | "pass.out" \ |
| 984 | "-O2 -fPIE -I../bfd" \ |
| 985 | ] \ |
| 986 | [list \ |
| 987 | "Run pr18718 with PIE (3)" \ |
| 988 | "-pie -Wl,-z,now" \ |
| 989 | "" \ |
| 990 | { pr18718.c check-ptr-eq.c } \ |
| 991 | "pr18718pie3" \ |
| 992 | "pass.out" \ |
| 993 | "-O2 -fPIE -I../bfd" \ |
| 994 | ] \ |
| 995 | [list \ |
| 996 | "Run pr18718 with PIE (4)" \ |
| 997 | "-Wl,-z,now" \ |
| 998 | "" \ |
| 999 | { pr18718.c check-ptr-eq.c } \ |
| 1000 | "pr18718pie4" \ |
| 1001 | "pass.out" \ |
| 1002 | "-O2 -fPIE -I../bfd" \ |
| 1003 | ] \ |
| 1004 | [list \ |
| 1005 | "Run pr18718 with PIC (1)" \ |
| 1006 | "" \ |
| 1007 | "" \ |
| 1008 | { pr18718.c check-ptr-eq.c } \ |
| 1009 | "pr18718pic1" \ |
| 1010 | "pass.out" \ |
| 1011 | "-O2 -fPIC -I../bfd" \ |
| 1012 | ] \ |
| 1013 | [list \ |
| 1014 | "Run pr18718 with PIC (2)" \ |
| 1015 | "-pie" \ |
| 1016 | "" \ |
| 1017 | { pr18718.c check-ptr-eq.c } \ |
| 1018 | "pr18718pic2" \ |
| 1019 | "pass.out" \ |
| 1020 | "-O2 -fPIC -I../bfd" \ |
| 1021 | ] \ |
| 1022 | [list \ |
| 1023 | "Run pr18718 with PIC (3)" \ |
| 1024 | "-Wl,-z,now" \ |
| 1025 | "" \ |
| 1026 | { pr18718.c check-ptr-eq.c } \ |
| 1027 | "pr18718pic3" \ |
| 1028 | "pass.out" \ |
| 1029 | "-O2 -fPIC -I../bfd" \ |
| 1030 | ] \ |
| 1031 | [list \ |
| 1032 | "Run pr18718 with PIC (4)" \ |
| 1033 | "-pie -Wl,-z,now" \ |
| 1034 | "" \ |
| 1035 | { pr18718.c check-ptr-eq.c } \ |
| 1036 | "pr18718pic4" \ |
| 1037 | "pass.out" \ |
| 1038 | "-O2 -fPIC -I../bfd" \ |
| 1039 | ] \ |
| 1040 | [list \ |
| 1041 | "Run pr19579" \ |
| 1042 | "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \ |
| 1043 | "" \ |
| 1044 | {dummy.c} \ |
| 1045 | "pr19579" \ |
| 1046 | "pass.out" \ |
| 1047 | "-fPIE" \ |
| 1048 | ] \ |
| 1049 | [list \ |
| 1050 | "Run pr19579 (-z now)" \ |
| 1051 | "-pie -Wl,-z,now -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \ |
| 1052 | "" \ |
| 1053 | {dummy.c} \ |
| 1054 | "pr19579n" \ |
| 1055 | "pass.out" \ |
| 1056 | "-fPIE" \ |
| 1057 | ] \ |
| 1058 | [list \ |
| 1059 | "Run pr22393-2" \ |
| 1060 | "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \ |
| 1061 | "" \ |
| 1062 | {pr22393-2b.c} \ |
| 1063 | "pr22393-2" \ |
| 1064 | "pass.out" \ |
| 1065 | "$NOPIE_CFLAGS" \ |
| 1066 | ] \ |
| 1067 | [list \ |
| 1068 | "Run pr22393-2 (PIE)" \ |
| 1069 | "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \ |
| 1070 | "" \ |
| 1071 | {pr22393-2b.c} \ |
| 1072 | "pr22393-2-pie" \ |
| 1073 | "pass.out" \ |
| 1074 | "-fPIE" \ |
| 1075 | ] \ |
| 1076 | [list \ |
| 1077 | "Run pr22393-2 (static)" \ |
| 1078 | "-static -Wl,-z,separate-code" \ |
| 1079 | "" \ |
| 1080 | {pr22393-2a.c pr22393-2b.c} \ |
| 1081 | "pr22393-2-static" \ |
| 1082 | "pass.out" \ |
| 1083 | ] \ |
| 1084 | ] |
| 1085 | } |
| 1086 | |
| 1087 | proc mix_pic_and_non_pic {xfails cflags ldflags exe} { |
| 1088 | run_cc_link_tests [list \ |
| 1089 | [list \ |
| 1090 | "Build libpr19719a.so" \ |
| 1091 | "-shared -Wl,-soname,libpr19719.so" \ |
| 1092 | "-fPIC" \ |
| 1093 | { pr19719d.c } \ |
| 1094 | {} \ |
| 1095 | "libpr19719a.so" \ |
| 1096 | ] \ |
| 1097 | [list \ |
| 1098 | "Build libpr19719b.so" \ |
| 1099 | "-shared -Wl,-soname,libpr19719.so" \ |
| 1100 | "-fPIC" \ |
| 1101 | { dummy.c } \ |
| 1102 | {} \ |
| 1103 | "libpr19719b.so" \ |
| 1104 | ] \ |
| 1105 | [list \ |
| 1106 | "Build libpr19719b.o" \ |
| 1107 | "-r -nostdlib" \ |
| 1108 | "-fPIC" \ |
| 1109 | { pr19719b.c } \ |
| 1110 | {} \ |
| 1111 | "libpr19719b.o" \ |
| 1112 | ] \ |
| 1113 | ] |
| 1114 | |
| 1115 | send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n" |
| 1116 | exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so |
| 1117 | |
| 1118 | run_ld_link_exec_tests [list \ |
| 1119 | [list \ |
| 1120 | "Run $exe fun defined" \ |
| 1121 | "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \ |
| 1122 | "" \ |
| 1123 | { pr19719a.c pr19719c.c } \ |
| 1124 | $exe \ |
| 1125 | "pass.out" \ |
| 1126 | "$cflags" \ |
| 1127 | ] \ |
| 1128 | ] |
| 1129 | |
| 1130 | send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n" |
| 1131 | exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so |
| 1132 | |
| 1133 | foreach targ $xfails { |
| 1134 | setup_xfail $targ |
| 1135 | } |
| 1136 | |
| 1137 | if ![isnative] { |
| 1138 | unsupported "Run $exe fun undefined" |
| 1139 | return |
| 1140 | } |
| 1141 | |
| 1142 | set exec_output [run_host_cmd "tmpdir/$exe" ""] |
| 1143 | if {![string match "PASS" $exec_output]} { |
| 1144 | fail "Run $exe fun undefined" |
| 1145 | } else { |
| 1146 | pass "Run $exe fun undefined" |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719" |
| 1151 | mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie" |