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.
This commit is contained in:
Clément Chigot
2024-12-09 11:00:07 +01:00
parent e88c452e6f
commit 7edefdf710
2 changed files with 16 additions and 16 deletions

View File

@@ -113,13 +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.
set board_flags [get_board_flags]
# Create executable containing unique symbol.
if ![ld_link "$CC_FOR_TARGET $NOPIE_LDFLAGS $board_flags" "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

@@ -210,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]
@@ -701,12 +712,6 @@ proc run_ld_link_exec_tests { ldtests args } {
global exec_output
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.
set board_flags [get_board_flags]
foreach testitem $ldtests {
set testname [lindex $testitem 0]
set ld_options [lindex $testitem 1]
@@ -786,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_flags $ld_options $objfiles $ld_after "] } {
untested $testname
continue
}
if ![$link_proc $link_cmd $binfile "$board_flags -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
}
}
@@ -867,8 +873,6 @@ proc run_cc_link_tests { ldtests } {
global exec_output
global STATIC_LDFLAGS
set board_flags [get_board_flags]
foreach testitem $ldtests {
set testname [lindex $testitem 0]
set ldflags [lindex $testitem 1]
@@ -975,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_flags $ldflags $objfiles "] } {
untested $testname
continue
}
ld_link $cc_cmd $binfile "$board_flags -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 {