]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
ld: Properly override compiler flags in tests
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 16 Aug 2025 21:49:05 +0000 (14:49 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 18 Aug 2025 20:17:24 +0000 (13:17 -0700)
commit258ebe350e6d8ca1fa388a05789bf47f3d9d9fb4
tree8aa8766576914f53f6c25cb41a744fca877b9f2a
parentb6ebe65cdac1afc15d5459318007be2d1d8832d0
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>
ld/testsuite/config/default.exp
ld/testsuite/ld-elf/dwarf.exp
ld/testsuite/ld-elf/shared.exp
ld/testsuite/ld-plugin/plugin.exp
ld/testsuite/ld-shared/shared.exp
ld/testsuite/ld-srec/srec.exp
ld/testsuite/lib/ld-lib.exp