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.
This commit is contained in:
Alan Modra 2014-07-07 13:37:16 +09:30
parent f60ec1cfa8
commit f1d7f4a64c
5 changed files with 93 additions and 108 deletions

View file

@ -1,3 +1,18 @@
2014-07-07 Alan Modra <amodra@gmail.com>
* 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 <amodra@gmail.com> 2014-07-05 Alan Modra <amodra@gmail.com>
* lib/ld-lib.exp (run_ld_link_tests): Stop after assembling objects * lib/ld-lib.exp (run_ld_link_tests): Stop after assembling objects

View file

@ -51,31 +51,24 @@ if ![info exists strip] then {
remote_exec host "mkdir -p tmpdir" remote_exec host "mkdir -p tmpdir"
# Make a symlink from tmpdir/as to the assembler in the build tree, so # Make symlinks from tmpdir/ld to the linker and assembler in the
# that we can use a -B option to gcc to force it to use the newly # build tree, so that we can use a -B option to gcc to force it to use
# built assembler. # the newly built linker and 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.
if {![file isdirectory tmpdir/ld]} then { if {![file isdirectory tmpdir/ld]} then {
catch "exec mkdir tmpdir/ld" status catch "exec mkdir tmpdir/ld" status
catch "exec ln -s ../../ld-new tmpdir/ld/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 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 # load the linker path
set ld_L_opt ""
if {[file exists tmpdir/libpath.exp]} { if {[file exists tmpdir/libpath.exp]} {
load_lib tmpdir/libpath.exp load_lib tmpdir/libpath.exp
foreach dir $libpath { 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] || (![board_info [target_info name] exists multilib_flags] ||
![string match "*-mabi" [board_info [target_info name] 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-*-*] } { if { [istarget rx-*-*] } {

View file

@ -391,28 +391,28 @@ run_ld_link_exec_tests [list "*-*-netbsdelf*"] $run_tests
# Check --no-add-needed and --no-copy-dt-needed-entries # Check --no-add-needed and --no-copy-dt-needed-entries
set testname "--no-add-needed" 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 ] } { if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
pass $testname pass $testname
} { } {
fail $testname fail $testname
} }
set testname "--no-copy-dt-needed-entries" 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 ] } { if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
pass $testname pass $testname
} { } {
fail $testname fail $testname
} }
set testname "--no-add-needed -shared" 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 ] } { if { [ regexp "undefined reference to `bar'" $exec_output ] } {
pass $testname pass $testname
} { } {
fail $testname fail $testname
} }
set testname "--no-copy-dt-needed-entries -shared" 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 ] } { if { [ regexp "undefined reference to `bar'" $exec_output ] } {
pass $testname pass $testname
} { } {

View file

@ -314,7 +314,7 @@ run_cc_link_tests $lto_link_tests
if { [is_elf_format] && [check_lto_shared_available] } { if { [is_elf_format] && [check_lto_shared_available] } {
run_cc_link_tests $lto_link_elf_tests run_cc_link_tests $lto_link_elf_tests
set testname "PR ld/15146 (2)" 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 ] } { if { [ regexp "undefined reference to symbol 'xxx'" $exec_output ] } {
pass $testname pass $testname
} { } {
@ -334,7 +334,7 @@ if {![string match "" $catch_output]} {
if { [at_least_gcc_version 4 7] } { if { [at_least_gcc_version 4 7] } {
# Check expected LTO linker errors. # Check expected LTO linker errors.
set testname "PR ld/12942 (3)" 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 ] } { if { [ regexp "undefined reference to `link_error\\(\\)'" $exec_output ] } {
pass $testname pass $testname
} { } {

View file

@ -79,14 +79,33 @@ proc default_ld_version { ld } {
proc run_host_cmd { prog command } { proc run_host_cmd { prog command } {
global link_output global link_output
global gcc_B_opt
global ld_L_opt
if { ![is_remote host] && [which "$prog"] == 0 } then { if { ![is_remote host] && [which "$prog"] == 0 } then {
perror "$prog does not exist" perror "$prog does not exist"
return 0 return 0
} }
verbose -log "$prog $command" # If we are compiling with gcc, we want to add gcc_B_opt and
set status [remote_exec host [concat sh -c [list "$prog $command 2>&1"]] "" "/dev/null" "ld.tmp"] # 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" remote_upload host "ld.tmp"
set link_output [file_contents "ld.tmp"] set link_output [file_contents "ld.tmp"]
regsub "\n$" $link_output "" link_output 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 } { proc default_ld_simple_link { ld target objects } {
global host_triplet global host_triplet
global gcc_ld_flag
global exec_output global exec_output
set flags ""
if [is_endian_output_format $objects] then { if [is_endian_output_format $objects] then {
set flags [big_or_little_endian] 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 remote_file host delete $target
set exec_output [run_host_cmd "$ld" "$flags -o $target $objects"]
set exec_output [run_host_cmd "$ld" "$ldflags $flags -o $target $objects"]
set exec_output [prune_warnings $exec_output] set exec_output [prune_warnings $exec_output]
# We don't care if we get a warning about a non-existent start # We don't care if we get a warning about a non-existent start
# symbol, since the default linker script might use ENTRY. # 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 regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
if [string match "" $exec_output] then { return [string match "" $exec_output]
return 1
} else {
return 0
}
} }
# Compile an object using cc. # Compile an object using cc.
@ -257,7 +253,7 @@ proc default_ld_compile { cc source object } {
global srcdir global srcdir
global subdir global subdir
global host_triplet global host_triplet
global gcc_gas_flag global gcc_B_opt
set cc_prog $cc set cc_prog $cc
if {[llength $cc_prog] > 1} then { if {[llength $cc_prog] > 1} then {
@ -271,11 +267,12 @@ proc default_ld_compile { cc source object } {
remote_file build delete "$object" remote_file build delete "$object"
remote_file host 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 # If we are compiling with gcc, we want to add gcc_B_opt to flags.
# flags. Rather than determine this in some complex way, we guess # However, if $prog already has -B options, which might be the
# based on the name of the compiler. # case when running gcc out of a build directory, we want our -B
# options to come first.
set ccexe $cc set ccexe $cc
set ccparm [string first " " $cc] set ccparm [string first " " $cc]
set ccflags "" set ccflags ""
@ -284,15 +281,12 @@ proc default_ld_compile { cc source object } {
set ccexe [string range $cc 0 $ccparm] set ccexe [string range $cc 0 $ccparm]
set cc $ccexe 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]} { if {[string match "*++*" $ccexe]} {
set flags "$flags $CXXFLAGS" append flags " $CXXFLAGS"
} else { } else {
set flags "$flags $CFLAGS" append flags " $CFLAGS"
} }
if [board_info [target_info name] exists 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]" 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" remote_upload host "ld.tmp"
set exec_output [file_contents "ld.tmp"] set exec_output [file_contents "ld.tmp"]
remote_file build delete "ld.tmp" remote_file build delete "ld.tmp"
@ -1670,36 +1665,27 @@ proc check_lto_available { } {
global lto_available_saved global lto_available_saved
global CC 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]} { if {![info exists lto_available_saved]} {
# Check if gcc supports -flto -fuse-linker-plugin # Check if gcc supports -flto -fuse-linker-plugin
if { [which $CC] == 0 } { set flags ""
set lto_available_saved 0 if [board_info [target_info name] exists cflags] {
return 0 append flags " [board_info [target_info name] cflags]"
} }
set basename "lto" if [board_info [target_info name] exists ldflags] {
set src ${basename}[pid].c append flags " [board_info [target_info name] ldflags]"
set output ${basename}[pid].out }
set basename "tmpdir/lto[pid]"
set src ${basename}.c
set output ${basename}.out
set f [open $src "w"] set f [open $src "w"]
puts $f "int main() { return 0; }" puts $f "int main() { return 0; }"
close $f close $f
set status [remote_exec host $CC "$flags -B[pwd]/tmpdir/ld/ -flto -ffat-lto-objects -fuse-linker-plugin $src -o $output"] remote_download host $src
if { [lindex $status 0] == 0 } { set lto_available_saved [run_host_cmd_yesno "$CC" "$flags -flto -ffat-lto-objects -fuse-linker-plugin $src -o $output"]
set lto_available_saved 1 remote_file host delete $src
} else { remote_file host delete $output
set lto_available_saved 0
}
file delete $src file delete $src
file delete $output
} }
return $lto_available_saved return $lto_available_saved
} }
@ -1709,36 +1695,27 @@ proc check_lto_shared_available { } {
global lto_shared_available_saved global lto_shared_available_saved
global CC 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]} { if {![info exists lto_shared_available_saved]} {
# Check if gcc supports -flto -fuse-linker-plugin -shared # Check if gcc supports -flto -fuse-linker-plugin -shared
if { [which $CC] == 0 } { set flags ""
set lto_shared_available_saved 0 if [board_info [target_info name] exists cflags] {
return 0 append flags " [board_info [target_info name] cflags]"
} }
set basename "lto_shared" if [board_info [target_info name] exists ldflags] {
set src ${basename}[pid].c append flags " [board_info [target_info name] ldflags]"
set output ${basename}[pid].so }
set basename "tmpdir/lto_shared[pid]"
set src ${basename}.c
set output ${basename}.so
set f [open $src "w"] set f [open $src "w"]
puts $f "" puts $f ""
close $f close $f
set status [remote_exec host $CC "$flags -shared -fPIC -B[pwd]/tmpdir/ld/ -flto -fuse-linker-plugin $src -o $output"] remote_download host $src
if { [lindex $status 0] == 0 } { set lto_shared_available_saved [run_host_cmd_yesno "$CC" "$flags -shared -fPIC -flto -fuse-linker-plugin $src -o $output"]
set lto_shared_available_saved 1 remote_file host delete $src
} else { remote_file host delete $output
set lto_shared_available_saved 0
}
file delete $src file delete $src
file delete $output
} }
return $lto_shared_available_saved return $lto_shared_available_saved
} }