From 0fa69c9930bdb67f13b4ca5c927c32aa28c89047 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Mon, 22 Jul 2024 12:42:08 +0200 Subject: [PATCH] Support --without testsuite builds without perl installed (#2292195) Backport upstream commits to support installing /usr/bin/mtrace without Perl in the buildroot. Add an explicit dependency on /usr/bin/perl to glibc-utils because it's no longer generated automatically. --- glibc-rh2292195-1.patch | 72 +++++++++++++++++++++++++++++++++++ glibc-rh2292195-2.patch | 84 +++++++++++++++++++++++++++++++++++++++++ glibc-rh2292195-3.patch | 31 +++++++++++++++ glibc.spec | 9 ++++- 4 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 glibc-rh2292195-1.patch create mode 100644 glibc-rh2292195-2.patch create mode 100644 glibc-rh2292195-3.patch diff --git a/glibc-rh2292195-1.patch b/glibc-rh2292195-1.patch new file mode 100644 index 0000000..fc5bbfd --- /dev/null +++ b/glibc-rh2292195-1.patch @@ -0,0 +1,72 @@ +commit 086910fc41655152812b515dc324d2ac0dc36e67 +Author: Florian Weimer +Date: Thu Jun 20 10:32:16 2024 +0200 + + malloc: Always install mtrace (bug 31892) + + 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. + + Reviewed-by: Carlos O'Donell + +diff --git a/malloc/Makefile b/malloc/Makefile +index cc14cf66c9661f99..02aff1bd1dc664c3 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 075da0d9f11da15c..dc6085820e62092c 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"; diff --git a/glibc-rh2292195-2.patch b/glibc-rh2292195-2.patch new file mode 100644 index 0000000..61436e8 --- /dev/null +++ b/glibc-rh2292195-2.patch @@ -0,0 +1,84 @@ +commit dd144dce21c864781fade4561581d50fb4549956 +Author: Florian Weimer +Date: Thu Jun 20 20:55:10 2024 +0200 + + malloc: Replace shell/Perl gate in mtrace + + The previous version expanded $0 and $@ twice. + + The new version defines a q no-op shell command. The Perl syntax + error is masked by the eval Perl function. The q { … } construct + is executed by the shell without errors because the q shell function + was defined, but treated as a non-expanding quoted string by Perl, + effectively hiding its context from the Perl interpreter. As before + the script is read by require instead of executed directly, to avoid + infinite recursion because the #! line contains /bin/sh. + + Introduce the “fatal” function to produce diagnostics that are not + suppressed by “do”. Use “do” instead of “require” because it has + fewer requirements on the executed script than “require”. + + Prefix relative paths with './' because “do” (and “require“ before) + searches for the script in @INC if the path is relative and does not + start with './'. Use $_ to make the trampoline shorter. + + Add an Emacs mode marker to indentify the script as a Perl script. + +diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl +index dc6085820e62092c..0a631a07bc4cfbb6 100644 +--- a/malloc/mtrace.pl ++++ b/malloc/mtrace.pl +@@ -1,6 +1,12 @@ + #! /bin/sh +-eval exec "perl -e 'shift; \$progname=shift; shift; require \$progname'" . "$0" . "$@" +- if 0; ++# -*- 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,6 +28,7 @@ eval exec "perl -e 'shift; \$progname=shift; shift; require \$progname'" . "$0" + $VERSION = "@VERSION@"; + $PKGVERSION = "@PKGVERSION@"; + $REPORT_BUGS_TO = '@REPORT_BUGS_TO@'; ++$progname = $_; + + sub usage { + print "Usage: mtrace [OPTION]... [Binary] MtraceData\n"; +@@ -33,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 +@@ -86,7 +98,7 @@ 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 { +@@ -148,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 () { + my @cols = split (' '); + my $n, $where; diff --git a/glibc-rh2292195-3.patch b/glibc-rh2292195-3.patch new file mode 100644 index 0000000..ef2d7f1 --- /dev/null +++ b/glibc-rh2292195-3.patch @@ -0,0 +1,31 @@ +commit 2a6c922f09e7a1c206e0cbdb4424f1cf101a5bda +Author: Andreas Schwab +Date: Thu Jun 20 14:13:01 2024 +0200 + + mtrace: make shell commands robust against meta characters + + Use the list form of the open function to avoid interpreting meta + characters in the arguments. + +diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl +index 0a631a07bc4cfbb6..32b4da935f7c7c4a 100644 +--- a/malloc/mtrace.pl ++++ b/malloc/mtrace.pl +@@ -87,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 () { + chop; + if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) { +@@ -104,7 +104,7 @@ if ($#ARGV == 0) { + sub addr2line { + my $addr = pop(@_); + my $prog = pop(@_); +- if (open (ADDR, "addr2line -e $prog $addr|")) { ++ if (open (ADDR, "-|", "addr2line", "-e", $prog, $addr)) { + my $line = ; + chomp $line; + close (ADDR); diff --git a/glibc.spec b/glibc.spec index 79de104..9da781f 100644 --- a/glibc.spec +++ b/glibc.spec @@ -170,7 +170,7 @@ Version: %{glibcversion} # - It allows using the Release number without the %%dist tag in the dependency # generator to make the generated requires interchangeable between Rawhide # and ELN (.elnYY < .fcXX). -%global baserelease 19 +%global baserelease 20 Release: %{baserelease}%{?dist} # Licenses: @@ -407,6 +407,9 @@ Patch96: glibc-upstream-2.39-72.patch # NEWS update: glibc-upstream-2.39-73.patch # NEWS update: glibc-upstream-2.39-74.patch Patch97: glibc-upstream-2.39-75.patch +Patch98: glibc-rh2292195-1.patch +Patch99: glibc-rh2292195-2.patch +Patch100: glibc-rh2292195-3.patch ############################################################################## # Continued list of core "glibc" package information: @@ -1160,6 +1163,7 @@ the glibc-devel package instead. %package utils Summary: Development utilities from GNU C library Requires: %{name} = %{version}-%{release} +Requires: /usr/bin/perl %description utils The glibc-utils package contains memusage, a memory usage profiler, @@ -2636,6 +2640,9 @@ update_gconv_modules_cache () %endif %changelog +* Mon Jul 22 2024 Florian Weimer - 2.39-20 +- Support --without testsuite builds without perl installed (#2292195) + * Fri Jul 19 2024 Florian Weimer - 2.39-19 - Add Conflicts:/Obsoletes: for glibc32 to glibc.i686