[v2] malloc: Always install mtrace (bug 31892)

Message ID 87plsjqzlb.fsf@oldenburg.str.redhat.com
State Superseded
Headers
Series [v2] malloc: Always install mtrace (bug 31892) |

Checks

Context Check Description
redhat-pt-bot/TryBot-32bit success Build for i686
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Florian Weimer June 14, 2024, 4:05 p.m. UTC
  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.

Tested on x86_64-linux-gnu with Perl installed.

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


base-commit: 8919429b7553aaee0df74947fee7e0649923674b
  

Comments

Carlos O'Donell June 19, 2024, 3:41 p.m. UTC | #1
On 6/14/24 12:05 PM, 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.

Agreed, but this doesn't fix the bug?

It looks like you need to apply both of your patches together to solve the problem?

I think the correct solution is this patch:
https://inbox.sourceware.org/libc-alpha/87bk43u99n.fsf@oldenburg.str.redhat.com/
plus the changes you have here?

> 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.
> 
> Tested on x86_64-linux-gnu with Perl installed.

Looking forward to a v3.

> ---
>  malloc/Makefile  | 2 +-
>  malloc/mtrace.pl | 7 +++----
>  2 files changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/malloc/Makefile b/malloc/Makefile
> index c7d6678a40..02aff1bd1d 100644
> --- a/malloc/Makefile
> +++ b/malloc/Makefile
> @@ -347,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)|' \

OK. Good, drops PERL replacement.

>  	    -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;

OK. Clever shift shift usage. Use perl by default from the shell search as expected.

>  # 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;

OK. progname defined in the eval exec above.

>  
>  sub usage {
>      print "Usage: mtrace [OPTION]... [Binary] MtraceData\n";
> 
> base-commit: 8919429b7553aaee0df74947fee7e0649923674b
>
  

Patch

diff --git a/malloc/Makefile b/malloc/Makefile
index c7d6678a40..02aff1bd1d 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -347,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";