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 C1DD913835A for ; Fri, 16 Apr 2021 15:08:27 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BCB90E0824; Fri, 16 Apr 2021 15:08:26 +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 93ACAE0824 for ; Fri, 16 Apr 2021 15:08:26 +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 1F2CC340BDD for ; Fri, 16 Apr 2021 15:08:25 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A9B4064D for ; Fri, 16 Apr 2021 15:08:23 +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: <1618585568.8d2fa4fe36cf525bc5a16ec176d0fbe79cfab8e6.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: 8d2fa4fe36cf525bc5a16ec176d0fbe79cfab8e6 X-VCS-Branch: master Date: Fri, 16 Apr 2021 15:08:23 +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: 7f2de64c-cad5-4994-9f60-36114b263d13 X-Archives-Hash: 7cae87aa4531e0bc5b4087cd3301f35d commit: 8d2fa4fe36cf525bc5a16ec176d0fbe79cfab8e6 Author: Mike Frysinger chromium org> AuthorDate: Fri Apr 16 15:06:08 2021 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Apr 16 15:06:08 2021 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=8d2fa4fe lddtree: add --cwd option Rather than rely on ambient environmental settings (the cwd), allow users to override the cwd explicitly when processing paths. Bug: https://bugs.gentoo.org/653586 Signed-off-by: Mike Frysinger gentoo.org> lddtree.py | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/lddtree.py b/lddtree.py index d91e729..b8fde0c 100755 --- a/lddtree.py +++ b/lddtree.py @@ -277,13 +277,14 @@ def ParseLdSoConf(ldso_conf, root='/', debug=False, _first=True): return paths -def LoadLdpaths(root='/', prefix='', debug=False): +def LoadLdpaths(root='/', cwd=None, prefix='', debug=False): """Load linker paths from common locations This parses the ld.so.conf and LD_LIBRARY_PATH env var. Args: root: The root tree to prepend to paths + cwd: The path to resolve relative paths against prefix: The path under |root| to search debug: Enable debug output @@ -305,7 +306,7 @@ def LoadLdpaths(root='/', prefix='', debug=False): else: # XXX: If this contains $ORIGIN, we probably have to parse this # on a per-ELF basis so it can get turned into the right thing. - ldpaths['env'] = ParseLdPaths(env_ldpath, path='') + ldpaths['env'] = ParseLdPaths(env_ldpath, cwd=cwd, path='') # Load up /etc/ld.so.conf. ldpaths['conf'] = ParseLdSoConf(root + prefix + '/etc/ld.so.conf', root=root, @@ -374,7 +375,8 @@ def FindLib(elf, lib, ldpaths, root='/', debug=False): # We abuse the _all_libs state. We probably shouldn't, but we do currently. # pylint: disable=dangerous-default-value -def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, +def ParseELF(path, root='/', cwd=None, prefix='', + ldpaths={'conf':[], 'env':[], 'interp':[]}, display=None, debug=False, _first=True, _all_libs={}): """Parse the ELF dependency tree of the specified file @@ -382,6 +384,7 @@ def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[ path: The ELF to scan root: The root tree to prepend to paths; this applies to interp and rpaths only as |path| and |ldpaths| are expected to be prefixed already + cwd: The path to resolve relative paths against. prefix: The path under |root| to search ldpaths: dict containing library paths to search; should have the keys: conf, env, interp @@ -467,9 +470,9 @@ def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[ for t in segment.iter_tags(): if t.entry.d_tag == 'DT_RPATH': - rpaths = ParseLdPaths(bstr(t.rpath), root=root, path=path) + rpaths = ParseLdPaths(bstr(t.rpath), root=root, cwd=cwd, path=path) elif t.entry.d_tag == 'DT_RUNPATH': - runpaths = ParseLdPaths(bstr(t.runpath), root=root, path=path) + runpaths = ParseLdPaths(bstr(t.runpath), root=root, cwd=cwd, path=path) elif t.entry.d_tag == 'DT_NEEDED': libs.append(bstr(t.needed)) if runpaths: @@ -511,7 +514,7 @@ def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[ } if fullpath: try: - lret = ParseELF(realpath, root, prefix, ldpaths, display=fullpath, + lret = ParseELF(realpath, root, cwd, prefix, ldpaths, display=fullpath, debug=debug, _first=False, _all_libs=_all_libs) except exceptions.ELFError as e: warn('%s: %s' % (realpath, e)) @@ -681,18 +684,6 @@ def GetParser(): parser.add_argument('-a', '--all', action='store_true', default=False, help='Show all duplicated dependencies') - parser.add_argument('-R', '--root', - default=os.environ.get('ROOT', ''), type=str, - action=_NormalizePathAction, - help='Search for all files/dependencies in ROOT') - parser.add_argument('-P', '--prefix', - default=os.environ.get( - 'EPREFIX', '@GENTOO_PORTAGE_EPREFIX@'), type=str, - action=_NormalizePathAction, - help='Specify EPREFIX for binaries (for Gentoo Prefix)') - parser.add_argument('--no-auto-root', - dest='auto_root', action='store_false', default=True, - help='Do not automatically prefix input ELFs with ROOT') parser.add_argument('-l', '--list', action='store_true', default=False, help='Display output in a simple list (easy for copying)') @@ -711,6 +702,23 @@ def GetParser(): help='Show version information') parser.add_argument('path', nargs='+') + group = parser.add_argument_group('Path options') + group.add_argument('-R', '--root', + default=os.environ.get('ROOT', ''), type=str, + action=_NormalizePathAction, + help='Search for all files/dependencies in ROOT') + group.add_argument('--no-auto-root', + dest='auto_root', action='store_false', default=True, + help='Do not automatically prefix input ELFs with ROOT') + group.add_argument('-C', '--cwd', + default=os.getcwd(), type=str, action=_NormalizePathAction, + help='Path to resolve relative paths against') + group.add_argument('-P', '--prefix', + default=os.environ.get( + 'EPREFIX', '@GENTOO_PORTAGE_EPREFIX@'), type=str, + action=_NormalizePathAction, + help='Specify EPREFIX for binaries (for Gentoo Prefix)') + group = parser.add_argument_group('Copying options') group.add_argument('--copy-to-tree', dest='dest', default=None, type=str, @@ -754,12 +762,14 @@ def main(argv): parser.error('pick one handler for non-ELFs: skip or copy') dbg(options.debug, 'root =', options.root) + dbg(options.debug, 'cwd =', options.cwd) if options.dest: dbg(options.debug, 'dest =', options.dest) if not paths: err('missing ELF files to scan') - ldpaths = LoadLdpaths(options.root, options.prefix, debug=options.debug) + ldpaths = LoadLdpaths(options.root, cwd=options.cwd, prefix=options.prefix, + debug=options.debug) dbg(options.debug, 'ldpaths[conf] =', ldpaths['conf']) dbg(options.debug, 'ldpaths[env] =', ldpaths['env']) @@ -794,7 +804,7 @@ def main(argv): matched = True try: - elf = ParseELF(realpath, options.root, options.prefix, ldpaths, + elf = ParseELF(realpath, options.root, options.cwd, options.prefix, ldpaths, display=p, debug=options.debug) except exceptions.ELFError as e: if options.skip_non_elfs: