ld: Properly override compiler flags in tests

Some tests need to be compiled with additional flags.  When binutils is
built and compiled with

CC="gcc -fsanitize=address,undefined" CXX="g++ -fsanitize=address,undefined"

some linker tests fail to disable address sanitizer options since
proc default_ld_compile has

    set ccexe $cc
    set ccparm [string first " " $cc]
    set ccflags ""
    if { $ccparm > 0 } then {
        set ccflags [string range $cc $ccparm end]
        set ccexe [string range $cc 0 $ccparm]
        set cc $ccexe
    }
...
    set cmd "$cc $flags $ccflags -c $source -o $object"

Compiler flags in $CC and $CXX will be the last ones.  Add
CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST to use them in
proc default_ld_compile

    set cflag_test ""
    set cxxflag_test ""
    if {[string match "*++*" $ccexe]} {
        append flags " $CXXFLAGS_FOR_TARGET"
        set cflag_test "$CXXFLAGS_FOR_TARGET_TEST"
    } else {
        append flags " $CFLAGS_FOR_TARGET"
        set cflag_test "$CFLAGS_FOR_TARGET_TEST"
    }
...
    set cmd "$cc $flags $ccflags $cflag_test -c $source -o $object"

so that they will be the last flags passed to compiler.  Also update
run_ld_link_exec_tests and run_cc_link_tests to make
CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST the last flags
passed to compiler.

	* testsuite/config/default.exp (CFLAGS_FOR_TARGET_TEST): New.
	(CXXFLAGS_FOR_TARGET_TEST): Likewise.
	* testsuite/ld-elf/dwarf.exp (CFLAGS_FOR_TARGET): Renamed to ...
	(CFLAGS_FOR_TARGET_TEST): This.
	* testsuite/ld-elf/shared.exp: Save, append and restore
	CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST for
	$build_tests.  Save, append and restore CFLAGS_FOR_TARGET_TEST,
	instead of CFLAGS_FOR_TARGET, for $dlopen_run_tests.
	* testsuite/ld-plugin/plugin.exp (CFLAGS_FOR_TARGET): Renamed to
	...
	(CFLAGS_FOR_TARGET_TEST): This.
	* testsuite/ld-shared/shared.exp (CFLAGS_FOR_TARGET): Renamed to
	...
	(CFLAGS_FOR_TARGET_TEST): This.
	* testsuite/ld-srec/srec.exp (CFLAGS_FOR_TARGET): Renamed to ...
	(CFLAGS_FOR_TARGET_TEST): This.
	(CXXFLAGS_FOR_TARGET): Renamed to ...
	(CXXFLAGS_FOR_TARGET_TEST): This.
	* testsuite/lib/ld-lib.exp (default_ld_compile): Append
	CFLAGS_FOR_TARGET_TEST/CXXFLAGS_FOR_TARGET_TEST to compiler flags.
	(run_ld_link_exec_tests): Append CFLAGS_FOR_TARGET_TEST and
	CXXFLAGS_FOR_TARGET_TEST to compiler.
	(run_cc_link_tests): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
7 files changed