| 1 | # Expect script for ld-plugin LTO tests |
| 2 | # Copyright (C) 2011-2015 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. |
| 22 | if { ![check_plugin_api_available] |
| 23 | || ![check_lto_available] } { |
| 24 | return |
| 25 | } |
| 26 | |
| 27 | global CFLAGS |
| 28 | global CXXFLAGS |
| 29 | set saved_CFLAGS "$CFLAGS" |
| 30 | set saved_CXXFLAGS "$CXXFLAGS" |
| 31 | regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS |
| 32 | regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS |
| 33 | |
| 34 | proc restore_notify { } { |
| 35 | global saved_CFLAGS |
| 36 | global saved_CXXFLAGS |
| 37 | set CFLAGS "$saved_CFLAGS" |
| 38 | set CXXFLAGS "$saved_CXXFLAGS" |
| 39 | } |
| 40 | |
| 41 | set plugin_names { |
| 42 | liblto_plugin.so |
| 43 | liblto_plugin-0.dll |
| 44 | cyglto_plugin-0.dll |
| 45 | } |
| 46 | set plug_opt "" |
| 47 | foreach 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 | } |
| 57 | set lto_fat "" |
| 58 | if { [check_lto_fat_available] } { |
| 59 | set lto_fat "-ffat-lto-objects" |
| 60 | } |
| 61 | |
| 62 | # Simple LTO tests and generate input files for complex LTO tests. |
| 63 | set lto_link_tests [list \ |
| 64 | [list "LTO 1" \ |
| 65 | "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \ |
| 66 | {lto-1a.c lto-1b.c} {} "lto-1.exe"] \ |
| 67 | [list "Compile 2" \ |
| 68 | "" "-O2 -flto -fuse-linker-plugin" \ |
| 69 | {lto-2.c} {} ""] \ |
| 70 | [list "LTO 2" \ |
| 71 | "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" "" \ |
| 72 | {dummy.c} {} "lto-2.exe"] \ |
| 73 | [list "Compile 3a" \ |
| 74 | "" "-flto" \ |
| 75 | {lto-3a.c} {} ""] \ |
| 76 | [list "Compile 3c" \ |
| 77 | "" "-O2" \ |
| 78 | {lto-3c.c} {} ""] \ |
| 79 | [list "Build liblto-3.a" \ |
| 80 | "" "-flto $lto_fat" \ |
| 81 | {lto-3b.c} {} "liblto-3.a"] \ |
| 82 | [list "Compile 5a" \ |
| 83 | "" "-flto $lto_fat" \ |
| 84 | {lto-5a.c} {} ""] \ |
| 85 | [list "Compile 5b" \ |
| 86 | "" "-flto $lto_fat" \ |
| 87 | {lto-5b.c} {} ""] \ |
| 88 | [list "LTO 6" \ |
| 89 | "-O2 -flto -fuse-linker-plugin" "" \ |
| 90 | {lto-6.c} {} "lto-6.exe" "c"] \ |
| 91 | [list "Compile PR ld/12365" \ |
| 92 | "" "-flto -O2 $lto_fat" \ |
| 93 | {pr12365a.c pr12365b.c pr12365c.c} {} ""] \ |
| 94 | [list "Compile 9" \ |
| 95 | "" "-O2 -finline -flto" \ |
| 96 | {lto-9.cc} {} "" "c++"] \ |
| 97 | [list "Compile 11a" \ |
| 98 | "" "-O -flto" \ |
| 99 | {lto-11a.c} {} ""] \ |
| 100 | [list "Compile 11b" \ |
| 101 | "" "-O -flto" \ |
| 102 | {lto-11b.c} {} ""] \ |
| 103 | [list "Compile 11c" \ |
| 104 | "" "-O" \ |
| 105 | {lto-11c.c} {} ""] \ |
| 106 | [list "Build liblto-12.a" \ |
| 107 | "$plug_opt" "-O2 -flto" \ |
| 108 | {lto-12c.c} {} "liblto-12.a"] \ |
| 109 | [list "Compile 12" \ |
| 110 | "" "-O2 -flto" \ |
| 111 | {lto-12a.c lto-12b.c} {} ""] \ |
| 112 | [list "Compile 13" \ |
| 113 | "" "-O2 -flto" \ |
| 114 | {lto-13a.c lto-13b.c} {} ""] \ |
| 115 | [list "Build liblto-13.a" \ |
| 116 | "" "-O2" \ |
| 117 | {lto-13c.c} {} "liblto-13.a"] \ |
| 118 | [list "Compile 14a" \ |
| 119 | "" "-flto" \ |
| 120 | {lto-14a.c lto-14b.c} {} ""] \ |
| 121 | [list "Build liblto-14.a" \ |
| 122 | "$plug_opt" "-flto" \ |
| 123 | {lto-14c.c} {} "liblto-14.a"] \ |
| 124 | [list "Compile 15a" \ |
| 125 | "" "-flto" \ |
| 126 | {lto-15a.c} {} ""] \ |
| 127 | [list "Build liblto-15.a" \ |
| 128 | "$plug_opt" "-flto" \ |
| 129 | {lto-15b.c} {} "liblto-15.a"] \ |
| 130 | [list "PR ld/12696" \ |
| 131 | "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \ |
| 132 | {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \ |
| 133 | [list "Compile PR ld/12758" \ |
| 134 | "" "" \ |
| 135 | {pr12758a.s} {} ""] \ |
| 136 | [list "Build libpr12758.a" \ |
| 137 | "" "-flto -O2 $lto_fat" \ |
| 138 | {pr12758b.c} {} "libpr12758.a"] \ |
| 139 | [list "PR ld/12758" \ |
| 140 | "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" "" \ |
| 141 | {dummy.c} {} "pr12758.exe"] \ |
| 142 | [list "Compile PR ld/12760" \ |
| 143 | "" "-g -O0" \ |
| 144 | {pr12760a.c} {} ""] \ |
| 145 | [list "Build libpr12760.a" \ |
| 146 | "" "-flto -O2 $lto_fat" \ |
| 147 | {pr12760b.c} {} "libpr12760.a"] \ |
| 148 | [list "PR ld/12760" \ |
| 149 | "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \ |
| 150 | {dummy.c} {} "pr12760.exe" "c" "pr12760a.c:6: warning: Bad bar"] \ |
| 151 | [list "Build libpr13183.a" \ |
| 152 | "-T" "-flto -O2 $lto_fat" \ |
| 153 | {pr13183a.c} {} "libpr13183.a"] \ |
| 154 | [list "Compile PR ld/13183" \ |
| 155 | "" "-flto -O2" \ |
| 156 | {pr13183b.c} {} ""] \ |
| 157 | [list "Compile PR ld/13201" \ |
| 158 | "" "-flto -O2" \ |
| 159 | {pr13201.c} {} ""] \ |
| 160 | [list "PR ld/13287" \ |
| 161 | "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" \ |
| 162 | {pr13287.cc} {} "pr13287.exe" "c++"] \ |
| 163 | [list "PR ld/15323 (1)" \ |
| 164 | "" "-O2" \ |
| 165 | {pr15323a.c} {} "" "c"] \ |
| 166 | [list "PR ld/15323 (2)" \ |
| 167 | "-O2 -flto -r -nostdlib" "-O2 -flto" \ |
| 168 | {pr15323a.c} {} "pr15323a-r.o" "c"] \ |
| 169 | [list "Compile(1) PR ld/pr16846" \ |
| 170 | "" "-flto" \ |
| 171 | {pr16846a.c pr16846b.c} {} ""] \ |
| 172 | [list "Compile(2) PR ld/pr16846" \ |
| 173 | "" "" \ |
| 174 | {pr16846c.c} {} ""] \ |
| 175 | [list "PR ld/pr16846(1)" \ |
| 176 | "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846b.o tmpdir/pr16846c.o" "" \ |
| 177 | {dummy.c} {} "pr16846a.exe"] \ |
| 178 | [list "PR ld/pr16846(2)" \ |
| 179 | "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846c.o tmpdir/pr16846b.o" "" \ |
| 180 | {dummy.c} {} "pr16846b.exe"] \ |
| 181 | ] |
| 182 | |
| 183 | if { [at_least_gcc_version 4 7] } { |
| 184 | set lto_link_tests [concat $lto_link_tests [list \ |
| 185 | [list "Compile PR ld/12942 (1)" \ |
| 186 | "" "-flto -O2" \ |
| 187 | {pr12942a.cc pr12942c.cc} {} "" "c++"] \ |
| 188 | [list "Compile PR ld/12942 (2)" \ |
| 189 | "" "-O0" \ |
| 190 | {pr12942b.cc} {} "" "c++"] \ |
| 191 | ]] |
| 192 | } |
| 193 | |
| 194 | # Generate input files for complex LTO tests for ELF. |
| 195 | set lto_link_elf_tests [list \ |
| 196 | [list "Compile 7" \ |
| 197 | "" "-flto -O2" \ |
| 198 | {lto-7a.c lto-7b.c lto-7c.c} {} ""] \ |
| 199 | [list "Build liblto-7.so" \ |
| 200 | "-shared" "-O2 -fpic" \ |
| 201 | {lto-7d.c} {} "liblto-7.so" "c"] \ |
| 202 | [list "Compile 8a" \ |
| 203 | "" "-O2" \ |
| 204 | {lto-8a.c} {} ""] \ |
| 205 | [list "Compile 8b" \ |
| 206 | "" "-flto -O2" \ |
| 207 | {lto-8b.c} {} ""] \ |
| 208 | [list "Build liblto-17a.so" \ |
| 209 | "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \ |
| 210 | {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \ |
| 211 | [list "Build liblto-17b.so 1" \ |
| 212 | "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \ |
| 213 | {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \ |
| 214 | [list "Build liblto-17b.so 2" \ |
| 215 | "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \ |
| 216 | {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \ |
| 217 | [list "PR ld/12982" \ |
| 218 | "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \ |
| 219 | {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \ |
| 220 | [list "PR ld/12975" \ |
| 221 | "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \ |
| 222 | {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \ |
| 223 | [list "PR ld/13229" \ |
| 224 | "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \ |
| 225 | {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \ |
| 226 | [list "PR ld/13244" \ |
| 227 | "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \ |
| 228 | {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \ |
| 229 | [list "Build libpr15146a.a" \ |
| 230 | "$plug_opt" "-flto -O2" \ |
| 231 | {pr15146a.c} {} "lib15146a.a"] \ |
| 232 | [list "Build pr15146b.so" \ |
| 233 | "-shared" "-O2 -fpic" \ |
| 234 | {pr15146b.c} {} "pr15146b.so" "c"] \ |
| 235 | [list "Build pr15146c.so" \ |
| 236 | "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" \ |
| 237 | {pr15146c.c} {} "pr15146c.so" "c"] \ |
| 238 | [list "PR ld/15146 (1)" \ |
| 239 | "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \ |
| 240 | {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \ |
| 241 | [list "Build libpr15146d.a" \ |
| 242 | "$plug_opt" "-flto -O2" \ |
| 243 | {pr15146d.c} {} "lib15146d.a"] \ |
| 244 | [list "Build libpr16746a.a" \ |
| 245 | "" "" \ |
| 246 | {pr16746a.c pr16746b.c} {} "lib15146a.a"] \ |
| 247 | [list "Build libpr16746b.a" \ |
| 248 | "$plug_opt" "-O2 -flto" \ |
| 249 | {pr16746c.c pr16746d.c} {} "lib15146b.a"] \ |
| 250 | [list "PR ld/16746 (1)" \ |
| 251 | "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \ |
| 252 | {dummy.c} {} "pr16746a.exe"] \ |
| 253 | [list "PR ld/16746 (2)" \ |
| 254 | "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \ |
| 255 | {dummy.c} {} "pr16746b.exe"] \ |
| 256 | [list "PR ld/14918" \ |
| 257 | "-flto" "-flto" \ |
| 258 | {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \ |
| 259 | ] |
| 260 | |
| 261 | # Check final symbols in executables. |
| 262 | set lto_link_symbol_tests [list \ |
| 263 | [list "LTO 3 symbol" \ |
| 264 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \ |
| 265 | {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \ |
| 266 | [list "LTO 5 symbol" \ |
| 267 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \ |
| 268 | {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \ |
| 269 | [list "LTO 9 symbol" \ |
| 270 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \ |
| 271 | {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \ |
| 272 | [list "LTO 16a symbol" \ |
| 273 | "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \ |
| 274 | {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \ |
| 275 | [list "LTO 16b symbol" \ |
| 276 | "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \ |
| 277 | {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \ |
| 278 | [list "PR ld/13183" \ |
| 279 | "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \ |
| 280 | {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \ |
| 281 | ] |
| 282 | |
| 283 | # LTO run-time tests. |
| 284 | set lto_run_tests [list \ |
| 285 | [list "LTO 3a" \ |
| 286 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \ |
| 287 | {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \ |
| 288 | [list "LTO 3b" \ |
| 289 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \ |
| 290 | {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \ |
| 291 | [list "LTO 3c" \ |
| 292 | "-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" "" \ |
| 293 | {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \ |
| 294 | [list "LTO 5" \ |
| 295 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \ |
| 296 | {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \ |
| 297 | [list "LTO 11" \ |
| 298 | "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \ |
| 299 | {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \ |
| 300 | [list "LTO 12a" \ |
| 301 | "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \ |
| 302 | {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \ |
| 303 | [list "LTO 12b" \ |
| 304 | "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \ |
| 305 | {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \ |
| 306 | [list "LTO 13" \ |
| 307 | "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \ |
| 308 | {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \ |
| 309 | [list "LTO 14" \ |
| 310 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \ |
| 311 | {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \ |
| 312 | [list "LTO 15" \ |
| 313 | "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \ |
| 314 | {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \ |
| 315 | [list "PR ld/13066" \ |
| 316 | "-O2 -flto -fuse-linker-plugin" "" \ |
| 317 | {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \ |
| 318 | [list "PR ld/13201" \ |
| 319 | "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \ |
| 320 | {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \ |
| 321 | [list "PR ld/15323 (3)" \ |
| 322 | "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \ |
| 323 | {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \ |
| 324 | [list "PR ld/15323 (4)" \ |
| 325 | "-O2 -flto tmpdir/pr15323a-r.o" "" \ |
| 326 | {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \ |
| 327 | ] |
| 328 | |
| 329 | if { [at_least_gcc_version 4 7] } { |
| 330 | set lto_run_tests [concat $lto_run_tests [list \ |
| 331 | [list "PR ld/12942 (1)" \ |
| 332 | "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \ |
| 333 | {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \ |
| 334 | [list "PR ld/12942 (2)" \ |
| 335 | "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \ |
| 336 | {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \ |
| 337 | ]] |
| 338 | } |
| 339 | |
| 340 | # LTO run-time tests for ELF |
| 341 | set lto_run_elf_tests [list \ |
| 342 | [list "LTO 7" \ |
| 343 | "-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" "" \ |
| 344 | {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \ |
| 345 | [list "LTO 8" \ |
| 346 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \ |
| 347 | {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \ |
| 348 | [list "LTO TLS IE" \ |
| 349 | "-O2 -flto -fuse-linker-plugin" "" \ |
| 350 | {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \ |
| 351 | ] |
| 352 | |
| 353 | run_cc_link_tests $lto_link_tests |
| 354 | |
| 355 | # Restrict these to ELF targets that support shared libs and PIC. |
| 356 | if { [is_elf_format] && [check_lto_shared_available] } { |
| 357 | run_cc_link_tests $lto_link_elf_tests |
| 358 | set testname "PR ld/15146 (2)" |
| 359 | 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"] |
| 360 | if { [ regexp "undefined reference to symbol 'xxx'" $exec_output ] } { |
| 361 | pass $testname |
| 362 | } { |
| 363 | fail $testname |
| 364 | } |
| 365 | set testname "PR ld/16746 (3)" |
| 366 | set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"] |
| 367 | if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } { |
| 368 | pass $testname |
| 369 | } { |
| 370 | fail $testname |
| 371 | } |
| 372 | set testname "PR ld/16746 (4)" |
| 373 | set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"] |
| 374 | if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } { |
| 375 | pass $testname |
| 376 | } { |
| 377 | fail $testname |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | set testname "Build liblto-11.a" |
| 382 | remote_file host delete "tmpdir/liblto-11.a" |
| 383 | set 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"] |
| 384 | if {![string match "" $catch_output]} { |
| 385 | unresolved $testname |
| 386 | restore_notify |
| 387 | return |
| 388 | } |
| 389 | |
| 390 | if { [at_least_gcc_version 4 7] } { |
| 391 | # Check expected LTO linker errors. |
| 392 | # Since the asm symbol name hack in pr12365b.c doesn't work on all |
| 393 | # targets, run PR ld/12365 tests only for known targets. |
| 394 | if { ([istarget "i?86-*-elf*"] |
| 395 | || (([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"]) |
| 396 | && ![istarget "*-*-*aout*"] |
| 397 | && ![istarget "*-*-*oldld*"]) |
| 398 | || [istarget "i?86-*-nacl*"] |
| 399 | || [istarget "x86_64-*-nacl*"] |
| 400 | || [istarget "x86_64-*-linux*"] |
| 401 | || [istarget "amd64-*-linux*"]) } { |
| 402 | set testname "PR ld/12365" |
| 403 | set exec_output [run_host_cmd "$CC" "-O2 -flto -flto-partition=none -fuse-linker-plugin tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"] |
| 404 | if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } { |
| 405 | pass $testname |
| 406 | } { |
| 407 | fail $testname |
| 408 | } |
| 409 | } |
| 410 | set testname "PR ld/12942 (3)" |
| 411 | set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"] |
| 412 | if { [ regexp "undefined reference to `link_error\\(\\)'" $exec_output ] } { |
| 413 | pass $testname |
| 414 | } { |
| 415 | fail $testname |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | # Run "ld -r" to generate inputs for complex LTO tests. |
| 420 | run_dump_test "lto-3r" |
| 421 | remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o" |
| 422 | run_dump_test "lto-5r" |
| 423 | remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o" |
| 424 | |
| 425 | run_cc_link_tests $lto_link_symbol_tests |
| 426 | |
| 427 | # The following tests require running the executable generated by ld. |
| 428 | if ![isnative] { |
| 429 | return |
| 430 | } |
| 431 | |
| 432 | run_ld_link_exec_tests [] $lto_run_tests |
| 433 | |
| 434 | if { [is_elf_format] } { |
| 435 | run_ld_link_exec_tests [] $lto_run_elf_tests |
| 436 | } |
| 437 | |
| 438 | restore_notify |