Compare commits

...

3 Commits

Author SHA1 Message Date
Clément Chigot
7edefdf710 ld/testsuite: move board flags to ld_link
Both CFLAGS and LDFLAGS provided by dejagnu board configuration could be
required to perform a link.

Up to now, those flags were pulled with run_cc_link_tests and
run_ld_link_exec_tests and then passed to ld_link process as arguments.
This means that calling `ld_link` outside those functions must remember
to manually pass them.
2025-01-06 14:01:09 +01:00
Clément Chigot
e88c452e6f ld/testsuite/lto: replace manual links by ld_link helper
Some tests are calling run_host_cmd in order to retrieve the
errors/warnings messages generated.
ld_link is also making them available through exec_output global
variable but as the advantages of taking the board configuration into
account unlike run_host_cmd.
2025-01-06 14:01:09 +01:00
Clément Chigot
05dce2c841 ld/testsuite: centralize board_cflags and board_ldflags
Those flags are retrieving the CFLAGS or LDFLAGS defined by the dejagnu
board. The same pattern was repeated many times.
2025-01-06 14:01:09 +01:00
3 changed files with 67 additions and 129 deletions

View File

@@ -29,6 +29,8 @@ if { ![check_plugin_api_available]
return
}
global exec_output
set saved_CFLAGS "$CFLAGS_FOR_TARGET"
set saved_CXXFLAGS "$CXXFLAGS_FOR_TARGET"
regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS_FOR_TARGET "" CFLAGS_FOR_TARGET
@@ -905,10 +907,8 @@ run_cc_link_tests $lto_compile_elf_tests
#
# Update LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook
#
set exec_output [run_host_cmd "$CC_FOR_TARGET" \
"-O2 -fcommon -flto -o tmpdir/common-2 \
tmpdir/common-2a.o tmpdir/libcommon-2.a \
tmpdir/libcommon-2.a"]
ld_link "$CC_FOR_TARGET" pr32083.exe "-O2 -fcommon -flto -o tmpdir/common-2 \
tmpdir/common-2a.o tmpdir/libcommon-2.a tmpdir/libcommon-2.a"
if [string match "" $exec_output] then {
pass "PR ld/32083"
} elseif { [ regexp "lto1: fatal error: multiple prevailing defs for 'func'" $exec_output ] } {
@@ -919,23 +919,25 @@ if [string match "" $exec_output] then {
# Restrict these to ELF targets that support shared libs and PIC.
if { [is_elf_format] && [check_lto_shared_available] } {
global exec_output
run_cc_link_tests $lto_link_elf_tests
set testname "PR ld/15146 (2)"
set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"]
ld_link "$CC_FOR_TARGET" pr15146-2.exe "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"
if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
pass $testname
} {
fail $testname
}
set testname "PR ld/16746 (3)"
set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
ld_link "$CC_FOR_TARGET" pr16746-3.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"
if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
pass $testname
} {
fail $testname
}
set testname "PR ld/16746 (4)"
set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
ld_link "$CC_FOR_TARGET" pr16746-4.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"
if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
pass $testname
} {
@@ -957,10 +959,11 @@ run_cc_link_tests [list \
] \
]
set board_flags [get_board_flags]
set exec_output [run_host_cmd "sh" \
"-c \"ulimit -n 20; \
$CC_FOR_TARGET $gcc_B_opt $CFLAGS_FOR_TARGET \
$ld_L_opt -o tmpdir/pr28138 \
$board_flags $ld_L_opt -o tmpdir/pr28138 \
tmpdir/pr28138.o tmpdir/pr28138.a\""]
set exec_output [prune_warnings $exec_output]
if [string match "" $exec_output] then {
@@ -991,14 +994,15 @@ if { [at_least_gcc_version 4 7] } {
# Check expected LTO linker errors.
# Since the asm symbol name hack in pr12365b.c doesn't work on all
# targets, run PR ld/12365 tests only for known targets.
global exec_output
if { ([istarget "i?86-*-elf*"]
|| [istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
|| [istarget "x86_64-*-linux*"]
|| [istarget "amd64-*-linux*"]) } {
set testname "PR ld/12365"
set exec_output [run_host_cmd "$CC_FOR_TARGET" "-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]
ld_link "$CC_FOR_TARGET" pr12365.exe "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"
if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
# Linker should catch the reference to undefined `my_bcopy'
# error caused by a GCC bug.
@@ -1045,7 +1049,7 @@ if { [at_least_gcc_version 4 7] } {
]
}
set testname "PR ld/12942 (3)"
set exec_output [run_host_cmd "$CXX_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
ld_link "$CXX_FOR_TARGET" pr12942-3.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"
if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
pass $testname
} {
@@ -1138,9 +1142,10 @@ if { [is_elf_format] && [check_lto_shared_available] } {
proc pr20103 {cflags libs} {
global CC_FOR_TARGET
global exec_output
set testname "PR ld/20103 ($cflags $libs)"
set exec_output [run_host_cmd "$CC_FOR_TARGET" "$cflags $libs"]
ld_link "$CC_FOR_TARGET" pr20103.exe "$cflags $libs"
# NB: Starting from GCC 4.9, -flto is optional for final link.
if { [ regexp "fatpr20103" "$libs" ] \
&& ([regexp " -flto" "$cflags"] \

View File

@@ -113,23 +113,8 @@ if ![ld_compile "$CC_FOR_TARGET -c" "$srcdir/$subdir/unique_empty.s" "tmpdir/uni
set fails [expr $fails + 1]
}
# When using GCC as the linker driver, we need to specify board cflags when
# linking because cflags may contain linker options. For example when linker
# options are included in GCC spec files then we need the -specs option.
if [board_info [target_info name] exists cflags] {
set board_cflags " [board_info [target_info name] cflags]"
} else {
set board_cflags ""
}
if [board_info [target_info name] exists ldflags] {
set board_ldflags " [board_info [target_info name] ldflags]"
} else {
set board_ldflags ""
}
# Create executable containing unique symbol.
if ![ld_link "$CC_FOR_TARGET $NOPIE_LDFLAGS $board_cflags $board_ldflags" "tmpdir/unique_prog" "tmpdir/unique.o"] {
if ![ld_link "$CC_FOR_TARGET $NOPIE_LDFLAGS" "tmpdir/unique_prog" "tmpdir/unique.o"] {
fail "Could not link a unique executable"
set fails [expr $fails + 1]
}

View File

@@ -177,6 +177,28 @@ proc is_endian_output_format { object_flags } {
}
}
# Return flags as defined within board_info
#
proc get_board_flags {} {
global board_cflags
global board_ldflags
if [board_info [target_info name] exists cflags] {
set board_cflags " [board_info [target_info name] cflags]"
} else {
set board_cflags ""
}
if [board_info [target_info name] exists ldflags] {
set board_ldflags " [board_info [target_info name] ldflags]"
} else {
set board_ldflags ""
}
return "$board_cflags $board_ldflags"
}
# Link a program using ld
#
proc default_ld_link { ld target objects } {
@@ -188,6 +210,17 @@ proc default_ld_link { ld target objects } {
set flags [big_or_little_endian]
}
# When using GCC as the linker driver, we need to specify board cflags when
# linking because cflags may contain linker options. For example when
# linker options are included in GCC spec files then we need the -specs
# option.
set gccexe [string replace $ld 0 [string last "/" $ld] ""]
if {[string match "*cc*" $gccexe] ||
[string match "*++*" $gccexe] ||
[string match "clang*" $gccexe]} then {
set flags "$flags [get_board_flags]"
}
remote_file host delete $target
set exec_output [run_host_cmd "$ld" "$flags -o $target $objects"]
set exec_output [prune_warnings $exec_output]
@@ -677,26 +710,8 @@ proc run_ld_link_exec_tests { ldtests args } {
global CXX_FOR_TARGET
global errcnt
global exec_output
global board_cflags
global board_ldflags
global STATIC_LDFLAGS
# When using GCC as the linker driver, we need to specify board cflags when
# linking because cflags may contain linker options. For example when
# linker options are included in GCC spec files then we need the -specs
# option.
if [board_info [target_info name] exists cflags] {
set board_cflags " [board_info [target_info name] cflags]"
} else {
set board_cflags ""
}
if [board_info [target_info name] exists ldflags] {
set board_ldflags " [board_info [target_info name] ldflags]"
} else {
set board_ldflags ""
}
foreach testitem $ldtests {
set testname [lindex $testitem 0]
set ld_options [lindex $testitem 1]
@@ -776,12 +791,13 @@ proc run_ld_link_exec_tests { ldtests args } {
pass $testname
continue;
} else {
set board_flags [get_board_flags]
if { [string match "" $STATIC_LDFLAGS] \
&& [regexp -- ".* \[-\]+static .*" " $board_cflags $board_ldflags $ld_options $objfiles $ld_after "] } {
&& [regexp -- ".* \[-\]+static .*" " $board_flags $ld_options $objfiles $ld_after "] } {
untested $testname
continue
}
if ![$link_proc $link_cmd $binfile "$board_cflags $board_ldflags -L$srcdir/$subdir $ld_options $objfiles $ld_after"] {
if ![$link_proc $link_cmd $binfile " -L$srcdir/$subdir $ld_options $objfiles $ld_after"] {
set failed 1
}
}
@@ -855,22 +871,8 @@ proc run_cc_link_tests { ldtests } {
global CXX_FOR_TARGET
global ar
global exec_output
global board_cflags
global board_ldflags
global STATIC_LDFLAGS
if [board_info [target_info name] exists cflags] {
set board_cflags " [board_info [target_info name] cflags]"
} else {
set board_cflags ""
}
if [board_info [target_info name] exists ldflags] {
set board_ldflags " [board_info [target_info name] ldflags]"
} else {
set board_ldflags ""
}
foreach testitem $ldtests {
set testname [lindex $testitem 0]
set ldflags [lindex $testitem 1]
@@ -977,12 +979,13 @@ proc run_cc_link_tests { ldtests } {
set failed 1
}
} else {
set board_flags [get_board_flags]
if { [string match "" $STATIC_LDFLAGS] \
&& [regexp -- ".* \[-\]+static .*" " $board_cflags $board_ldflags $ldflags $objfiles "] } {
&& [regexp -- ".* \[-\]+static .*" " $board_flags $ldflags $objfiles "] } {
untested $testname
continue
}
ld_link $cc_cmd $binfile "$board_cflags $board_ldflags -L$srcdir/$subdir $ldflags $objfiles"
ld_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"
set ld_output "$exec_output"
if { $check_ld(source) == "regexp" } then {
@@ -1113,8 +1116,8 @@ proc check_gc_sections_available { } {
# elf2flt uses -q (--emit-relocs), which is incompatible with
# --gc-sections.
if { [board_info target exists ldflags]
&& [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
set board_flags [get_board_flags]
if { [regexp " (-Wl,)*-elf2flt\[ =\]" " $board_flags "] } {
set gc_sections_available_saved 0
return 0
}
@@ -1227,14 +1230,7 @@ proc check_compiler_available { } {
return 0
}
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set flags [get_board_flags]
set basename "tmpdir/compiler[pid]"
set src ${basename}.c
set output ${basename}.out
@@ -1300,14 +1296,7 @@ proc check_lto_available { } {
return 1
}
# Check if gcc supports -flto -fuse-linker-plugin
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set flags [get_board_flags]
set basename "tmpdir/lto[pid]"
set src ${basename}.c
set output ${basename}.out
@@ -1343,14 +1332,7 @@ proc check_lto_fat_available { } {
return 1
}
# Check if gcc supports -flto -fuse-linker-plugin
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set flags [get_board_flags]
set basename "tmpdir/lto[pid]"
set src ${basename}.c
set output ${basename}.out
@@ -1386,14 +1368,7 @@ proc check_lto_shared_available { } {
return 1
}
# Check if gcc supports -flto -fuse-linker-plugin -shared
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set flags [get_board_flags]
set basename "tmpdir/lto_shared[pid]"
set src ${basename}.c
set output ${basename}.so
@@ -1445,14 +1420,7 @@ proc check_ifunc_available { } {
return 0
}
# Check if gcc supports -flto -fuse-linker-plugin
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set flags [get_board_flags]
set basename "tmpdir/ifunc[pid]"
set src ${basename}.c
set output ${basename}.out
@@ -1494,14 +1462,7 @@ proc check_ifunc_attribute_available { } {
return 0
}
# Check if gcc supports -flto -fuse-linker-plugin
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set flags [get_board_flags]
set basename "tmpdir/ifunc[pid]"
set src ${basename}.c
set output ${basename}.out
@@ -1577,14 +1538,7 @@ proc check_gnu2_tls_available { } {
return 0
}
# Check if GNU2 TLS works.
set flags "$GNU2_CFLAGS"
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set flags "$GNU2_CFLAGS [get_board_flags]"
set basename "tmpdir/gnu2_tls[pid]"
set src1 ${basename}1.c
set output1 ${basename}.so
@@ -1633,13 +1587,7 @@ proc compile_one_cc { src output additional_flags } {
global CC_FOR_TARGET
global CFLAGS_FOR_TARGET
set flags ""
if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]"
}
if [board_info [target_info name] exists ldflags] {
append flags " [board_info [target_info name] ldflags]"
}
set flags [get_board_flags]
if [is_remote host] {
set src [remote_download host $src]