]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld/testsuite: move board flags to ld_link
authorClément Chigot <chigot@adacore.com>
Mon, 9 Dec 2024 10:00:07 +0000 (11:00 +0100)
committerClément Chigot <chigot@adacore.com>
Tue, 7 Jan 2025 13:07:19 +0000 (14:07 +0100)
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.

ld/testsuite/ld-unique/unique.exp
ld/testsuite/lib/ld-lib.exp

index 855e25509fd6432128d02f9c0a8e035472f0b0fb..fe77516eaac7409c8a412f45ee6925644411d4f1 100644 (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]
 }
index bd2dd50ae47113b6452bb6665043b68c45641ae9..55f26d6cddf383ae0b14545e52eb0bb88b0c11dc 100644 (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 {