From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 61EED1382C5 for ; Fri, 16 Apr 2021 03:41:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9F44CE07D7; Fri, 16 Apr 2021 03:41:39 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 80559E07D7 for ; Fri, 16 Apr 2021 03:41:39 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5437F335D16 for ; Fri, 16 Apr 2021 03:41:38 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B5B37643 for ; Fri, 16 Apr 2021 03:41:36 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1618543447.cb5da5f0f8ca714a552b70f201ace2eb24f0d2b1.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: lddtree.py X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: cb5da5f0f8ca714a552b70f201ace2eb24f0d2b1 X-VCS-Branch: master Date: Fri, 16 Apr 2021 03:41:36 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: eee8c342-4cb3-4804-88f6-c8e7853d08ea X-Archives-Hash: ea28da5ff4dea517d3b93656fade6ce1 commit: cb5da5f0f8ca714a552b70f201ace2eb24f0d2b1 Author: Mike Frysinger chromium org> AuthorDate: Fri Apr 16 03:24:07 2021 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Apr 16 03:24:07 2021 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=cb5da5f0 lddtree: use ldso's --argv0 when available Newer glibc has a --argv0 option in current releases to explicitly set argv[0]. This is useful for the generated shell wrappers as we need to rename it (with an .elf suffix) and that can either confuse the output or break tools that inspect their argv[0] strictly. Signed-off-by: Mike Frysinger gentoo.org> lddtree.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lddtree.py b/lddtree.py index 7ec04fa..fae39e0 100755 --- a/lddtree.py +++ b/lddtree.py @@ -43,6 +43,7 @@ import argparse import functools import glob import errno +import mmap import os import shutil import sys @@ -123,6 +124,17 @@ def dedupe(items): return [seen.setdefault(x, x) for x in items if x not in seen] +@functools.lru_cache(maxsize=None) +def interp_supports_argv0(interp) -> bool: + """See whether |interp| supports the --argv0 option. + + Starting with glibc-2.33, the ldso supports --argv0 to override argv[0]. + """ + with open(interp, 'rb') as fp: + with mmap.mmap(fp.fileno(), 0, prot=mmap.PROT_READ) as mm: + return mm.find(b'--argv0') >= 0 + + def GenerateLdsoWrapper(root, path, interp, libpaths=()): """Generate a shell script wrapper which uses local ldso to run the ELF @@ -145,6 +157,7 @@ def GenerateLdsoWrapper(root, path, interp, libpaths=()): interp_name), 'libpaths': ':'.join(['${basedir}/' + os.path.relpath(p, basedir) for p in libpaths]), + 'argv0_arg': '--argv0 "$0"' if interp_supports_argv0(interp) else '', } wrapper = """#!/bin/sh if ! base=$(realpath "$0" 2>/dev/null); then @@ -154,12 +167,13 @@ if ! base=$(realpath "$0" 2>/dev/null); then esac fi basedir=${base%%/*} -exec \ - "${basedir}/%(interp)s" \ - --library-path "%(libpaths)s" \ - --inhibit-cache \ - --inhibit-rpath '' \ - "${base}.elf" \ +exec \\ + "${basedir}/%(interp)s" \\ + %(argv0_arg)s \\ + --library-path "%(libpaths)s" \\ + --inhibit-cache \\ + --inhibit-rpath '' \\ + "${base}.elf" \\ "$@" """ wrappath = root + path