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 86DD51382C5 for ; Fri, 16 Apr 2021 03:39:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A129EE07D7; Fri, 16 Apr 2021 03:39:23 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 401E2E07D7 for ; Fri, 16 Apr 2021 03:39:23 +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 0DBC833BDF0 for ; Fri, 16 Apr 2021 03:39:22 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 44F88647 for ; Fri, 16 Apr 2021 03:39:20 +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.816065b7964ef8ad5a65f1a92190a2f5ff4b3744.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: 816065b7964ef8ad5a65f1a92190a2f5ff4b3744 X-VCS-Branch: master Date: Fri, 16 Apr 2021 03:39:20 +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: 2134e36f-2790-4db7-bbd6-79fb4ed92b7e X-Archives-Hash: 387aeed5329bbd3b330e35fa0d3a270c commit: 816065b7964ef8ad5a65f1a92190a2f5ff4b3744 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=816065b7 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 | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lddtree.py b/lddtree.py index 7ec04fa..6be4fdd 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,18 @@ 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]. + """ + print(interp) + 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 +158,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 +168,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