[2/3] ld/testsuite/lto: replace manual links by ld_link helper

Message ID 20250106132830.1530158-2-chigot@adacore.com
State New
Headers
Series [1/3] ld/testsuite: centralize board_cflags and board_ldflags |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Clément Chigot Jan. 6, 2025, 1:28 p.m. UTC
  Some tests are calling run_host_cmd in order to retrieve the
errors/warnings messages generated.
ld_link is also making them available through exec_output global
variable but as the advantages of taking the board configuration into
account unlike run_host_cmd.
---
 ld/testsuite/ld-plugin/lto.exp | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
  

Comments

Alan Modra Jan. 7, 2025, 10:50 a.m. UTC | #1
On Mon, Jan 06, 2025 at 02:28:29PM +0100, Clément Chigot wrote:
> Some tests are calling run_host_cmd in order to retrieve the
> errors/warnings messages generated.
> ld_link is also making them available through exec_output global
> variable but as the advantages of taking the board configuration into
> account unlike run_host_cmd.
> ---
>  ld/testsuite/ld-plugin/lto.exp | 29 +++++++++++++++++------------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 
> diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
> index b0816c437f4..9a16f013ed9 100644
> --- a/ld/testsuite/ld-plugin/lto.exp
> +++ b/ld/testsuite/ld-plugin/lto.exp
> @@ -29,6 +29,8 @@ if { ![check_plugin_api_available]
>      return
>  }
>  
> +global exec_output
> +

I don't think you need this, or any other "global exec_output" except
the last one, inside the proc.  Otherwise OK.

>  set saved_CFLAGS "$CFLAGS_FOR_TARGET"
>  set saved_CXXFLAGS "$CXXFLAGS_FOR_TARGET"
>  regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS_FOR_TARGET "" CFLAGS_FOR_TARGET
> @@ -905,10 +907,8 @@ run_cc_link_tests $lto_compile_elf_tests
>  #
>  #    Update LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook
>  #
> -set exec_output [run_host_cmd "$CC_FOR_TARGET" \
> -			      "-O2 -fcommon -flto -o tmpdir/common-2 \
> -			       tmpdir/common-2a.o tmpdir/libcommon-2.a \
> -			       tmpdir/libcommon-2.a"]
> +ld_link "$CC_FOR_TARGET" pr32083.exe "-O2 -fcommon -flto -o tmpdir/common-2 \
> +    tmpdir/common-2a.o tmpdir/libcommon-2.a tmpdir/libcommon-2.a"
>  if [string match "" $exec_output] then {
>      pass "PR ld/32083"
>  } elseif { [ regexp "lto1: fatal error: multiple prevailing defs for 'func'" $exec_output ] } {
> @@ -919,23 +919,25 @@ if [string match "" $exec_output] then {
>  
>  # Restrict these to ELF targets that support shared libs and PIC.
>  if { [is_elf_format] && [check_lto_shared_available] } {
> +    global exec_output
> +
>      run_cc_link_tests $lto_link_elf_tests
>      set testname "PR ld/15146 (2)"
> -    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"]
> +    ld_link "$CC_FOR_TARGET" pr15146-2.exe "-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
>      } {
>  	fail $testname
>      }
>      set testname "PR ld/16746 (3)"
> -    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
> +    ld_link "$CC_FOR_TARGET" pr16746-3.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"
>      if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
>  	pass $testname
>      } {
>  	fail $testname
>      }
>      set testname "PR ld/16746 (4)"
> -    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
> +    ld_link "$CC_FOR_TARGET" pr16746-4.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"
>      if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
>  	pass $testname
>      } {
> @@ -957,10 +959,11 @@ run_cc_link_tests [list \
>      ] \
>  ]
>  
> +set board_flags [get_board_flags]
>  set exec_output [run_host_cmd "sh" \
>  			      "-c \"ulimit -n 20; \
>  			      $CC_FOR_TARGET $gcc_B_opt $CFLAGS_FOR_TARGET \
> -			      $ld_L_opt -o tmpdir/pr28138 \
> +			      $board_flags $ld_L_opt -o tmpdir/pr28138 \
>  			      tmpdir/pr28138.o tmpdir/pr28138.a\""]
>  set exec_output [prune_warnings $exec_output]
>  if [string match "" $exec_output] then {
> @@ -991,14 +994,15 @@ if { [at_least_gcc_version 4 7] } {
>      # Check expected LTO linker errors.
>      # Since the asm symbol name hack in pr12365b.c doesn't work on all
>      # targets, run PR ld/12365 tests only for known targets.
> +    global exec_output
> +
>      if { ([istarget "i?86-*-elf*"]
>  	   || [istarget "i?86-*-linux*"]
>  	   || [istarget "i?86-*-gnu*"]
>  	   || [istarget "x86_64-*-linux*"]
>  	   || [istarget "amd64-*-linux*"]) } {
>  	set testname "PR ld/12365"
> -	set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"]
> -	set exec_output [prune_warnings $exec_output]
> +	ld_link "$CC_FOR_TARGET" pr12365.exe "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"
>  	if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
>  	    # Linker should catch the reference to undefined `my_bcopy'
>  	    # error caused by a GCC bug.
> @@ -1045,7 +1049,7 @@ if { [at_least_gcc_version 4 7] } {
>  	]
>      }
>      set testname "PR ld/12942 (3)"
> -    set exec_output [run_host_cmd "$CXX_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
> +    ld_link "$CXX_FOR_TARGET" pr12942-3.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"
>      if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
>          pass $testname
>      } {
> @@ -1138,9 +1142,10 @@ if { [is_elf_format] && [check_lto_shared_available] } {
>  
>  proc pr20103 {cflags libs} {
>      global CC_FOR_TARGET
> +    global exec_output
>  
>      set testname "PR ld/20103 ($cflags $libs)"
> -    set exec_output [run_host_cmd "$CC_FOR_TARGET" "$cflags $libs"]
> +    ld_link "$CC_FOR_TARGET" pr20103.exe "$cflags $libs"
>      # NB: Starting from GCC 4.9, -flto is optional for final link.
>      if { [ regexp "fatpr20103" "$libs" ] \
>  	 && ([regexp " -flto" "$cflags"] \
> -- 
> 2.34.1
  
Clément Chigot Jan. 7, 2025, 1:07 p.m. UTC | #2
On Tue, Jan 7, 2025 at 11:50 AM Alan Modra <amodra@gmail.com> wrote:
>
> On Mon, Jan 06, 2025 at 02:28:29PM +0100, Clément Chigot wrote:
> > Some tests are calling run_host_cmd in order to retrieve the
> > errors/warnings messages generated.
> > ld_link is also making them available through exec_output global
> > variable but as the advantages of taking the board configuration into
> > account unlike run_host_cmd.
> > ---
> >  ld/testsuite/ld-plugin/lto.exp | 29 +++++++++++++++++------------
> >  1 file changed, 17 insertions(+), 12 deletions(-)
> >
> > diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
> > index b0816c437f4..9a16f013ed9 100644
> > --- a/ld/testsuite/ld-plugin/lto.exp
> > +++ b/ld/testsuite/ld-plugin/lto.exp
> > @@ -29,6 +29,8 @@ if { ![check_plugin_api_available]
> >      return
> >  }
> >
> > +global exec_output
> > +
>
> I don't think you need this, or any other "global exec_output" except
> the last one, inside the proc.  Otherwise OK.

Indeed. Fixed and pushed.
Thanks for the review.

> >  set saved_CFLAGS "$CFLAGS_FOR_TARGET"
> >  set saved_CXXFLAGS "$CXXFLAGS_FOR_TARGET"
> >  regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS_FOR_TARGET "" CFLAGS_FOR_TARGET
> > @@ -905,10 +907,8 @@ run_cc_link_tests $lto_compile_elf_tests
> >  #
> >  #    Update LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook
> >  #
> > -set exec_output [run_host_cmd "$CC_FOR_TARGET" \
> > -                           "-O2 -fcommon -flto -o tmpdir/common-2 \
> > -                            tmpdir/common-2a.o tmpdir/libcommon-2.a \
> > -                            tmpdir/libcommon-2.a"]
> > +ld_link "$CC_FOR_TARGET" pr32083.exe "-O2 -fcommon -flto -o tmpdir/common-2 \
> > +    tmpdir/common-2a.o tmpdir/libcommon-2.a tmpdir/libcommon-2.a"
> >  if [string match "" $exec_output] then {
> >      pass "PR ld/32083"
> >  } elseif { [ regexp "lto1: fatal error: multiple prevailing defs for 'func'" $exec_output ] } {
> > @@ -919,23 +919,25 @@ if [string match "" $exec_output] then {
> >
> >  # Restrict these to ELF targets that support shared libs and PIC.
> >  if { [is_elf_format] && [check_lto_shared_available] } {
> > +    global exec_output
> > +
> >      run_cc_link_tests $lto_link_elf_tests
> >      set testname "PR ld/15146 (2)"
> > -    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"]
> > +    ld_link "$CC_FOR_TARGET" pr15146-2.exe "-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
> >      } {
> >       fail $testname
> >      }
> >      set testname "PR ld/16746 (3)"
> > -    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
> > +    ld_link "$CC_FOR_TARGET" pr16746-3.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"
> >      if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
> >       pass $testname
> >      } {
> >       fail $testname
> >      }
> >      set testname "PR ld/16746 (4)"
> > -    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
> > +    ld_link "$CC_FOR_TARGET" pr16746-4.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"
> >      if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
> >       pass $testname
> >      } {
> > @@ -957,10 +959,11 @@ run_cc_link_tests [list \
> >      ] \
> >  ]
> >
> > +set board_flags [get_board_flags]
> >  set exec_output [run_host_cmd "sh" \
> >                             "-c \"ulimit -n 20; \
> >                             $CC_FOR_TARGET $gcc_B_opt $CFLAGS_FOR_TARGET \
> > -                           $ld_L_opt -o tmpdir/pr28138 \
> > +                           $board_flags $ld_L_opt -o tmpdir/pr28138 \
> >                             tmpdir/pr28138.o tmpdir/pr28138.a\""]
> >  set exec_output [prune_warnings $exec_output]
> >  if [string match "" $exec_output] then {
> > @@ -991,14 +994,15 @@ if { [at_least_gcc_version 4 7] } {
> >      # Check expected LTO linker errors.
> >      # Since the asm symbol name hack in pr12365b.c doesn't work on all
> >      # targets, run PR ld/12365 tests only for known targets.
> > +    global exec_output
> > +
> >      if { ([istarget "i?86-*-elf*"]
> >          || [istarget "i?86-*-linux*"]
> >          || [istarget "i?86-*-gnu*"]
> >          || [istarget "x86_64-*-linux*"]
> >          || [istarget "amd64-*-linux*"]) } {
> >       set testname "PR ld/12365"
> > -     set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"]
> > -     set exec_output [prune_warnings $exec_output]
> > +     ld_link "$CC_FOR_TARGET" pr12365.exe "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"
> >       if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
> >           # Linker should catch the reference to undefined `my_bcopy'
> >           # error caused by a GCC bug.
> > @@ -1045,7 +1049,7 @@ if { [at_least_gcc_version 4 7] } {
> >       ]
> >      }
> >      set testname "PR ld/12942 (3)"
> > -    set exec_output [run_host_cmd "$CXX_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
> > +    ld_link "$CXX_FOR_TARGET" pr12942-3.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"
> >      if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
> >          pass $testname
> >      } {
> > @@ -1138,9 +1142,10 @@ if { [is_elf_format] && [check_lto_shared_available] } {
> >
> >  proc pr20103 {cflags libs} {
> >      global CC_FOR_TARGET
> > +    global exec_output
> >
> >      set testname "PR ld/20103 ($cflags $libs)"
> > -    set exec_output [run_host_cmd "$CC_FOR_TARGET" "$cflags $libs"]
> > +    ld_link "$CC_FOR_TARGET" pr20103.exe "$cflags $libs"
> >      # NB: Starting from GCC 4.9, -flto is optional for final link.
> >      if { [ regexp "fatpr20103" "$libs" ] \
> >        && ([regexp " -flto" "$cflags"] \
> > --
> > 2.34.1
>
> --
> Alan Modra
  

Patch

diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index b0816c437f4..9a16f013ed9 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -29,6 +29,8 @@  if { ![check_plugin_api_available]
     return
 }
 
+global exec_output
+
 set saved_CFLAGS "$CFLAGS_FOR_TARGET"
 set saved_CXXFLAGS "$CXXFLAGS_FOR_TARGET"
 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS_FOR_TARGET "" CFLAGS_FOR_TARGET
@@ -905,10 +907,8 @@  run_cc_link_tests $lto_compile_elf_tests
 #
 #    Update LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook
 #
-set exec_output [run_host_cmd "$CC_FOR_TARGET" \
-			      "-O2 -fcommon -flto -o tmpdir/common-2 \
-			       tmpdir/common-2a.o tmpdir/libcommon-2.a \
-			       tmpdir/libcommon-2.a"]
+ld_link "$CC_FOR_TARGET" pr32083.exe "-O2 -fcommon -flto -o tmpdir/common-2 \
+    tmpdir/common-2a.o tmpdir/libcommon-2.a tmpdir/libcommon-2.a"
 if [string match "" $exec_output] then {
     pass "PR ld/32083"
 } elseif { [ regexp "lto1: fatal error: multiple prevailing defs for 'func'" $exec_output ] } {
@@ -919,23 +919,25 @@  if [string match "" $exec_output] then {
 
 # Restrict these to ELF targets that support shared libs and PIC.
 if { [is_elf_format] && [check_lto_shared_available] } {
+    global exec_output
+
     run_cc_link_tests $lto_link_elf_tests
     set testname "PR ld/15146 (2)"
-    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"]
+    ld_link "$CC_FOR_TARGET" pr15146-2.exe "-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
     } {
 	fail $testname
     }
     set testname "PR ld/16746 (3)"
-    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
+    ld_link "$CC_FOR_TARGET" pr16746-3.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"
     if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
 	pass $testname
     } {
 	fail $testname
     }
     set testname "PR ld/16746 (4)"
-    set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
+    ld_link "$CC_FOR_TARGET" pr16746-4.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"
     if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
 	pass $testname
     } {
@@ -957,10 +959,11 @@  run_cc_link_tests [list \
     ] \
 ]
 
+set board_flags [get_board_flags]
 set exec_output [run_host_cmd "sh" \
 			      "-c \"ulimit -n 20; \
 			      $CC_FOR_TARGET $gcc_B_opt $CFLAGS_FOR_TARGET \
-			      $ld_L_opt -o tmpdir/pr28138 \
+			      $board_flags $ld_L_opt -o tmpdir/pr28138 \
 			      tmpdir/pr28138.o tmpdir/pr28138.a\""]
 set exec_output [prune_warnings $exec_output]
 if [string match "" $exec_output] then {
@@ -991,14 +994,15 @@  if { [at_least_gcc_version 4 7] } {
     # Check expected LTO linker errors.
     # Since the asm symbol name hack in pr12365b.c doesn't work on all
     # targets, run PR ld/12365 tests only for known targets.
+    global exec_output
+
     if { ([istarget "i?86-*-elf*"]
 	   || [istarget "i?86-*-linux*"]
 	   || [istarget "i?86-*-gnu*"]
 	   || [istarget "x86_64-*-linux*"]
 	   || [istarget "amd64-*-linux*"]) } {
 	set testname "PR ld/12365"
-	set exec_output [run_host_cmd "$CC_FOR_TARGET" "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"]
-	set exec_output [prune_warnings $exec_output]
+	ld_link "$CC_FOR_TARGET" pr12365.exe "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"
 	if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
 	    # Linker should catch the reference to undefined `my_bcopy'
 	    # error caused by a GCC bug.
@@ -1045,7 +1049,7 @@  if { [at_least_gcc_version 4 7] } {
 	]
     }
     set testname "PR ld/12942 (3)"
-    set exec_output [run_host_cmd "$CXX_FOR_TARGET" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
+    ld_link "$CXX_FOR_TARGET" pr12942-3.exe "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"
     if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
         pass $testname
     } {
@@ -1138,9 +1142,10 @@  if { [is_elf_format] && [check_lto_shared_available] } {
 
 proc pr20103 {cflags libs} {
     global CC_FOR_TARGET
+    global exec_output
 
     set testname "PR ld/20103 ($cflags $libs)"
-    set exec_output [run_host_cmd "$CC_FOR_TARGET" "$cflags $libs"]
+    ld_link "$CC_FOR_TARGET" pr20103.exe "$cflags $libs"
     # NB: Starting from GCC 4.9, -flto is optional for final link.
     if { [ regexp "fatpr20103" "$libs" ] \
 	 && ([regexp " -flto" "$cflags"] \