1# Expect script for ld-plugin LTO tests 2# Copyright (C) 2011-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# These tests require plugin and LTO. 22if { ![check_plugin_api_available] 23 || ![check_lto_available] } { 24 return 25} 26 27global CFLAGS 28global CXXFLAGS 29set saved_CFLAGS "$CFLAGS" 30set saved_CXXFLAGS "$CXXFLAGS" 31regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS 32regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS 33 34proc restore_notify { } { 35 global saved_CFLAGS 36 global saved_CXXFLAGS 37 set CFLAGS "$saved_CFLAGS" 38 set CXXFLAGS "$saved_CXXFLAGS" 39} 40 41set plugin_names { 42 liblto_plugin.so 43 liblto_plugin-0.dll 44 cyglto_plugin-0.dll 45} 46set plug_opt "" 47foreach plug $plugin_names { 48 set plug_so [run_host_cmd $CC "--print-prog-name $plug"] 49 if { $plug_so eq $plug } then { 50 set plug_so [run_host_cmd $CC "--print-file-name $plug"] 51 } 52 if { $plug_so ne $plug } then { 53 set plug_opt "--plugin $plug_so" 54 break 55 } 56} 57set lto_fat "" 58set lto_no_fat "" 59if { [check_lto_fat_available] } { 60 set lto_fat "-ffat-lto-objects" 61 set lto_no_fat "-fno-fat-lto-objects" 62} 63 64# Simple LTO tests and generate input files for complex LTO tests. 65set lto_link_tests [list \ 66 [list "LTO 1" \ 67 "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \ 68 {lto-1a.c lto-1b.c} {} "lto-1.exe"] \ 69 [list "Compile 2" \ 70 "" "-O2 -flto -fuse-linker-plugin" \ 71 {lto-2.c} {} ""] \ 72 [list "LTO 2" \ 73 "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" "" \ 74 {dummy.c} {} "lto-2.exe"] \ 75 [list "Compile 3a" \ 76 "" "-flto" \ 77 {lto-3a.c} {} ""] \ 78 [list "Compile 3c" \ 79 "" "-O2" \ 80 {lto-3c.c} {} ""] \ 81 [list "Build liblto-3.a" \ 82 "" "-flto $lto_fat" \ 83 {lto-3b.c} {} "liblto-3.a"] \ 84 [list "Compile 5a" \ 85 "" "-flto $lto_fat" \ 86 {lto-5a.c} {} ""] \ 87 [list "Compile 5b" \ 88 "" "-flto $lto_fat" \ 89 {lto-5b.c} {} ""] \ 90 [list "LTO 6" \ 91 "-O2 -flto -fuse-linker-plugin" "" \ 92 {lto-6.c} {} "lto-6.exe" "c"] \ 93 [list "Compile PR ld/12365" \ 94 "" "-flto -O2 $lto_fat" \ 95 {pr12365a.c pr12365b.c pr12365c.c} {} ""] \ 96 [list "Compile 9" \ 97 "" "-O2 -finline -flto" \ 98 {lto-9.cc} {} "" "c++"] \ 99 [list "Compile 11a" \ 100 "" "-O -flto" \ 101 {lto-11a.c} {} ""] \ 102 [list "Compile 11b" \ 103 "" "-O -flto" \ 104 {lto-11b.c} {} ""] \ 105 [list "Compile 11c" \ 106 "" "-O" \ 107 {lto-11c.c} {} ""] \ 108 [list "Build liblto-12.a" \ 109 "$plug_opt" "-O2 -flto" \ 110 {lto-12c.c} {} "liblto-12.a"] \ 111 [list "Compile 12" \ 112 "" "-O2 -flto" \ 113 {lto-12a.c lto-12b.c} {} ""] \ 114 [list "Compile 13" \ 115 "" "-O2 -flto" \ 116 {lto-13a.c lto-13b.c} {} ""] \ 117 [list "Build liblto-13.a" \ 118 "" "-O2" \ 119 {lto-13c.c} {} "liblto-13.a"] \ 120 [list "Compile 14a" \ 121 "" "-flto" \ 122 {lto-14a.c lto-14b.c} {} ""] \ 123 [list "Build liblto-14.a" \ 124 "$plug_opt" "-flto" \ 125 {lto-14c.c} {} "liblto-14.a"] \ 126 [list "Compile 15a" \ 127 "" "-flto" \ 128 {lto-15a.c} {} ""] \ 129 [list "Build liblto-15.a" \ 130 "$plug_opt" "-flto" \ 131 {lto-15b.c} {} "liblto-15.a"] \ 132 [list "PR ld/12696" \ 133 "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \ 134 {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \ 135 [list "Compile PR ld/12758" \ 136 "" "" \ 137 {pr12758a.s} {} ""] \ 138 [list "Build libpr12758.a" \ 139 "" "-flto -O2 $lto_fat" \ 140 {pr12758b.c} {} "libpr12758.a"] \ 141 [list "PR ld/12758" \ 142 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" "" \ 143 {dummy.c} {} "pr12758.exe"] \ 144 [list "Compile PR ld/12760" \ 145 "" "-g -O0" \ 146 {pr12760a.c} {} ""] \ 147 [list "Build libpr12760.a" \ 148 "" "-flto -O2 $lto_fat" \ 149 {pr12760b.c} {} "libpr12760.a"] \ 150 [list "PR ld/12760" \ 151 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \ 152 {dummy.c} {} "pr12760.exe" "c" "pr12760a.c:6: warning: Bad bar"] \ 153 [list "Build libpr13183.a" \ 154 "-T" "-flto -O2 $lto_fat" \ 155 {pr13183a.c} {} "libpr13183.a"] \ 156 [list "Compile PR ld/13183" \ 157 "" "-flto -O2" \ 158 {pr13183b.c} {} ""] \ 159 [list "Compile PR ld/13201" \ 160 "" "-flto -O2" \ 161 {pr13201.c} {} ""] \ 162 [list "PR ld/13287" \ 163 "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" \ 164 {pr13287.cc} {} "pr13287.exe" "c++"] \ 165 [list "PR ld/15323 (1)" \ 166 "" "-O2" \ 167 {pr15323a.c} {} "" "c"] \ 168 [list "PR ld/15323 (2)" \ 169 "-O2 -flto -r -nostdlib" "-O2 -flto" \ 170 {pr15323a.c} {} "pr15323a-r.o" "c"] \ 171 [list "Compile(1) PR ld/pr16846" \ 172 "" "-flto" \ 173 {pr16846a.c pr16846b.c} {} ""] \ 174 [list "Compile(2) PR ld/pr16846" \ 175 "" "" \ 176 {pr16846c.c} {} ""] \ 177 [list "PR ld/pr16846(1)" \ 178 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846b.o tmpdir/pr16846c.o" "" \ 179 {dummy.c} {} "pr16846a.exe"] \ 180 [list "PR ld/pr16846(2)" \ 181 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846c.o tmpdir/pr16846b.o" "" \ 182 {dummy.c} {} "pr16846b.exe"] \ 183 [list "PR ld/19317 (1)" \ 184 "$plug_opt" "-flto $lto_no_fat" \ 185 {pr19317.c} {} "libpr19317.a"] \ 186 [list "Build pr20276a.o" \ 187 "" "-fno-lto" \ 188 {pr20276a.c}] \ 189 [list "Build pr20276b.o" \ 190 "$plug_opt" "-flto $lto_no_fat" \ 191 {pr20276b.c}] \ 192 [list "Build pr20267a.o" \ 193 "" "" \ 194 {pr20267a.c}] \ 195 [list "Build libpr20267a.a" \ 196 "$plug_opt" "-flto $lto_fat" \ 197 {pr20267b.c} {} "libpr20267a.a"] \ 198 [list "Build libpr20267b.a" \ 199 "$plug_opt" "-flto $lto_no_fat" \ 200 {pr20267b.c} {} "libpr20267b.a"] \ 201] 202 203if { [at_least_gcc_version 4 7] } { 204 set lto_link_tests [concat $lto_link_tests [list \ 205 [list "Compile PR ld/12942 (1)" \ 206 "" "-flto -O2" \ 207 {pr12942a.cc pr12942c.cc} {} "" "c++"] \ 208 [list "Compile PR ld/12942 (2)" \ 209 "" "-O0" \ 210 {pr12942b.cc} {} "" "c++"] \ 211 ]] 212} 213 214# Generate input files for complex LTO tests for ELF. 215set lto_link_elf_tests [list \ 216 [list "Compile 7" \ 217 "" "-flto -O2" \ 218 {lto-7a.c lto-7b.c lto-7c.c} {} ""] \ 219 [list "Build liblto-7.so" \ 220 "-shared" "-O2 -fpic" \ 221 {lto-7d.c} {} "liblto-7.so" "c"] \ 222 [list "Compile 8a" \ 223 "" "-O2" \ 224 {lto-8a.c} {} ""] \ 225 [list "Compile 8b" \ 226 "" "-flto -O2" \ 227 {lto-8b.c} {} ""] \ 228 [list "Build liblto-17a.so" \ 229 "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \ 230 {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \ 231 [list "Build liblto-17b.so 1" \ 232 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \ 233 {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \ 234 [list "Build liblto-17b.so 2" \ 235 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \ 236 {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \ 237 [list "PR ld/12982" \ 238 "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \ 239 {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \ 240 [list "PR ld/12975" \ 241 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \ 242 {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \ 243 [list "PR ld/13229" \ 244 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \ 245 {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \ 246 [list "PR ld/13244" \ 247 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \ 248 {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \ 249 [list "Build libpr15146a.a" \ 250 "$plug_opt" "-flto -O2" \ 251 {pr15146a.c} {} "lib15146a.a"] \ 252 [list "Build pr15146b.so" \ 253 "-shared" "-O2 -fpic" \ 254 {pr15146b.c} {} "pr15146b.so" "c"] \ 255 [list "Build pr15146c.so" \ 256 "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" \ 257 {pr15146c.c} {} "pr15146c.so" "c"] \ 258 [list "PR ld/15146 (1)" \ 259 "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \ 260 {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \ 261 [list "Build libpr15146d.a" \ 262 "$plug_opt" "-flto -O2" \ 263 {pr15146d.c} {} "lib15146d.a"] \ 264 [list "Build libpr16746a.a" \ 265 "" "" \ 266 {pr16746a.c pr16746b.c} {} "lib15146a.a"] \ 267 [list "Build libpr16746b.a" \ 268 "$plug_opt" "-O2 -flto" \ 269 {pr16746c.c pr16746d.c} {} "lib15146b.a"] \ 270 [list "PR ld/16746 (1)" \ 271 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \ 272 {dummy.c} {} "pr16746a.exe"] \ 273 [list "PR ld/16746 (2)" \ 274 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \ 275 {dummy.c} {} "pr16746b.exe"] \ 276 [list "PR ld/14918" \ 277 "-flto" "-flto" \ 278 {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \ 279] 280 281# Check final symbols in executables. 282set lto_link_symbol_tests [list \ 283 [list "LTO 3 symbol" \ 284 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \ 285 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \ 286 [list "LTO 5 symbol" \ 287 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \ 288 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \ 289 [list "LTO 9 symbol" \ 290 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \ 291 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \ 292 [list "LTO 16a symbol" \ 293 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \ 294 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \ 295 [list "LTO 16b symbol" \ 296 "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \ 297 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \ 298 [list "PR ld/13183" \ 299 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \ 300 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \ 301] 302 303# LTO run-time tests. 304set lto_run_tests [list \ 305 [list "LTO 3a" \ 306 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \ 307 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \ 308 [list "LTO 3b" \ 309 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \ 310 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \ 311 [list "LTO 3c" \ 312 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o -Wl,--whole-archive tmpdir/liblto-3.a -Wl,--no-whole-archive tmpdir/liblto-3.a" "" \ 313 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \ 314 [list "LTO 5" \ 315 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \ 316 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \ 317 [list "LTO 11" \ 318 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \ 319 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \ 320 [list "LTO 12a" \ 321 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \ 322 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \ 323 [list "LTO 12b" \ 324 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \ 325 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \ 326 [list "LTO 13" \ 327 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \ 328 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \ 329 [list "LTO 14" \ 330 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \ 331 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \ 332 [list "LTO 15" \ 333 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \ 334 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \ 335 [list "PR ld/13066" \ 336 "-O2 -flto -fuse-linker-plugin" "" \ 337 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \ 338 [list "PR ld/13201" \ 339 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \ 340 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \ 341 [list "PR ld/15323 (3)" \ 342 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \ 343 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \ 344 [list "PR ld/15323 (4)" \ 345 "-O2 -flto tmpdir/pr15323a-r.o" "" \ 346 {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \ 347 [list "PR ld/19317 (3)" \ 348 "-O2 -flto tmpdir/pr19317-r.o" "" \ 349 {dummy.c} "pr19317.exe" "pr19317.out" "-flto -O2" "c"] \ 350 [list "Run pr20276" \ 351 "-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \ 352 {dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \ 353 [list "Run pr20267a" \ 354 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \ 355 {dummy.c} "pr20267a" "pass.out" "-flto -O2" "c"] \ 356 [list "Run pr20267b" \ 357 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \ 358 {dummy.c} "pr20267b" "pass.out" "-flto -O2" "c"] \ 359] 360 361if { [at_least_gcc_version 4 7] } { 362 set lto_run_tests [concat $lto_run_tests [list \ 363 [list "PR ld/12942 (1)" \ 364 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \ 365 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \ 366 [list "PR ld/12942 (2)" \ 367 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \ 368 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \ 369 ]] 370} 371 372# LTO run-time tests for ELF 373set lto_run_elf_tests [list \ 374 [list "LTO 7" \ 375 "-O2 -flto -fuse-linker-plugin tmpdir/lto-7b.o tmpdir/lto-7c.o tmpdir/lto-7a.o -Wl,--no-as-needed tmpdir/liblto-7.so" "" \ 376 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \ 377 [list "LTO 8" \ 378 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \ 379 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \ 380 [list "LTO TLS IE" \ 381 "-O2 -flto -fuse-linker-plugin" "" \ 382 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \ 383] 384 385run_cc_link_tests $lto_link_tests 386 387# Restrict these to ELF targets that support shared libs and PIC. 388if { [is_elf_format] && [check_lto_shared_available] } { 389 run_cc_link_tests $lto_link_elf_tests 390 set testname "PR ld/15146 (2)" 391 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"] 392 if { [ regexp "undefined reference to symbol 'xxx'" $exec_output ] } { 393 pass $testname 394 } { 395 fail $testname 396 } 397 set testname "PR ld/16746 (3)" 398 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"] 399 if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } { 400 pass $testname 401 } { 402 fail $testname 403 } 404 set testname "PR ld/16746 (4)" 405 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"] 406 if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } { 407 pass $testname 408 } { 409 fail $testname 410 } 411} 412 413set testname "Build liblto-11.a" 414remote_file host delete "tmpdir/liblto-11.a" 415set catch_output [run_host_cmd "$ar" "rc $plug_opt tmpdir/liblto-11.a tmpdir/lto-11a.o tmpdir/lto-11b.o tmpdir/lto-11c.o"] 416if {![string match "" $catch_output]} { 417 unresolved $testname 418 restore_notify 419 return 420} 421 422if { [at_least_gcc_version 4 7] } { 423 # Check expected LTO linker errors. 424 # Since the asm symbol name hack in pr12365b.c doesn't work on all 425 # targets, run PR ld/12365 tests only for known targets. 426 if { ([istarget "i?86-*-elf*"] 427 || (([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"]) 428 && ![istarget "*-*-*aout*"] 429 && ![istarget "*-*-*oldld*"]) 430 || [istarget "i?86-*-nacl*"] 431 || [istarget "x86_64-*-nacl*"] 432 || [istarget "x86_64-*-linux*"] 433 || [istarget "amd64-*-linux*"]) } { 434 set testname "PR ld/12365" 435 set exec_output [run_host_cmd "$CC" "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"] 436 if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } { 437 # Linker should catch the reference to undefined `my_bcopy' 438 # error caused by a GCC bug. 439 pass $testname 440 } elseif { [ string match "" $exec_output ] } { 441 global READELF 442 set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"] 443 if { [ regexp "my_bcopy" $exec_output ] } { 444 # Verify that there is no `my_bcopy' symbol in executable. 445 fail $testname 446 } { 447 pass $testname 448 } 449 } { 450 fail $testname 451 } 452 } 453 set testname "PR ld/12942 (3)" 454 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"] 455 if { [ regexp "undefined reference to `link_error\\(\\)'" $exec_output ] } { 456 pass $testname 457 } { 458 fail $testname 459 } 460} 461 462# Run "ld -r" to generate inputs for complex LTO tests. 463run_dump_test "lto-3r" 464remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o" 465run_dump_test "lto-5r" 466remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o" 467 468run_cc_link_tests $lto_link_symbol_tests 469 470run_ld_link_tests [list \ 471 [list "PR ld/19317 (2)" \ 472 "-r tmpdir/pr19317.o" "" "" \ 473 {dummy.s} {} "pr19317-r.o"] \ 474] 475 476# The following tests require running the executable generated by ld. 477if ![isnative] { 478 return 479} 480 481run_ld_link_exec_tests [] $lto_run_tests 482 483if { [is_elf_format] } { 484 run_ld_link_exec_tests [] $lto_run_elf_tests 485} 486 487proc pr20103 {cflags libs} { 488 global CC 489 490 set testname "PR ld/20103 ($cflags $libs)" 491 set exec_output [run_host_cmd "$CC" "$cflags $libs"] 492 if { [ regexp "undefined reference to `dead'" $exec_output ] } { 493 pass "$testname (1)" 494 } { 495 fail "$testname (1)" 496 } 497 if { [ regexp "plugin needed to handle lto object" $exec_output ] } { 498 fail "$testname (2)" 499 } { 500 pass "$testname (2)" 501 } 502} 503 504if { [check_lto_fat_available] } { 505 run_cc_link_tests [list \ 506 [list \ 507 "Build fatpr20103a.a" \ 508 "$plug_opt" "-flto -ffat-lto-objects" \ 509 {pr20103a.c} {} "fatpr20103a.a" 510 ] \ 511 [list \ 512 "Build fatpr20103b.a" \ 513 "$plug_opt" "-flto -ffat-lto-objects" \ 514 {pr20103b.c} {} "fatpr20103b.a" 515 ] \ 516 [list \ 517 "Build fatpr20103c.a" \ 518 "$plug_opt" "-flto -ffat-lto-objects" \ 519 {pr20103c.c} {} "fatpr20103c.a" \ 520 ] \ 521 [list \ 522 "Build thinpr20103a.a" \ 523 "$plug_opt" "-flto -fno-fat-lto-objects" \ 524 {pr20103a.c} {} "thinpr20103a.a" 525 ] \ 526 [list \ 527 "Build thinpr20103b.a" \ 528 "$plug_opt" "-flto -fno-fat-lto-objects" \ 529 {pr20103b.c} {} "thinpr20103b.a" 530 ] \ 531 [list \ 532 "Build thinpr20103c.a" \ 533 "$plug_opt" "-flto -fno-fat-lto-objects" \ 534 {pr20103c.c} {} "thinpr20103c.a" \ 535 ] \ 536 [list \ 537 "Build pr20103a" \ 538 "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \ 539 "-O2 -flto" \ 540 {dummy.c} {} "pr20103a" \ 541 ] \ 542 [list \ 543 "Build pr20103b" \ 544 "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \ 545 "-O2 -flto" \ 546 {dummy.c} {} "pr20103b" \ 547 ] \ 548 [list \ 549 "Build pr20103c" \ 550 "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \ 551 "-O2" \ 552 {dummy.c} {} "pr20103c" \ 553 ] \ 554 ] 555 pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a" 556 pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a" 557 pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a" 558 559 if { [at_least_gcc_version 4 9] } { 560 run_cc_link_tests [list \ 561 [list \ 562 "Build pr20103d" \ 563 "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \ 564 "-O2" \ 565 {dummy.c} {} "pr20103d" \ 566 ] \ 567 ] 568 pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a" 569 } 570} 571 572restore_notify 573