Bug 31892 - Always install mtrace.
Summary: Always install mtrace.
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: build (show other bugs)
Version: 2.40
: P2 normal
Target Milestone: 2.40
Assignee: Florian Weimer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-13 17:17 UTC by Carlos O'Donell
Modified: 2024-06-21 11:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2024-06-13 17:17:15 UTC
The malloc/Makefile conflates PERL=no with running perl code *and* installing mtrace. We should always install mtrace, but we might not always be able to run the script (lack of perl on the host).

252 # The Perl script to analyze the output of the mtrace functions.
253 ifneq ($(PERL),no)
254 install-bin-script = mtrace
255 generated += mtrace
256 
257 # The Perl script will print addresses and to do this nicely we must know
258 # whether we are on a 32 or 64 bit machine.
259 ifneq ($(findstring wordsize-32,$(config-sysdirs)),)
260 address-width=10
261 else
262 address-width=18
263 endif
264 endif

My position is that we should just always install mtrace.

The existing mtrace tests are predicated on PERL being detected, so it should work.
Comment 1 Joseph Myers 2024-06-13 18:44:20 UTC
It also conflates the $(PERL) path determined on the system building glibc with the @PERL@ substituted in the mtrace.pl script that's a path on the system running glibc; the paths need not be the same even if perl is found (but obviously a script starting "#! no" would be bad).
Comment 2 Carlos O'Donell 2024-06-13 19:06:02 UTC
The following tests are incorrectly conditionalized:

FAIL: misc/tst-allocate_once-mem
FAIL: misc/tst-error1-mem
FAIL: nptl/tst-stack3-mem
FAIL: posix/bug-ga2-mem
FAIL: posix/bug-glob2-mem
FAIL: posix/bug-regex14-mem
FAIL: posix/bug-regex2-mem
FAIL: posix/bug-regex21-mem
FAIL: posix/bug-regex31-mem
FAIL: posix/bug-regex36-mem
FAIL: posix/tst-boost-mem
FAIL: posix/tst-fnmatch-mem
FAIL: posix/tst-glob-tilde-mem
FAIL: posix/tst-pcre-mem
FAIL: posix/tst-rxspencer-no-utf8-mem
FAIL: posix/tst-vfork3-mem
FAIL: stdio-common/tst-printf-bz18872-mem
FAIL: stdio-common/tst-printf-bz25691-mem
FAIL: stdio-common/tst-printf-fp-free-mem
FAIL: stdio-common/tst-printf-fp-leak-mem
FAIL: stdio-common/tst-vfprintf-width-prec-mem
Comment 3 Florian Weimer 2024-06-14 10:09:17 UTC
Patch posted:

[PATCH] malloc: Always install mtrace (bug 31892)
<https://inbox.sourceware.org/libc-alpha/87bk43u99n.fsf@oldenburg.str.redhat.com/>
Comment 4 Carlos O'Donell 2024-06-14 16:02:09 UTC
More incorrectly conditionalized tests:

FAIL: check-local-headers
FAIL: catgets/tst-catgets-mem
FAIL: elf/noload-mem
FAIL: elf/tst-leaks1-mem
FAIL: libio/test-fmemopen-mem
FAIL: libio/tst-bz22415-mem
FAIL: libio/tst-bz24228-mem
FAIL: libio/tst-fdopen-seek-failure-mem
FAIL: libio/tst-fopenloc-mem
Comment 5 Carlos O'Donell 2024-06-14 16:03:44 UTC
(In reply to Florian Weimer from comment #3)
> Patch posted:
> 
> [PATCH] malloc: Always install mtrace (bug 31892)
> <https://inbox.sourceware.org/libc-alpha/87bk43u99n.fsf@oldenburg.str.redhat.
> com/>

Florian and I disucssed that this patch needs to take into account what happens when perl is not installed. So we need a v2 to account for more details e.g. fallback default if perl isn't installed (like in the minimized buildroots on Fedora builders if you disable certain parts of the glibc build).

I think there is a valid use case where you haven't yet bootstrapped perl and are building glibc and want this to succeed with some sensible default.
Comment 6 Florian Weimer 2024-06-14 16:14:12 UTC
(In reply to Carlos O'Donell from comment #5)
> (In reply to Florian Weimer from comment #3)
> > Patch posted:
> > 
> > [PATCH] malloc: Always install mtrace (bug 31892)
> > <https://inbox.sourceware.org/libc-alpha/87bk43u99n.fsf@oldenburg.str.redhat.
> > com/>
> 
> Florian and I disucssed that this patch needs to take into account what
> happens when perl is not installed. So we need a v2 to account for more
> details e.g. fallback default if perl isn't installed (like in the minimized
> buildroots on Fedora builders if you disable certain parts of the glibc
> build).

I just posted a v2:

[PATCH v2] malloc: Always install mtrace (bug 31892)
<https://inbox.sourceware.org/libc-alpha/87plsjqzlb.fsf@oldenburg.str.redhat.com/>

It took me a while to figure out a way to get Perl to run a Perl script with a #!/bin/sh line.
Comment 7 Florian Weimer 2024-06-20 08:33:29 UTC
Fixed for 2.40 via:

commit 086910fc41655152812b515dc324d2ac0dc36e67
Author: Florian Weimer <fweimer@redhat.com>
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 <carlos@redhat.com>
Comment 8 Andreas Schwab 2024-06-20 09:18:05 UTC
The script now has insufficient quoting.
Comment 9 Florian Weimer 2024-06-21 11:15:52 UTC
The quoting issue was fixed via:

commit dd144dce21c864781fade4561581d50fb4549956
Author: Florian Weimer <fweimer@redhat.com>
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.