public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3] malloc: Always install mtrace (bug 31892)
@ 2024-06-19 15:47 Florian Weimer
  2024-06-19 18:13 ` Carlos O'Donell
  2024-06-20  8:53 ` Andreas Schwab
  0 siblings, 2 replies; 4+ messages in thread
From: Florian Weimer @ 2024-06-19 15:47 UTC (permalink / raw)
  To: libc-alpha

Generation of the Perl script does not depend on Perl, so we can
always install it even if $(PERL) is not set during the build.

Change the malloc/mtrace.pl text substition not to rely on $(PERL).
Instead use PATH at run time to find the Perl interpreter. The Perl
interpreter cannot execute directly a script that starts with
“#! /bin/sh”: it always executes it with /bin/sh.  There is no
perl command line switch to disable this behavior.  Instead, use
the Perl require function to execute the script.  The additional
shift calls remove the “.” shell arguments.  Perl interprets the
“.” as a string concatenation operator, making the expression
syntactically valid.

---
v3: Git mishap did not squash together both changes.  Restore the
    removal of the $(PERL) conditional.

 malloc/Makefile  | 4 +---
 malloc/mtrace.pl | 7 +++----
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/malloc/Makefile b/malloc/Makefile
index cc14cf66c9..02aff1bd1d 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -250,7 +250,6 @@ others-extras = mcheck-init.o
 aux := set-freeres thread-freeres
 
 # The Perl script to analyze the output of the mtrace functions.
-ifneq ($(PERL),no)
 install-bin-script = mtrace
 generated += mtrace
 
@@ -261,7 +260,6 @@ address-width=10
 else
 address-width=18
 endif
-endif
 
 # Unless we get a test for the availability of libgd which also works
 # for cross-compiling we disable the memusagestat generation in this
@@ -349,7 +347,7 @@ sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
 
 $(objpfx)mtrace: mtrace.pl
 	rm -f $@.new
-	sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
+	sed -e 's|@XXX@|$(address-width)|' \
 	    -e 's|@VERSION@|$(version)|' \
 	    -e 's|@PKGVERSION@|$(PKGVERSION)|' \
 	    -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl
index 075da0d9f1..dc6085820e 100644
--- a/malloc/mtrace.pl
+++ b/malloc/mtrace.pl
@@ -1,6 +1,6 @@
-#! @PERL@
-eval "exec @PERL@ -S $0 $@"
-    if 0;
+#! /bin/sh
+eval exec "perl -e 'shift; \$progname=shift; shift; require \$progname'" . "$0" . "$@"
+   if 0;
 # Copyright (C) 1997-2024 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 # Based on the mtrace.awk script.
@@ -22,7 +22,6 @@ eval "exec @PERL@ -S $0 $@"
 $VERSION = "@VERSION@";
 $PKGVERSION = "@PKGVERSION@";
 $REPORT_BUGS_TO = '@REPORT_BUGS_TO@';
-$progname = $0;
 
 sub usage {
     print "Usage: mtrace [OPTION]... [Binary] MtraceData\n";

base-commit: 4f1cf0c0e1764bd77235b07ff63631e866939ec6


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

* Re: [PATCH v3] malloc: Always install mtrace (bug 31892)
  2024-06-19 15:47 [PATCH v3] malloc: Always install mtrace (bug 31892) Florian Weimer
@ 2024-06-19 18:13 ` Carlos O'Donell
  2024-06-20  8:53 ` Andreas Schwab
  1 sibling, 0 replies; 4+ messages in thread
From: Carlos O'Donell @ 2024-06-19 18:13 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

On 6/19/24 11:47 AM, Florian Weimer wrote:
> Generation of the Perl script does not depend on Perl, so we can
> always install it even if $(PERL) is not set during the build.
> 
> Change the malloc/mtrace.pl text substition not to rely on $(PERL).
> Instead use PATH at run time to find the Perl interpreter. The Perl
> interpreter cannot execute directly a script that starts with
> “#! /bin/sh”: it always executes it with /bin/sh.  There is no
> perl command line switch to disable this behavior.  Instead, use
> the Perl require function to execute the script.  The additional
> shift calls remove the “.” shell arguments.  Perl interprets the
> “.” as a string concatenation operator, making the expression
> syntactically valid.

LGTM. Thanks for fixing this!

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
 
> ---
> v3: Git mishap did not squash together both changes.  Restore the
>     removal of the $(PERL) conditional.
> 
>  malloc/Makefile  | 4 +---
>  malloc/mtrace.pl | 7 +++----
>  2 files changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/malloc/Makefile b/malloc/Makefile
> index cc14cf66c9..02aff1bd1d 100644
> --- a/malloc/Makefile
> +++ b/malloc/Makefile
> @@ -250,7 +250,6 @@ others-extras = mcheck-init.o
>  aux := set-freeres thread-freeres
>  
>  # The Perl script to analyze the output of the mtrace functions.
> -ifneq ($(PERL),no)
>  install-bin-script = mtrace
>  generated += mtrace
>  
> @@ -261,7 +260,6 @@ address-width=10
>  else
>  address-width=18
>  endif
> -endif
>  
>  # Unless we get a test for the availability of libgd which also works
>  # for cross-compiling we disable the memusagestat generation in this
> @@ -349,7 +347,7 @@ sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
>  
>  $(objpfx)mtrace: mtrace.pl
>  	rm -f $@.new
> -	sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
> +	sed -e 's|@XXX@|$(address-width)|' \
>  	    -e 's|@VERSION@|$(version)|' \
>  	    -e 's|@PKGVERSION@|$(PKGVERSION)|' \
>  	    -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
> diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl
> index 075da0d9f1..dc6085820e 100644
> --- a/malloc/mtrace.pl
> +++ b/malloc/mtrace.pl
> @@ -1,6 +1,6 @@
> -#! @PERL@
> -eval "exec @PERL@ -S $0 $@"
> -    if 0;
> +#! /bin/sh
> +eval exec "perl -e 'shift; \$progname=shift; shift; require \$progname'" . "$0" . "$@"
> +   if 0;
>  # Copyright (C) 1997-2024 Free Software Foundation, Inc.
>  # This file is part of the GNU C Library.
>  # Based on the mtrace.awk script.
> @@ -22,7 +22,6 @@ eval "exec @PERL@ -S $0 $@"
>  $VERSION = "@VERSION@";
>  $PKGVERSION = "@PKGVERSION@";
>  $REPORT_BUGS_TO = '@REPORT_BUGS_TO@';
> -$progname = $0;
>  
>  sub usage {
>      print "Usage: mtrace [OPTION]... [Binary] MtraceData\n";
> 
> base-commit: 4f1cf0c0e1764bd77235b07ff63631e866939ec6
> 

-- 
Cheers,
Carlos.


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

* Re: [PATCH v3] malloc: Always install mtrace (bug 31892)
  2024-06-19 15:47 [PATCH v3] malloc: Always install mtrace (bug 31892) Florian Weimer
  2024-06-19 18:13 ` Carlos O'Donell
@ 2024-06-20  8:53 ` Andreas Schwab
  2024-06-20  9:14   ` Florian Weimer
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2024-06-20  8:53 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

On Jun 19 2024, Florian Weimer wrote:

> +#! /bin/sh
> +eval exec "perl -e 'shift; \$progname=shift; shift; require \$progname'" . "$0" . "$@"

eval expands the arguments a second time, so they need to be quoted twice.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH v3] malloc: Always install mtrace (bug 31892)
  2024-06-20  8:53 ` Andreas Schwab
@ 2024-06-20  9:14   ` Florian Weimer
  0 siblings, 0 replies; 4+ messages in thread
From: Florian Weimer @ 2024-06-20  9:14 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

* Andreas Schwab:

> On Jun 19 2024, Florian Weimer wrote:
>
>> +#! /bin/sh
>> +eval exec "perl -e 'shift; \$progname=shift; shift; require \$progname'" . "$0" . "$@"
>
> eval expands the arguments a second time, so they need to be quoted twice.

I acknowledge that this is a problem.  I will try to come up with a
solution.  If I can't find one, I will revert this.

Thanks,
Florian


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

end of thread, other threads:[~2024-06-20  9:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-19 15:47 [PATCH v3] malloc: Always install mtrace (bug 31892) Florian Weimer
2024-06-19 18:13 ` Carlos O'Donell
2024-06-20  8:53 ` Andreas Schwab
2024-06-20  9:14   ` Florian Weimer

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).