public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4] ld: Support LD_UNDER_TEST environment variable
@ 2024-03-17 12:15 H.J. Lu
  2024-03-19 12:06 ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2024-03-17 12:15 UTC (permalink / raw)
  To: binutils

Support LD_UNDER_TEST environment variable to test a different linker.
Issue an error if LD_UNDER_TEST isn't an absolute 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 an absolute full path.
---
 ld/testsuite/config/default.exp | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 705543054c2..ed6002e6427 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -21,6 +21,23 @@
 # Written by Jeffrey Wheat (cassidy@cygnus.com)
 #
 
+if [info exists env(LD_UNDER_TEST)] {
+    # LD_UNDER_TEST must be an absolute full path.
+    if {[file pathtype $env(LD_UNDER_TEST)] ne "absolute"} {
+	perror "**************************************************"
+	perror "$env(LD_UNDER_TEST) isn't an absolute full path."
+	perror "**************************************************"
+	exit 1
+    } elseif {![file exists $env(LD_UNDER_TEST)]} {
+	perror "**************************************************"
+	perror "$env(LD_UNDER_TEST) doesn't exist."
+	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,12 +81,17 @@ remote_exec host "mkdir -p tmpdir"
 if {[info exists ld_testsuite_bindir]} {
     set gcc_B_opt "-B$ld_testsuite_bindir/"
 } else {
-    if {![file isdirectory tmpdir/ld]} then {
-	catch "exec mkdir tmpdir/ld" status
+    # Delete tmpdir/ld first to remove tmpdir/ld/ld created by the
+    # previous LD_UNDER_TEST runs.
+    file delete -force tmpdir/ld
+    catch "exec mkdir tmpdir/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
     }
+    catch "exec ln -s ld tmpdir/ld/collect-ld" status
+    catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
     set gcc_B_opt "-B[pwd]/tmpdir/ld/"
 }
 
-- 
2.44.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] ld: Support LD_UNDER_TEST environment variable
  2024-03-17 12:15 [PATCH v4] ld: Support LD_UNDER_TEST environment variable H.J. Lu
@ 2024-03-19 12:06 ` Nick Clifton
  2024-03-19 14:07   ` H.J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2024-03-19 12:06 UTC (permalink / raw)
  To: H.J. Lu, binutils

Hi H.J.

> Support LD_UNDER_TEST environment variable to test a different linker.
> Issue an error if LD_UNDER_TEST isn't an absolute full path.

I would ask for one more change:

> +	perror "**************************************************"
> +	perror "$env(LD_UNDER_TEST) isn't an absolute full path."
> +	perror "**************************************************"

If I am reading this correctly the error message will show the contents
of the LD_UNDER_TEST environment variable, but not the name of the variable.
This could be confusing if the user does not realise that they have the
variable set.  Therefore please could you update the message to something
like:

   perror "Environment variable LD_UNDER_TEST ($env(LD_UNDER_TEST)) is not an absolute full path"

And similarly for the other error message.

Patch approved with these changes,.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] ld: Support LD_UNDER_TEST environment variable
  2024-03-19 12:06 ` Nick Clifton
@ 2024-03-19 14:07   ` H.J. Lu
  0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2024-03-19 14:07 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

On Tue, Mar 19, 2024 at 5:07 AM Nick Clifton <nickc@redhat.com> wrote:
>
> Hi H.J.
>
> > Support LD_UNDER_TEST environment variable to test a different linker.
> > Issue an error if LD_UNDER_TEST isn't an absolute full path.
>
> I would ask for one more change:
>
> > +     perror "**************************************************"
> > +     perror "$env(LD_UNDER_TEST) isn't an absolute full path."
> > +     perror "**************************************************"
>
> If I am reading this correctly the error message will show the contents
> of the LD_UNDER_TEST environment variable, but not the name of the variable.
> This could be confusing if the user does not realise that they have the
> variable set.  Therefore please could you update the message to something
> like:
>
>    perror "Environment variable LD_UNDER_TEST ($env(LD_UNDER_TEST)) is not an absolute full path"
>
> And similarly for the other error message.

Fixed.

> Patch approved with these changes,.
>
> Cheers
>    Nick
>

This is what I am checking in.

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-ld-Support-LD_UNDER_TEST-environment-variable.patch --]
[-- Type: text/x-patch, Size: 2626 bytes --]

From 2a92a019de551bd811fb734da82e2bb87bed55eb Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 16 Mar 2024 06:23:19 -0700
Subject: [PATCH] ld: Support LD_UNDER_TEST environment variable

Support LD_UNDER_TEST environment variable to test a different linker.
Issue an error if LD_UNDER_TEST isn't an absolute 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 an absolute full path.
---
 ld/testsuite/config/default.exp | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 705543054c2..afaf4bcb1ff 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -21,6 +21,23 @@
 # Written by Jeffrey Wheat (cassidy@cygnus.com)
 #
 
+if [info exists env(LD_UNDER_TEST)] {
+    # LD_UNDER_TEST must be an absolute full path.
+    if {[file pathtype $env(LD_UNDER_TEST)] ne "absolute"} {
+	perror "**************************************************"
+	perror "Environment variable LD_UNDER_TEST ($env(LD_UNDER_TEST)) isn't an absolute full path."
+	perror "**************************************************"
+	exit 1
+    } elseif {![file exists $env(LD_UNDER_TEST)]} {
+	perror "**************************************************"
+	perror "Environment variable LD_UNDER_TEST ($env(LD_UNDER_TEST)) doesn't exist."
+	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,12 +81,17 @@ remote_exec host "mkdir -p tmpdir"
 if {[info exists ld_testsuite_bindir]} {
     set gcc_B_opt "-B$ld_testsuite_bindir/"
 } else {
-    if {![file isdirectory tmpdir/ld]} then {
-	catch "exec mkdir tmpdir/ld" status
+    # Delete tmpdir/ld first to remove tmpdir/ld/ld created by the
+    # previous LD_UNDER_TEST runs.
+    file delete -force tmpdir/ld
+    catch "exec mkdir tmpdir/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
     }
+    catch "exec ln -s ld tmpdir/ld/collect-ld" status
+    catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
     set gcc_B_opt "-B[pwd]/tmpdir/ld/"
 }
 
-- 
2.44.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-19 14:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-17 12:15 [PATCH v4] ld: Support LD_UNDER_TEST environment variable H.J. Lu
2024-03-19 12:06 ` Nick Clifton
2024-03-19 14:07   ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).