# Expect script for ld-plugin LTO tests
-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
+# Copyright (C) 2011-2020 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils.
#
# MA 02110-1301, USA.
# Check to see if the C and C++ compilers work
-if { [which $CC] == 0 || [which $CXX] == 0 } {
+if { ![check_compiler_available] || [which $CXX] == 0 } {
return
}
regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS
regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS
+global NOSANTIZE_CFLAGS
+
proc restore_notify { } {
global saved_CFLAGS
global saved_CXXFLAGS
"-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \
{lto-1a.c lto-1b.c} {} "lto-1.exe"] \
[list "Compile 2" \
- "" "-O2 -flto -fuse-linker-plugin" \
+ "" "-O2 -flto -fuse-linker-plugin $NOSANTIZE_CFLAGS" \
{lto-2.c} {} ""] \
[list "LTO 2" \
- "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" "" \
+ "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" \
+ "$NOSANTIZE_CFLAGS" \
{dummy.c} {} "lto-2.exe"] \
[list "Compile 3a" \
"" "-flto" \
"" "" \
{pr12758a.s} {} ""] \
[list "Build libpr12758.a" \
- "" "-flto -O2 $lto_fat" \
+ "" "-flto -O2 $lto_fat $NOSANTIZE_CFLAGS" \
{pr12758b.c} {} "libpr12758.a"] \
[list "PR ld/12758" \
- "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" "" \
+ "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" \
+ "$NOSANTIZE_CFLAGS" \
{dummy.c} {} "pr12758.exe"] \
[list "Compile PR ld/12760" \
"" "-g -O0" \
"$plug_opt" "-flto $lto_no_fat" \
{pr19317.c} {} "libpr19317.a"] \
[list "Build pr20276a.o" \
- "" "-fno-lto" \
+ "" "-fno-lto -fcommon" \
{pr20276a.c}] \
[list "Build pr20276b.o" \
- "$plug_opt" "-flto $lto_no_fat" \
+ "$plug_opt" "-flto $lto_no_fat -fcommon" \
{pr20276b.c}] \
[list "Build pr20267a.o" \
- "" "" \
+ "" "-fcommon" \
{pr20267a.c}] \
[list "Build libpr20267a.a" \
- "$plug_opt" "-flto $lto_fat" \
+ "$plug_opt" "-flto $lto_fat -fcommon" \
{pr20267b.c} {} "libpr20267a.a"] \
[list "Build libpr20267b.a" \
- "$plug_opt" "-flto $lto_no_fat" \
+ "$plug_opt" "-flto $lto_no_fat -fcommon" \
{pr20267b.c} {} "libpr20267b.a"] \
[list "Build pr20321" \
"-flto -Wl,-plugin,$plug_so" "-flto" \
[list "Build pr22751.a" \
"$plug_opt" "-flto $lto_no_fat $INT128_CFLAGS" \
{pr22751.c} {} "pr22751.a"] \
+ [list "Build libpr23818.so" \
+ "-shared -flto -g -Wl,-version-script,pr23818.t" \
+ "-g -flto $lto_fat" \
+ {pr23818a.c pr23818b.c} \
+ {{"readelf" {-s --wide} "pr23818.d"}} \
+ "libpr23818.so"] \
+ [list "Build libpr23958.so" \
+ "-shared -flto -Wl,-version-script,pr23958.t" \
+ "-g -flto $lto_fat" \
+ {pr23958.c} \
+ "" \
+ "libpr23958.so"] \
+ [list "Build pr24406-2b.o" \
+ "" "-O2 -fno-lto" \
+ {pr24406-2b.c}] \
]
+if { [at_least_gcc_version 10 0] } {
+ set lto_link_tests [concat $lto_link_tests [list \
+ [list "pr25355.o" \
+ "" \
+ "-flto -fno-common $lto_no_fat" \
+ {pr25355.c} \
+ [list [list "nm" "$plug_opt" "pr25355.d"]]] \
+ ]]
+}
+
if { [at_least_gcc_version 4 7] } {
set lto_link_tests [concat $lto_link_tests [list \
[list "Compile PR ld/12942 (1)" \
[list "Build liblto-17b.so 2" \
"-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
{lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \
- [list "PR ld/12982" \
- "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
- {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
[list "PR ld/12975" \
"-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \
{pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \
[list {Build pr22220main.o} \
{} {-flto} \
{pr22220main.cc} {} {} {c++}] \
+ [list "Build pr24486a.o" \
+ "$plug_opt" "-flto -O2" \
+ {pr24486a.c} {} "" "c"] \
+ [list "Build pr24486b.so" \
+ "-shared" "-O2 -fpic" \
+ {pr24486b.c} {} "pr24486b.so" "c"] \
+ [list "Build pr24486c.so" \
+ "-shared -Wl,--no-as-needed tmpdir/pr24486b.so" "-O2 -fpic" \
+ {pr24486c.c} {} "pr24486c.so" "c"] \
+ [list "PR ld/24486" \
+ "-O2 -flto tmpdir/pr24486a.o tmpdir/pr24486c.so -Wl,--as-needed tmpdir/pr24486b.so" "" \
+ {dummy.c} {} "pr24486.exe"] \
+ [list "Build pr25593a-1.o" \
+ "$plug_opt" "-flto -O2" \
+ {pr25593a-1.c} {} "" "c"] \
+ [list "Build pr25593a-2.o" \
+ "" "-O2" \
+ {pr25593a-2.c} {} "" "c"] \
+ [list "Build pr25593b.o" \
+ "" "-O2" \
+ {pr25593b.c} {} "" "c"] \
+ [list "Build pr25593c.so" \
+ "-shared" "-O2 -fpic" \
+ {pr25593c.c} {} "pr25593c.so" "c"] \
+ [list "Build pr25593d.so" \
+ "-shared" "-O2 -fpic" \
+ {pr25593d.c} {} "pr25593d.so" "c"] \
+ [list "Build pr25593e.so" \
+ "-shared" "-O2 -fpic" \
+ {pr25593e.c} {} "pr25593e.so" "c"] \
+ [list "PR ld/r25593 (LTO)" \
+ "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-1.o tmpdir/pr25593b.o \
+ tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
+ {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593a.exe"] \
+ [list "PR ld/r25593" \
+ "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-2.o tmpdir/pr25593b.o \
+ tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
+ {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593b.exe"] \
+ [list "Build pr25618a.o" \
+ "$plug_opt" "-O2 -flto -fpic" \
+ {pr25618a.cc} {} "" "c++"] \
+ [list "Build pr25618.a" \
+ "$plug_opt" "-O2 -flto -fpic" \
+ {pr25618b.cc} {} "pr25618.a" "c++"] \
+ [list "Build pr25618.so" \
+ "-shared -Wl,--exclude-libs,ALL tmpdir/pr25618a.o tmpdir/pr25618.a" \
+ "-fpic" \
+ {dummy.c} {{readelf {--dyn-syms --wide} pr25618.d}} "pr25618.so" "c++"] \
]
# PR 14918 checks that libgcc is not spuriously included in a shared link of
]]
}
+# PR 12982 checks that an executable stack is not created by default
+# when using the LTO plugin. The HPPA target however requires an
+# executable stack for syscall restarts and signal returns, so we
+# skip this test for that target.
+if { ! [istarget "hppa*-*-*"] } {
+ set lto_link_elf_tests [concat $lto_link_elf_tests [list \
+ [list "PR ld/12982" \
+ "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
+ {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
+ ]]
+}
+
# Check final symbols in executables.
set lto_link_symbol_tests [list \
[list "LTO 3 symbol" \
"-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \
{dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \
[list "Run pr20267a" \
- "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
- {dummy.c} "pr20267a" "pass.out" "-flto -O2" "c"] \
+ "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
+ {dummy.c} "pr20267a" "pass.out" "-flto -O2 -fcommon" "c"] \
[list "Run pr20267b" \
- "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
- {dummy.c} "pr20267b" "pass.out" "-flto -O2" "c"] \
+ "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
+ {dummy.c} "pr20267b" "pass.out" "-flto -O2 -fcommon" "c"] \
[list "Run pr22502" \
"-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
- {dummy.c} "pr20267" "pass.out" "-flto -O2" "c"] \
+ {dummy.c} "pr20267" "pass.out" "-flto -O2 -fcommon" "c"] \
[list "Run pr22751" \
"-O2 -flto" "" \
{dummy.c} "pr22751" "pass.out" "-flto -O2" "c" "" \
"-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive"] \
+ [list "Run pr24406-1" \
+ "-O2 -flto" "" \
+ {pr24406-1.c} "pr24406-1" "pass.out" "-flto -O2" "c" "" \
+ "-Wl,--wrap=read"] \
+ [list "Run pr24406-2" \
+ "-O2 -flto" "" \
+ {pr24406-2a.c} "pr24406-2" "pass.out" \
+ "-flto -O2" "c" "" \
+ "tmpdir/pr24406-2b.o -Wl,--wrap=cook"] \
]
if { [at_least_gcc_version 4 7] } {
|| [istarget "amd64-*-linux*"]) } {
set testname "PR ld/12365"
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"]
+ set exec_output [prune_warnings $exec_output]
if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
# Linker should catch the reference to undefined `my_bcopy'
# error caused by a GCC bug.
} {
fail $testname
}
+
+ run_cc_link_tests [list \
+ [list \
+ "Build pr23460*.o" \
+ "$plug_opt" \
+ "-O2 -fPIC -flto $lto_no_fat" \
+ {pr23460a.c pr23460b.c pr23460c.c \
+ pr23460d.c pr23460e.c pr23460f.c} \
+ ] \
+ ]
+ set exec_output [run_host_cmd "sh" \
+ "-c \"ulimit -n 16; \
+ $ar -rc $plug_opt \
+ tmpdir/libpr23460.a \
+ tmpdir/pr23460a.o \
+ tmpdir/pr23460b.o \
+ tmpdir/pr23460c.o \
+ tmpdir/pr23460d.o \
+ tmpdir/pr23460e.o \
+ tmpdir/pr23460f.o\""]
+ set exec_output [prune_warnings $exec_output]
+ if [string match "" $exec_output] then {
+ pass "PR binutils/23460"
+ } else {
+ fail "PR binutils/23460"
+ }
}
# Run "ld -r" to generate inputs for complex LTO tests.