Wrong ELF class plugin vs. gcc ld version

When building 32-bit binutils with CC="gcc -m32" CXX="g++ -m32" we can
fail the gcc ld version test due to an error attempting to load a
64-bit plugin into 32-bit ld-new.  This results in bogus errors about
"Your compiler driver ignores -B when choosing ld."

	* testsuite/lib/ld-lib.exp: Whitespace.
	(load_common_lib): Expand single use and delete this proc.
	(run_host_cmd): Use -fno-lto when getting gcc's ld version.
	Use -B for clang too.
This commit is contained in:
Alan Modra
2021-02-18 14:43:14 +10:30
parent 0be51eb4c3
commit 2f973f134d
2 changed files with 79 additions and 72 deletions

View File

@ -1,3 +1,10 @@
2021-02-19 Alan Modra <amodra@gmail.com>
* testsuite/lib/ld-lib.exp: Whitespace.
(load_common_lib): Expand single use and delete this proc.
(run_host_cmd): Use -fno-lto when getting gcc's ld version.
Use -B for clang too.
2021-02-18 Andrew Burgess <andrew.burgess@embecosm.com> 2021-02-18 Andrew Burgess <andrew.burgess@embecosm.com>
* testplugin.c (record_read_length): Remove debug fprintf. * testplugin.c (record_read_length): Remove debug fprintf.

View File

@ -18,12 +18,7 @@
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA. # MA 02110-1301, USA.
proc load_common_lib { name } { load_file $srcdir/../../binutils/testsuite/lib/binutils-common.exp
global srcdir
load_file $srcdir/../../binutils/testsuite/lib/$name
}
load_common_lib binutils-common.exp
# Returns 1 if the gcc for the target is at least version MAJOR.MINOR # Returns 1 if the gcc for the target is at least version MAJOR.MINOR
# Returns 0 otherwise. # Returns 0 otherwise.
@ -108,19 +103,24 @@ proc run_host_cmd { prog command } {
set prog $gccexe set prog $gccexe
} }
set gccexe [string replace $gccexe 0 [string last "/" $gccexe] ""] set gccexe [string replace $gccexe 0 [string last "/" $gccexe] ""]
if {[string match "*cc*" $gccexe] || [string match "*++*" $gccexe]} then { if {[string match "*cc*" $gccexe] ||
[string match "*++*" $gccexe] ||
[string match "clang*" $gccexe]} then {
set gccflags "$gcc_B_opt $gccflags $ld_L_opt" set gccflags "$gcc_B_opt $gccflags $ld_L_opt"
if {![info exists gcc_ld_B_opt_tested]} { if {![info exists gcc_ld_B_opt_tested]} {
set gcc_ld_B_opt_tested 1 set gcc_ld_B_opt_tested 1
set ld_version_message [run_host_cmd "$ld" "--version"] set ld_version_message [run_host_cmd "$ld" "--version"]
set gcc_ld_version_message [run_host_cmd "$prog" "$gccflags -Wl,--version"] set ver "-Wl,--version"
if [check_lto_available] {
set ver "-fno-lto $ver"
}
set gcc_ld_version_message [run_host_cmd "$prog" "$gccflags $ver"]
if {[string first $ld_version_message $gcc_ld_version_message] < 0} { if {[string first $ld_version_message $gcc_ld_version_message] < 0} {
perror "************************************************************************" perror "************************************************************************"
perror "Your compiler driver ignores -B when choosing ld." perror "Your compiler driver ignores -B when choosing ld."
perror "You will not be testing the new ld in many of the following tests." perror "You will not be testing the new ld in many of the following tests."
set gcc_ld_version [run_host_cmd "$prog" "$gccflags --print-prog-name=ld"] set gcc_ld_version [run_host_cmd "$prog" "$gccflags --print-prog-name=ld"]
if {![string match "" $gcc_ld_version] && ![string match "ld" $gcc_ld_version]} { if {![string match "" $gcc_ld_version] && ![string match "ld" $gcc_ld_version]} {
perror "It seems you will be testing $gcc_ld_version instead." perror "It seems you will be testing $gcc_ld_version instead."
} }
perror "************************************************************************" perror "************************************************************************"
@ -175,13 +175,13 @@ proc default_ld_relocate { ld target objects } {
proc is_endian_output_format { object_flags } { proc is_endian_output_format { object_flags } {
if {[string match "*-oformat binary*" $object_flags] || \ if {[string match "*-oformat binary*" $object_flags] || \
[string match "*-oformat ieee*" $object_flags] || \ [string match "*-oformat ieee*" $object_flags] || \
[string match "*-oformat ihex*" $object_flags] || \ [string match "*-oformat ihex*" $object_flags] || \
[string match "*-oformat netbsd-core*" $object_flags] || \ [string match "*-oformat netbsd-core*" $object_flags] || \
[string match "*-oformat srec*" $object_flags] || \ [string match "*-oformat srec*" $object_flags] || \
[string match "*-oformat tekhex*" $object_flags] || \ [string match "*-oformat tekhex*" $object_flags] || \
[string match "*-oformat trad-core*" $object_flags] } then { [string match "*-oformat trad-core*" $object_flags] } then {
return 0 return 0
} else { } else {
return 1 return 1
} }
@ -254,7 +254,7 @@ proc default_ld_compile { cc source object } {
} }
if [board_info [target_info name] exists cflags] { if [board_info [target_info name] exists cflags] {
append flags " [board_info [target_info name] cflags]" append flags " [board_info [target_info name] cflags]"
} }
if [board_info [target_info name] exists multilib_flags] { if [board_info [target_info name] exists multilib_flags] {
@ -355,7 +355,7 @@ proc default_ld_nm { nm nmflags object } {
while { [gets $file line] != -1 } { while { [gets $file line] != -1 } {
verbose "$line" 2 verbose "$line" 2
if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] \\.*(.+)$" $line whole value name] { if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] \\.*(.+)$" $line whole value name] {
set name [string trimleft $name "_"] set name [string trimleft $name "_"]
verbose "Setting nm_output($name) to 0x$value" 2 verbose "Setting nm_output($name) to 0x$value" 2
set nm_output($name) 0x$value set nm_output($name) 0x$value
} }
@ -376,12 +376,12 @@ proc ld_link_defsyms {} {
# ARM targets call __gccmain # ARM targets call __gccmain
if {[istarget arm*-*-*]} { if {[istarget arm*-*-*]} {
append flags " --defsym __gccmain=0" append flags " --defsym __gccmain=0"
} }
# Windows targets need __main, some prefixed with underscore. # Windows targets need __main, some prefixed with underscore.
if {[istarget *-*-cygwin* ] || [istarget *-*-mingw*]} { if {[istarget *-*-cygwin* ] || [istarget *-*-mingw*]} {
append flags " --defsym __main=main --defsym ___main=main" append flags " --defsym __main=main --defsym ___main=main"
} }
# PowerPC EABI code calls __eabi. # PowerPC EABI code calls __eabi.
@ -579,13 +579,13 @@ proc run_ld_link_tests { ldtests args } {
set dump_prog "" set dump_prog ""
switch -- $action { switch -- $action {
objdump objdump
{ set dump_prog $objdump } { set dump_prog $objdump }
nm nm
{ set dump_prog $nm } { set dump_prog $nm }
readelf readelf
{ set dump_prog $READELF } { set dump_prog $READELF }
ld ld
{ set dump_prog "ld" } { set dump_prog "ld" }
default default
{ {
perror "Unrecognized action $action" perror "Unrecognized action $action"
@ -615,12 +615,12 @@ proc run_ld_link_tests { ldtests args } {
} }
set env(LC_ALL) "C" set env(LC_ALL) "C"
set cmd "$binary $progopts $binfile" set cmd "$binary $progopts $binfile"
set status [remote_exec host [concat sh -c [list "$cmd >dump.out 2>ld.stderr"]] "" "/dev/null"] set status [remote_exec host [concat sh -c [list "$cmd >dump.out 2>ld.stderr"]] "" "/dev/null"]
send_log "$cmd\n" send_log "$cmd\n"
remote_upload host "ld.stderr" remote_upload host "ld.stderr"
set comp_output [prune_warnings [file_contents "ld.stderr"]] set comp_output [prune_warnings [file_contents "ld.stderr"]]
remote_file host delete "ld.stderr" remote_file host delete "ld.stderr"
remote_file build delete "ld.stderr" remote_file build delete "ld.stderr"
if {[info exists old_lc_all]} { if {[info exists old_lc_all]} {
set env(LC_ALL) $old_lc_all set env(LC_ALL) $old_lc_all
@ -639,8 +639,8 @@ proc run_ld_link_tests { ldtests args } {
if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then { if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then {
verbose "output is [file_contents "dump.out"]" 2 verbose "output is [file_contents "dump.out"]" 2
set failed 1 set failed 1
remote_file build delete "dump.out" remote_file build delete "dump.out"
remote_file host delete "dump.out" remote_file host delete "dump.out"
break break
} }
remote_file build delete "dump.out" remote_file build delete "dump.out"
@ -693,7 +693,7 @@ proc run_ld_link_exec_tests { ldtests args } {
# linker options are included in GCC spec files then we need the -specs # linker options are included in GCC spec files then we need the -specs
# option. # option.
if [board_info [target_info name] exists cflags] { if [board_info [target_info name] exists cflags] {
set board_cflags " [board_info [target_info name] cflags]" set board_cflags " [board_info [target_info name] cflags]"
} else { } else {
set board_cflags "" set board_cflags ""
} }
@ -857,7 +857,7 @@ proc run_cc_link_tests { ldtests } {
global STATIC_LDFLAGS global STATIC_LDFLAGS
if [board_info [target_info name] exists cflags] { if [board_info [target_info name] exists cflags] {
set board_cflags " [board_info [target_info name] cflags]" set board_cflags " [board_info [target_info name] cflags]"
} else { } else {
set board_cflags "" set board_cflags ""
} }
@ -900,28 +900,28 @@ proc run_cc_link_tests { ldtests } {
# Find actions related to error/warning processing. # Find actions related to error/warning processing.
switch -- $action { switch -- $action {
error error
{ {
set check_ld(source) "regexp" set check_ld(source) "regexp"
set check_ld(regexp) $progopts set check_ld(regexp) $progopts
set check_ld(terminal) 1 set check_ld(terminal) 1
} }
warning warning
{ {
set check_ld(source) "regexp" set check_ld(source) "regexp"
set check_ld(regexp) $progopts set check_ld(regexp) $progopts
} }
error_output error_output
{ {
set check_ld(source) "file" set check_ld(source) "file"
set check_ld(file) $progopts set check_ld(file) $progopts
set check_ld(terminal) 1 set check_ld(terminal) 1
} }
warning_output warning_output
{ {
set check_ld(source) "file" set check_ld(source) "file"
set check_ld(file) $progopts set check_ld(file) $progopts
} }
} }
} }
@ -988,15 +988,15 @@ proc run_cc_link_tests { ldtests } {
} }
if { $check_ld(source) != "" } then { if { $check_ld(source) != "" } then {
if { $ld_output == "" } then { if { $ld_output == "" } then {
verbose -log "Linker was expected to give error or warning" verbose -log "Linker was expected to give error or warning"
set failed 1 set failed 1
} }
} else { } else {
if { $ld_output != "" } then { if { $ld_output != "" } then {
verbose -log "Unexpected linker warning or error" verbose -log "Unexpected linker warning or error"
set failed 1 set failed 1
} }
} }
} }
@ -1011,11 +1011,11 @@ proc run_cc_link_tests { ldtests } {
set dump_prog "" set dump_prog ""
switch -- $action { switch -- $action {
objdump objdump
{ set dump_prog $objdump } { set dump_prog $objdump }
nm nm
{ set dump_prog $nm } { set dump_prog $nm }
readelf readelf
{ set dump_prog $READELF } { set dump_prog $READELF }
error {} error {}
warning {} warning {}
error_output {} error_output {}
@ -1082,7 +1082,7 @@ proc check_gc_sections_available { } {
# Some targets don't support gc-sections despite whatever's # Some targets don't support gc-sections despite whatever's
# advertised by ld's options. # advertised by ld's options.
if { [istarget alpha-*-*] if { [istarget alpha-*-*]
|| [istarget bpf-*-*] || [istarget bpf-*-*]
|| [istarget d30v-*-*] || [istarget d30v-*-*]
|| [istarget dlx-*-*] || [istarget dlx-*-*]
|| [istarget hppa*64-*-*] || [istarget hppa*64-*-*]
@ -1200,7 +1200,7 @@ proc check_compiler_available { } {
global CC global CC
if {![info exists compiler_available_saved]} { if {![info exists compiler_available_saved]} {
if { [which $CC] == 0 } { if { [which $CC] == 0 } {
set compiler_available_saved 0 set compiler_available_saved 0
return 0 return 0
} }
@ -1266,7 +1266,7 @@ proc check_lto_available { } {
global CC global CC
if {![info exists lto_available_saved]} { if {![info exists lto_available_saved]} {
if { ![check_gcc_plugin_enabled] } { if { ![check_gcc_plugin_enabled] } {
set lto_available_saved 0 set lto_available_saved 0
return 0 return 0
} }
@ -1309,7 +1309,7 @@ proc check_lto_fat_available { } {
global CC global CC
if {![info exists lto_fat_available_saved]} { if {![info exists lto_fat_available_saved]} {
if { ![check_gcc_plugin_enabled] } { if { ![check_gcc_plugin_enabled] } {
set lto_fat_available_saved 0 set lto_fat_available_saved 0
return 0 return 0
} }
@ -1352,7 +1352,7 @@ proc check_lto_shared_available { } {
global CC global CC
if {![info exists lto_shared_available_saved]} { if {![info exists lto_shared_available_saved]} {
if { ![check_gcc_plugin_enabled] } { if { ![check_gcc_plugin_enabled] } {
set lto_shared_available_saved 0 set lto_shared_available_saved 0
return 0 return 0
} }
@ -1418,7 +1418,7 @@ proc check_ifunc_available { } {
global CC global CC
if {![info exists ifunc_available_saved]} { if {![info exists ifunc_available_saved]} {
if { ![check_compiler_available] } { if { ![check_compiler_available] } {
set ifunc_available_saved 0 set ifunc_available_saved 0
return 0 return 0
} }
@ -1467,7 +1467,7 @@ proc check_ifunc_attribute_available { } {
global CC global CC
if {![info exists ifunc_attribute_available_saved]} { if {![info exists ifunc_attribute_available_saved]} {
if { ![check_compiler_available] } { if { ![check_compiler_available] } {
set ifunc_attribute_available_saved 0 set ifunc_attribute_available_saved 0
return 0 return 0
} }
@ -1514,7 +1514,7 @@ proc check_libdl_available { } {
global CC global CC
if {![info exists libdl_available_saved]} { if {![info exists libdl_available_saved]} {
if { ![check_compiler_available] } { if { ![check_compiler_available] } {
set libdl_available_saved 0 set libdl_available_saved 0
return 0 return 0
} }
@ -1550,7 +1550,7 @@ proc check_gnu2_tls_available { } {
global GNU2_CFLAGS global GNU2_CFLAGS
if {![info exists gnu2_tls_available_saved]} { if {![info exists gnu2_tls_available_saved]} {
if { ![check_compiler_available] || "$GNU2_CFLAGS" == "" } { if { ![check_compiler_available] || "$GNU2_CFLAGS" == "" } {
set gnu2_tls_available_saved 0 set gnu2_tls_available_saved 0
return 0 return 0
} }