On May 19, 2020, Alexandre Oliva <ol...@adacore.com> wrote: > - fix for outputs.exp for platforms with nonempty ldflags, libs, > ldscripts, or output_format in the dejagnu board configuration, and > for link tests with aux dumps in the testsuite when ldflags, libs or > ldscripts in the board config name files that gcc would regard as > additional inputs.
protect filenames in linker flags with -Wl, From: Alexandre Oliva <ol...@adacore.com> outputs.exp is not suited for remote compilation, so disable it if host is remote. Make it so that any extra data that complements fail messages goes in a separate line, instead of appearing to be part of the test name. ldflags, libs, ldscripts and output_format flags that would normally be passed to the compiler driver when linking would not be passed in our special arrangement that bypasses the dejagnu requirement of naming an output file when creating an executable. With this patch we collect them into a variable and add them to the options when running linking tests. Another issue with linking tests is that any object or library names in these board configuration knobs would be taken by the compiler driver as another input, changing the name of auxiliary outputs such as those that -save-temps creates. Tests that look for the auxiliary outputs for single-inputs would not find them, and end up UNSUPPORTED. This is fixed by prependig "-Wl," to any filename that appears in ldflags, libs or ldscripts. for gcc/testsuite/ChangeLog * gcc.misc-tests/outputs.exp: Skip if host is remote. (link_options): New. Compute once, use in all link tests. (outest): Move extra notes for fails to separate line. * lib/gcc-defs.exp (gcc_adjusted_linker_flags): New. (gcc_adjust_linker_flags): New. (dg-additional-files-options): Call it. --- gcc/testsuite/gcc.misc-tests/outputs.exp | 36 +++++++++++++++++++++++--- gcc/testsuite/lib/gcc-defs.exp | 42 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gcc.misc-tests/outputs.exp b/gcc/testsuite/gcc.misc-tests/outputs.exp index 6cb2c64..889db17 100644 --- a/gcc/testsuite/gcc.misc-tests/outputs.exp +++ b/gcc/testsuite/gcc.misc-tests/outputs.exp @@ -31,7 +31,7 @@ set b "outputs" # doesn't return the same values, so disable parallelization # of this *.exp file. The first parallel runtest to reach # this will run all the tests serially. -if ![gcc_parallel_test_run_p $b] { +if {![gcc_parallel_test_run_p $b] || [is_remote host]} { return } gcc_parallel_test_enable 0 @@ -43,6 +43,29 @@ if ![check_no_compiler_messages gsplitdwarf object { set gsplit_dwarf "" } +# Prepare additional options to be used for linking. +# We do not compile to an executable, because that requires naming an output. +set link_options "" +set dest [target_info name] +foreach i { ldflags libs ldscripts } { + if {[board_info $dest exists $i]} { + set skip "" + foreach opt [split [board_info $dest $i]] { + if { $skip != "" } then { + set skip "" + } elseif { $opt == "-Xlinker" } then { + set skip $opt + } elseif { ![string match "-*" $opt] && [file isfile $opt] } { + set opt "-Wl,$opt" + } + append link_options " additional_flags=$opt" + } + } +} +if {[board_info $dest exists output_format]} { + append link_options " additional_flags=-Wl,-oformat,[board_info $dest output_format]" +} + # For the test named TEST, run the compiler with SOURCES and OPTS, and # look in DIRS for OUTPUTS. SOURCES is a list of suffixes for source # files starting with $b in $srcdir/$subdir, OPTS is a string with @@ -79,7 +102,12 @@ proc outest { test sources opts dirs outputs } { } set options "" foreach opt [split $opts " "] { - set options "$options additional_flags=$opt" + append options " additional_flags=$opt" + } + # Add linker flags if we're linking + if {![string match "* -\[ESc\] *" " $opts "]} { + global link_options + append options "$link_options" } set gcc_output [gcc_target_compile $src "" none "$options"] set outs {} @@ -136,13 +164,13 @@ proc outest { test sources opts dirs outputs } { if { [llength $outs] == 0 } then { pass "$test: extra" } else { - fail "$test: extra $outs" + fail "$test: extra\n$outs" } if { [string equal "$gcc_output" ""] } then { pass "$test: std out" } else { - fail "$test: std out $gcc_output" + fail "$test: std out\n$gcc_output" } } diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.exp index 4abb2b3..fc7e8e2 100644 --- a/gcc/testsuite/lib/gcc-defs.exp +++ b/gcc/testsuite/lib/gcc-defs.exp @@ -285,11 +285,53 @@ proc dg-additional-files { args } { set additional_files [lindex $args 1] } +set gcc_adjusted_linker_flags 0 + +# Add -Wl, before any file names in ldflags, libs, and ldscripts, so +# that default object files or libraries do not change the names of +# gcc auxiliary outputs. + +proc gcc_adjust_linker_flags {} { + global gcc_adjusted_linker_flags + if {$gcc_adjusted_linker_flags} { + return + } + set gcc_adjusted_linker_flags 1 + + if {![is_remote host]} { + set dest [target_info name] + foreach i { ldflags libs ldscripts } { + if {[board_info $dest exists $i]} { + set opts [board_info $dest $i] + set nopts {} + set skip "" + foreach opt [split $opts] { + if { $skip != "" } then { + set skip "" + } elseif { $opt == "-Xlinker" } then { + set skip $opt + } elseif { ![string match "-*" $opt] \ + && [file isfile $opt] } { + set opt "-Wl,$opt" + } + lappend nopts $opt + } + if { $nopts != $opts } { + unset_currtarget_info $i + set_currtarget_info $i "$nopts" + } + } + } + } +} + # Return an updated version of OPTIONS that mentions any additional # source files registered with dg-additional-sources. SOURCE is the # name of the test case. proc dg-additional-files-options { options source } { + gcc_adjust_linker_flags + global additional_sources global additional_sources_used global additional_files -- Alexandre Oliva, freedom fighter he/him https://FSFLA.org/blogs/lxo/ Free Software Evangelist Stallman was right, but he's left :( GNU Toolchain Engineer Live long and free, and prosper ethically