From f1d7f4a64c4d92911127abe6dbab95a219405c2b Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 7 Jul 2014 13:37:16 +0930 Subject: [PATCH] Ensure ld testsuite gcc -B options precede $CC -B options Various ld-elf/shared.exp and ld-plugin/lto.exp tests simply appended the testsuite -B options intended to force gcc use the linker under test. This fails if $CC itself has -B options, as when setting CC to run gcc out of a build directory. Net result is that tests were run using the gcc build dir collect-ld. * config/default.exp: Don't make tmpdir/gas. Put as symlink into tmpdir/ld. (gcc_gas_flag, gcc_ld_flag): Delete. (gcc_B_opt, ld_L_opt): New globals. ld-elf/shared.exp: Remove all refs to gcc_gas_flag and gcc_ld_flag. ld-plugin/lto.exp: Likewise. lib/ld-lib.exp (run_host_cmd): Add gcc_B_opt and ld_L_opt here. (ld_simple_link): Remove -B handling now that this is done in run_host_cmd. Simplify. (default_ld_compile): Simplify. (check_lto_available): Use run_host_cmd_yesno. (check_lto_shared_available): Likewise. --- ld/testsuite/ChangeLog | 15 ++++ ld/testsuite/config/default.exp | 23 +++--- ld/testsuite/ld-elf/shared.exp | 8 +-- ld/testsuite/ld-plugin/lto.exp | 4 +- ld/testsuite/lib/ld-lib.exp | 151 +++++++++++++++++----------------------- 5 files changed, 93 insertions(+), 108 deletions(-) diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index f95fcbd..8877311 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,18 @@ +2014-07-07 Alan Modra + + * config/default.exp: Don't make tmpdir/gas. Put as symlink into + tmpdir/ld. + (gcc_gas_flag, gcc_ld_flag): Delete. + (gcc_B_opt, ld_L_opt): New globals. + ld-elf/shared.exp: Remove all refs to gcc_gas_flag and gcc_ld_flag. + ld-plugin/lto.exp: Likewise. + lib/ld-lib.exp (run_host_cmd): Add gcc_B_opt and ld_L_opt here. + (ld_simple_link): Remove -B handling now that this is done in + run_host_cmd. Simplify. + (default_ld_compile): Simplify. + (check_lto_available): Use run_host_cmd_yesno. + (check_lto_shared_available): Likewise. + 2014-07-05 Alan Modra * lib/ld-lib.exp (run_ld_link_tests): Stop after assembling objects diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp index 8b776a6..09b2626 100644 --- a/ld/testsuite/config/default.exp +++ b/ld/testsuite/config/default.exp @@ -51,31 +51,24 @@ if ![info exists strip] then { remote_exec host "mkdir -p tmpdir" -# Make a symlink from tmpdir/as to the assembler in the build tree, so -# that we can use a -B option to gcc to force it to use the newly -# built assembler. -if {![file isdirectory tmpdir/gas]} then { - catch "exec mkdir tmpdir/gas" status - catch "exec ln -s ../../../gas/as-new tmpdir/gas/as" status -} -set gcc_gas_flag "-B[pwd]/tmpdir/gas/" - -# Make a symlink from tmpdir/ld to the linker in the build tree, so -# that we can use a -B option to gcc to force it to use the newly -# built linker. +# Make symlinks from tmpdir/ld to the linker and assembler in the +# build tree, so that we can use a -B option to gcc to force it to use +# the newly built linker and assembler. if {![file isdirectory tmpdir/ld]} then { catch "exec mkdir tmpdir/ld" status catch "exec ln -s ../../ld-new tmpdir/ld/ld" status catch "exec ln -s ld tmpdir/ld/collect-ld" status + catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status } -set gcc_ld_flag "-B[pwd]/tmpdir/ld/" +set gcc_B_opt "-B[pwd]/tmpdir/ld/" # load the linker path +set ld_L_opt "" if {[file exists tmpdir/libpath.exp]} { load_lib tmpdir/libpath.exp foreach dir $libpath { - set gcc_ld_flag "$gcc_ld_flag -L$dir" + append ld_L_opt " -L$dir" } } @@ -103,7 +96,7 @@ if {[istarget mips64*-*-linux*] && (![board_info [target_info name] exists multilib_flags] || ![string match "*-mabi" [board_info [target_info name] multilib_flags]]) } { - append gcc_gas_flag " -mabi=n32" + append gcc_B_opt " -mabi=n32" } if { [istarget rx-*-*] } { diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index 0763cd4..de2a5f2 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -391,28 +391,28 @@ run_ld_link_exec_tests [list "*-*-netbsdelf*"] $run_tests # Check --no-add-needed and --no-copy-dt-needed-entries set testname "--no-add-needed" -set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"] +set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"] if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } { pass $testname } { fail $testname } set testname "--no-copy-dt-needed-entries" -set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"] +set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"] if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } { pass $testname } { fail $testname } set testname "--no-add-needed -shared" -set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"] +set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"] if { [ regexp "undefined reference to `bar'" $exec_output ] } { pass $testname } { fail $testname } set testname "--no-copy-dt-needed-entries -shared" -set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"] +set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"] if { [ regexp "undefined reference to `bar'" $exec_output ] } { pass $testname } { diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index e7f4427..b14f13c 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -314,7 +314,7 @@ run_cc_link_tests $lto_link_tests if { [is_elf_format] && [check_lto_shared_available] } { run_cc_link_tests $lto_link_elf_tests set testname "PR ld/15146 (2)" - set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"] + set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"] if { [ regexp "undefined reference to symbol 'xxx'" $exec_output ] } { pass $testname } { @@ -334,7 +334,7 @@ if {![string match "" $catch_output]} { if { [at_least_gcc_version 4 7] } { # Check expected LTO linker errors. set testname "PR ld/12942 (3)" - set exec_output [run_host_cmd "$CXX" "$gcc_gas_flag $gcc_ld_flag -O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"] + set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"] if { [ regexp "undefined reference to `link_error\\(\\)'" $exec_output ] } { pass $testname } { diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index 5b3e01d..a657a97 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -79,14 +79,33 @@ proc default_ld_version { ld } { proc run_host_cmd { prog command } { global link_output + global gcc_B_opt + global ld_L_opt if { ![is_remote host] && [which "$prog"] == 0 } then { perror "$prog does not exist" return 0 } - verbose -log "$prog $command" - set status [remote_exec host [concat sh -c [list "$prog $command 2>&1"]] "" "/dev/null" "ld.tmp"] + # If we are compiling with gcc, we want to add gcc_B_opt and + # ld_L_opt to flags. However, if $prog already has -B options, + # which might be the case when running gcc out of a build + # directory, we want our -B options to come first. + set gccexe $prog + set gccparm [string first " " $gccexe] + set gccflags "" + if { $gccparm > 0 } then { + set gccflags [string range $gccexe $gccparm end] + set gccexe [string range $gccexe 0 $gccparm] + set prog $gccexe + } + set gccexe [string replace $gccexe 0 [string last "/" $gccexe] ""] + if {[string match "*cc*" $gccexe] || [string match "*++*" $gccexe]} then { + set gccflags "$gcc_B_opt $gccflags $ld_L_opt" + } + + verbose -log "$prog $gccflags $command" + set status [remote_exec host [concat sh -c [list "$prog $gccflags $command 2>&1"]] "" "/dev/null" "ld.tmp"] remote_upload host "ld.tmp" set link_output [file_contents "ld.tmp"] regsub "\n$" $link_output "" link_output @@ -208,45 +227,22 @@ proc default_ld_link { ld target objects } { # proc default_ld_simple_link { ld target objects } { global host_triplet - global gcc_ld_flag global exec_output + set flags "" if [is_endian_output_format $objects] then { set flags [big_or_little_endian] - } else { - set flags "" - } - - # If we are compiling with gcc, we want to add gcc_ld_flag to - # flags. Rather than determine this in some complex way, we guess - # based on the name of the compiler. - set ldexe $ld - set ldparm [string first " " $ld] - set ldflags "" - if { $ldparm > 0 } then { - set ldflags [string range $ld $ldparm end] - set ldexe [string range $ld 0 $ldparm] - set ld $ldexe - } - set ldexe [string replace $ldexe 0 [string last "/" $ldexe] ""] - if {[string match "*gcc*" $ldexe] || [string match "*++*" $ldexe]} then { - set ldflags "$gcc_ld_flag $ldflags" } remote_file host delete $target - - set exec_output [run_host_cmd "$ld" "$ldflags $flags -o $target $objects"] + set exec_output [run_host_cmd "$ld" "$flags -o $target $objects"] set exec_output [prune_warnings $exec_output] # We don't care if we get a warning about a non-existent start # symbol, since the default linker script might use ENTRY. regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output - if [string match "" $exec_output] then { - return 1 - } else { - return 0 - } + return [string match "" $exec_output] } # Compile an object using cc. @@ -257,7 +253,7 @@ proc default_ld_compile { cc source object } { global srcdir global subdir global host_triplet - global gcc_gas_flag + global gcc_B_opt set cc_prog $cc if {[llength $cc_prog] > 1} then { @@ -271,11 +267,12 @@ proc default_ld_compile { cc source object } { remote_file build delete "$object" remote_file host delete "$object" - set flags "-I$srcdir/$subdir" + set flags "$gcc_B_opt -I$srcdir/$subdir" - # If we are compiling with gcc, we want to add gcc_gas_flag to - # flags. Rather than determine this in some complex way, we guess - # based on the name of the compiler. + # If we are compiling with gcc, we want to add gcc_B_opt to flags. + # However, if $prog already has -B options, which might be the + # case when running gcc out of a build directory, we want our -B + # options to come first. set ccexe $cc set ccparm [string first " " $cc] set ccflags "" @@ -284,15 +281,12 @@ proc default_ld_compile { cc source object } { set ccexe [string range $cc 0 $ccparm] set cc $ccexe } - set ccexe [string replace $ccexe 0 [string last "/" $ccexe] ""] - if {[string match "*gcc*" $ccexe] || [string match "*++*" $ccexe]} then { - set flags "$gcc_gas_flag $flags" - } + set ccexe [string replace $ccexe 0 [string last "/" $ccexe] ""] if {[string match "*++*" $ccexe]} { - set flags "$flags $CXXFLAGS" + append flags " $CXXFLAGS" } else { - set flags "$flags $CFLAGS" + append flags " $CFLAGS" } if [board_info [target_info name] exists cflags] { @@ -303,9 +297,10 @@ proc default_ld_compile { cc source object } { append flags " [board_info [target_info name] multilib_flags]" } - verbose -log "$cc $flags $ccflags -c $source -o $object" + set cmd "$cc $flags $ccflags -c $source -o $object" + verbose -log "$cmd" - set status [remote_exec host [concat sh -c [list "$cc $flags $ccflags -c $source -o $object 2>&1"]] "" "/dev/null" "ld.tmp"] + set status [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"] remote_upload host "ld.tmp" set exec_output [file_contents "ld.tmp"] remote_file build delete "ld.tmp" @@ -1670,36 +1665,27 @@ proc check_lto_available { } { global lto_available_saved global CC - set flags "" - - if [board_info [target_info name] exists cflags] { - append flags " [board_info [target_info name] cflags]" - } - - if [board_info [target_info name] exists ldflags] { - append flags " [board_info [target_info name] ldflags]" - } - if {![info exists lto_available_saved]} { # Check if gcc supports -flto -fuse-linker-plugin - if { [which $CC] == 0 } { - set lto_available_saved 0 - return 0 + set flags "" + if [board_info [target_info name] exists cflags] { + append flags " [board_info [target_info name] cflags]" + } + if [board_info [target_info name] exists ldflags] { + append flags " [board_info [target_info name] ldflags]" } - set basename "lto" - set src ${basename}[pid].c - set output ${basename}[pid].out + + set basename "tmpdir/lto[pid]" + set src ${basename}.c + set output ${basename}.out set f [open $src "w"] puts $f "int main() { return 0; }" close $f - set status [remote_exec host $CC "$flags -B[pwd]/tmpdir/ld/ -flto -ffat-lto-objects -fuse-linker-plugin $src -o $output"] - if { [lindex $status 0] == 0 } { - set lto_available_saved 1 - } else { - set lto_available_saved 0 - } + remote_download host $src + set lto_available_saved [run_host_cmd_yesno "$CC" "$flags -flto -ffat-lto-objects -fuse-linker-plugin $src -o $output"] + remote_file host delete $src + remote_file host delete $output file delete $src - file delete $output } return $lto_available_saved } @@ -1709,36 +1695,27 @@ proc check_lto_shared_available { } { global lto_shared_available_saved global CC - set flags "" - - if [board_info [target_info name] exists cflags] { - append flags " [board_info [target_info name] cflags]" - } - - if [board_info [target_info name] exists ldflags] { - append flags " [board_info [target_info name] ldflags]" - } - if {![info exists lto_shared_available_saved]} { # Check if gcc supports -flto -fuse-linker-plugin -shared - if { [which $CC] == 0 } { - set lto_shared_available_saved 0 - return 0 + set flags "" + if [board_info [target_info name] exists cflags] { + append flags " [board_info [target_info name] cflags]" + } + if [board_info [target_info name] exists ldflags] { + append flags " [board_info [target_info name] ldflags]" } - set basename "lto_shared" - set src ${basename}[pid].c - set output ${basename}[pid].so + + set basename "tmpdir/lto_shared[pid]" + set src ${basename}.c + set output ${basename}.so set f [open $src "w"] puts $f "" close $f - set status [remote_exec host $CC "$flags -shared -fPIC -B[pwd]/tmpdir/ld/ -flto -fuse-linker-plugin $src -o $output"] - if { [lindex $status 0] == 0 } { - set lto_shared_available_saved 1 - } else { - set lto_shared_available_saved 0 - } + remote_download host $src + set lto_shared_available_saved [run_host_cmd_yesno "$CC" "$flags -shared -fPIC -flto -fuse-linker-plugin $src -o $output"] + remote_file host delete $src + remote_file host delete $output file delete $src - file delete $output } return $lto_shared_available_saved } -- 2.7.4