ld: Support LD_UNDER_TEST environment variable

Message ID 20240316133932.352523-1-hjl.tools@gmail.com
State Superseded
Headers
Series ld: Support LD_UNDER_TEST environment variable |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed

Commit Message

H.J. Lu March 16, 2024, 1:39 p.m. UTC
  Support LD_UNDER_TEST environment variable to test a different linker.
Issue an error if LD_UNDER_TEST isn't a full path.

	* testsuite/config/default.exp: If LD_UNDER_TEST environment
	variable exists, set ld and LD to it and set up tmpdir/ld/ld.
	Issue an error if LD_UNDER_TEST isn't a full path.
---
 ld/testsuite/config/default.exp | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
  

Comments

Andreas Schwab March 16, 2024, 3:28 p.m. UTC | #1
On Mär 16 2024, H.J. Lu wrote:

> @@ -64,9 +77,16 @@ remote_exec host "mkdir -p tmpdir"
>  if {[info exists ld_testsuite_bindir]} {
>      set gcc_B_opt "-B$ld_testsuite_bindir/"
>  } else {
> +    if [info exists env(LD_UNDER_TEST)] {
> +	file delete -force tmpdir/ld
> +    }
>      if {![file isdirectory tmpdir/ld]} then {
>  	catch "exec mkdir tmpdir/ld" status
> -	catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
> +	if [info exists env(LD_UNDER_TEST)] {
> +	    catch "exec ln -s $env(LD_UNDER_TEST) tmpdir/ld/ld" status

That won't do the right thing if LD_UNDER_TEST is relative.
  
H.J. Lu March 16, 2024, 3:36 p.m. UTC | #2
On Sat, Mar 16, 2024 at 8:28 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Mär 16 2024, H.J. Lu wrote:
>
> > @@ -64,9 +77,16 @@ remote_exec host "mkdir -p tmpdir"
> >  if {[info exists ld_testsuite_bindir]} {
> >      set gcc_B_opt "-B$ld_testsuite_bindir/"
> >  } else {
> > +    if [info exists env(LD_UNDER_TEST)] {
> > +     file delete -force tmpdir/ld
> > +    }
> >      if {![file isdirectory tmpdir/ld]} then {
> >       catch "exec mkdir tmpdir/ld" status
> > -     catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
> > +     if [info exists env(LD_UNDER_TEST)] {
> > +         catch "exec ln -s $env(LD_UNDER_TEST) tmpdir/ld/ld" status
>
> That won't do the right thing if LD_UNDER_TEST is relative.
>

The v2 patch:

https://sourceware.org/pipermail/binutils/2024-March/133061.html

checks the absolute full path instead.
  

Patch

diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 705543054c2..09115de65e5 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -21,6 +21,19 @@ 
 # Written by Jeffrey Wheat (cassidy@cygnus.com)
 #
 
+if [info exists env(LD_UNDER_TEST)] {
+    # LD_UNDER_TEST must be a full path.
+    catch "file dirname $env(LD_UNDER_TEST)" dirname
+    if [string match "." $dirname] then {
+	perror "**************************************************"
+	perror "$env(LD_UNDER_TEST) isn't a full path."
+	perror "**************************************************"
+	exit 1
+    }
+    set ld "$env(LD_UNDER_TEST)"
+    set LD "$ld"
+}
+
 if ![info exists ld] then {
     set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
 }
@@ -64,9 +77,16 @@  remote_exec host "mkdir -p tmpdir"
 if {[info exists ld_testsuite_bindir]} {
     set gcc_B_opt "-B$ld_testsuite_bindir/"
 } else {
+    if [info exists env(LD_UNDER_TEST)] {
+	file delete -force tmpdir/ld
+    }
     if {![file isdirectory tmpdir/ld]} then {
 	catch "exec mkdir tmpdir/ld" status
-	catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
+	if [info exists env(LD_UNDER_TEST)] {
+	    catch "exec ln -s $env(LD_UNDER_TEST) tmpdir/ld/ld" status
+	} else {
+	    catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
+	}
 	catch "exec ln -s ld tmpdir/ld/collect-ld" status
 	catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
     }