about summary refs log tree commit diff
path: root/malloc
diff options
context:
space:
mode:
Diffstat (limited to 'malloc')
-rw-r--r--malloc/Makefile4
-rw-r--r--malloc/mtrace.pl28
2 files changed, 21 insertions, 11 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..32b4da935f 100644
--- a/malloc/mtrace.pl
+++ b/malloc/mtrace.pl
@@ -1,6 +1,12 @@
-#! @PERL@
-eval "exec @PERL@ -S $0 $@"
-    if 0;
+#! /bin/sh
+# -*- perl -*-
+eval "q () {
+  :
+}";
+q {
+    exec perl -e '$_ = shift; $_ = "./$_" unless m,^/,; do $_' "$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 +28,7 @@ eval "exec @PERL@ -S $0 $@"
 $VERSION = "@VERSION@";
 $PKGVERSION = "@PKGVERSION@";
 $REPORT_BUGS_TO = '@REPORT_BUGS_TO@';
-$progname = $0;
+$progname = $_;
 
 sub usage {
     print "Usage: mtrace [OPTION]... [Binary] MtraceData\n";
@@ -34,6 +40,11 @@ sub usage {
     exit 0;
 }
 
+sub fatal {
+    print STDERR "$_[0]\n";
+    exit 1;
+}
+
 # We expect two arguments:
 #   #1: the complete path to the binary
 #   #2: the mtrace data filename
@@ -76,7 +87,7 @@ if ($#ARGV == 0) {
     }
     # Set the environment variable LD_TRACE_LOADED_OBJECTS to 2 so the
     # executable is also printed.
-    if (open (locs, "env LD_TRACE_LOADED_OBJECTS=2 $prog |")) {
+    if (open (locs, "-|", "env", "LD_TRACE_LOADED_OBJECTS=2", $prog)) {
 	while (<locs>) {
 	    chop;
 	    if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) {
@@ -87,13 +98,13 @@ if ($#ARGV == 0) {
 	close (LOCS);
     }
 } else {
-    die "Wrong number of arguments, run $progname --help for help.";
+    fatal "Wrong number of arguments, run $progname --help for help.";
 }
 
 sub addr2line {
     my $addr = pop(@_);
     my $prog = pop(@_);
-    if (open (ADDR, "addr2line -e $prog $addr|")) {
+    if (open (ADDR, "-|", "addr2line", "-e", $prog, $addr)) {
 	my $line = <ADDR>;
 	chomp $line;
 	close (ADDR);
@@ -149,7 +160,8 @@ sub location {
 }
 
 $nr=0;
-open(DATA, "<$data") || die "Cannot open mtrace data file";
+open(DATA, "<$data")
+  or fatal "$progname: Cannot open mtrace data file $data: $!";
 while (<DATA>) {
     my @cols = split (' ');
     my $n, $where;