[PATCH 3/3] ld/testsuite: move board flags to ld_link

Alan Modra amodra@gmail.com
Tue Jan 7 10:52:21 GMT 2025


On Mon, Jan 06, 2025 at 02:28:30PM +0100, Clément Chigot wrote:
> 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.

OK.

> ---
>  ld/testsuite/ld-unique/unique.exp |  7 +------
>  ld/testsuite/lib/ld-lib.exp       | 25 +++++++++++++++----------
>  2 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/ld/testsuite/ld-unique/unique.exp b/ld/testsuite/ld-unique/unique.exp
> index 855e25509fd..fe77516eaac 100644
> --- a/ld/testsuite/ld-unique/unique.exp
> +++ b/ld/testsuite/ld-unique/unique.exp
> @@ -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]
>  }
> diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
> index bd2dd50ae47..55f26d6cddf 100644
> --- a/ld/testsuite/lib/ld-lib.exp
> +++ b/ld/testsuite/lib/ld-lib.exp
> @@ -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 {
> -- 
> 2.34.1

-- 
Alan Modra


More information about the Binutils mailing list