[PR95720] protect gluefile and wrap_flags with -Wl too
authorAlexandre Oliva <oliva@adacore.com>
Fri, 24 Jul 2020 18:38:35 +0000 (15:38 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Fri, 24 Jul 2020 19:13:37 +0000 (16:13 -0300)
The testglue object file gets interpreted as another input file,
changing the dump and aux output names in GCC unless it is protected
by -Wl, like board file-named extra inputs.

Refactor the code that modifies the board settings so that it can be
used to modify regular variables as well, and do so.

for  gcc/testsuite/ChangeLog

PR testsuite/95720
* lib/gcc-defs.exp (gcc_adjust_linker_flags_list): Split out of...
(gcc_adjust_linker_flags): ... this.  Protect gluefile and
wrap_flags.
* gcc.misc-tests/outputs.exp: Use gcc_adjust_linker_flags_list.

gcc/testsuite/gcc.misc-tests/outputs.exp
gcc/testsuite/lib/gcc-defs.exp

index 469d94c..0784a8e 100644 (file)
@@ -56,17 +56,9 @@ set link_options ""
 set dest [target_info name]
 foreach i { ldflags libs ldscript } {
     if {[board_info $dest exists $i]} {
-       set skip ""
-       foreach opt [split [board_info $dest $i]] {
-           if { $opt == "" } then {
-               continue
-           } elseif { $skip != "" } then {
-               set skip ""
-           } elseif { $opt == "-Xlinker" } then {
-               set skip $opt
-           } elseif { ![string match "-*" $opt] && [file isfile $opt] } {
-               set opt "-Wl,$opt"
-           }
+       set opts [board_info $dest $i]
+       set nopts [gcc_adjust_linker_flags_list $opts]
+       foreach opt $nopts {
            append link_options " additional_flags=$opt"
        }
     }
index 87eeb7d..380a18b 100644 (file)
@@ -287,9 +287,32 @@ proc dg-additional-files { args } {
 
 set gcc_adjusted_linker_flags 0
 
-# Add -Wl, before any file names in ldflags, libs, and ldscript, so
-# that default object files or libraries do not change the names of
-# gcc auxiliary outputs.
+# Add -Wl, before any file names in $opts.  Return the modified list.
+
+proc gcc_adjust_linker_flags_list { args } {
+    set opts [lindex $args 0]
+    set nopts {}
+    set skip ""
+    foreach opt [split $opts " "] {
+       if { $opt == "" } then {
+           continue
+       } elseif { $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
+    }
+    return $nopts
+}
+
+# Add -Wl, before any file names in the target board's ldflags, libs,
+# and ldscript, as well as in global testglue and wrap_flags, 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
@@ -303,27 +326,23 @@ proc gcc_adjust_linker_flags {} {
        foreach i { ldflags libs ldscript } {
            if {[board_info $dest exists $i]} {
                set opts [board_info $dest $i]
-               set nopts {}
-               set skip ""
-               foreach opt [split $opts] {
-                   if { $opt == "" } then {
-                       continue
-                   } elseif { $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
-               }
+               set nopts [gcc_adjust_linker_flags_list $opts]
                if { $nopts != $opts } {
                    unset_currtarget_info $i
                    set_currtarget_info $i "$nopts"
                }
            }
        }
+       foreach i { gluefile wrap_flags } {
+           global $i
+           if {[info exists $i]} {
+               set opts [set $i]
+               set nopts [gcc_adjust_linker_flags_list $opts]
+               if { $nopts != $opts } {
+                   set $i $nopts
+               }
+           }
+       }
     }
 }