[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/11/20 01:22:36 Modified: lddtree.py Log: lddtree.py: if we could not find the lib for copying, issue a warning and skip the path Revision ChangesPath 1.56 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.56view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.56content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.55r2=1.56 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- lddtree.py 20 Nov 2014 01:17:23 - 1.55 +++ lddtree.py 20 Nov 2014 01:22:36 - 1.56 @@ -4,7 +4,7 @@ # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.55 2014/11/20 01:17:23 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.56 2014/11/20 01:22:36 vapier Exp $ Read the ELF dependency tree and show it @@ -447,7 +447,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.55 2014/11/20 01:17:23 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.56 2014/11/20 01:22:36 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0) @@ -557,6 +557,9 @@ for lib in elf['libs']: libdata = elf['libs'][lib] path = libdata['realpath'] +if path is None: + warn('could not locate library: %s' % lib) + continue if not options.libdir: libpaths.add(_StripRoot(os.path.dirname(path))) _copy(path, libdata['path'], outdir=options.libdir)
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/08/01 01:39:33 Modified: lddtree.py Log: lddtree.py: drop TODO since we should handle symlinks now Revision ChangesPath 1.52 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.52view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.52content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.51r2=1.52 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- lddtree.py 30 Jul 2014 14:35:38 - 1.51 +++ lddtree.py 1 Aug 2014 01:39:33 - 1.52 @@ -4,9 +4,7 @@ # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.51 2014/07/30 14:35:38 vapier Exp $ - -# TODO: Handle symlinks. +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.52 2014/08/01 01:39:33 vapier Exp $ Read the ELF dependency tree and show it @@ -443,7 +441,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.51 2014/07/30 14:35:38 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.52 2014/08/01 01:39:33 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0)
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/07/30 08:22:07 Modified: lddtree.py Log: lddtree: do symlink resolution on args on the command line This is needed when given a path which itself is an absolute symlink. If we deref it as-is, we end up poking into / instead of $ROOT. Revision ChangesPath 1.50 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.50view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.50content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.49r2=1.50 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- lddtree.py 30 Jul 2014 04:34:09 - 1.49 +++ lddtree.py 30 Jul 2014 08:22:07 - 1.50 @@ -4,7 +4,7 @@ # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.49 2014/07/30 04:34:09 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.50 2014/07/30 08:22:07 vapier Exp $ # TODO: Handle symlinks. @@ -307,7 +307,7 @@ def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, - debug=False, _first=True, _all_libs={}): + display=None, debug=False, _first=True, _all_libs={}): Parse the ELF dependency tree of the specified file Args: @@ -317,6 +317,7 @@ prefix: The path under |root| to search ldpaths: dict containing library paths to search; should have the keys: conf, env, interp +display: The path to show rather than |path| debug: Enable debug output _first: Recursive use only; is this the first ELF ? _all_libs: Recursive use only; dict of all libs we've seen @@ -343,7 +344,7 @@ ldpaths = ldpaths.copy() ret = { 'interp': None, -'path': path, +'path': path if display is None else display, 'needed': [], 'rpath': [], 'runpath': [], @@ -422,7 +423,8 @@ 'needed': [], } if fullpath: -lret = ParseELF(fullpath, root, prefix, ldpaths, debug, False, _all_libs) +lret = ParseELF(fullpath, root, prefix, ldpaths, debug=debug, +_first=False, _all_libs=_all_libs) _all_libs[lib]['needed'] = lret['needed'] del elf @@ -435,7 +437,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.49 2014/07/30 04:34:09 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.50 2014/07/30 08:22:07 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0) @@ -684,10 +686,26 @@ matched = False for p in glob.iglob(path): + # Once we've processed the globs, resolve the symlink. This way you can + # operate on a path that is an absolute symlink itself. e.g.: + # $ ln -sf /bin/bash $PWD/root/bin/sh + # $ lddtree --root $PWD/root /bin/sh + # First we'd turn /bin/sh into $PWD/root/bin/sh, then we want to resolve + # the symlink to $PWD/root/bin/bash rather than a plain /bin/bash. + dbg(options.debug, ' globbed =', p) + if not path.startswith('/'): +realpath = os.path.realpath(path) + elif options.auto_root: +realpath = readlink(p, options.root, prefixed=True) + else: +realpath = path + if path != realpath: +dbg(options.debug, ' resolved=', realpath) + matched = True try: -elf = ParseELF(p, options.root, options.prefix, ldpaths, - debug=options.debug) +elf = ParseELF(realpath, options.root, options.prefix, ldpaths, + display=p, debug=options.debug) except exceptions.ELFError as e: if options.skip_non_elfs: continue
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/07/30 14:35:39 Modified: lddtree.py Log: lddtree.py: save the original path as well as the full path for symlinks SONAMEs are usually symlinks, so we need to manually dereference them to get to the right file, but we want to save the original name so we can copy them to the right place Revision ChangesPath 1.51 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.51view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.51content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.50r2=1.51 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- lddtree.py 30 Jul 2014 08:22:07 - 1.50 +++ lddtree.py 30 Jul 2014 14:35:38 - 1.51 @@ -4,7 +4,7 @@ # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.50 2014/07/30 08:22:07 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.51 2014/07/30 14:35:38 vapier Exp $ # TODO: Handle symlinks. @@ -63,6 +63,10 @@ def readlink(path, root, prefixed=False): Like os.readlink(), but relative to a |root| + This does not currently handle the pathological case: +/lib/foo.so - ../../../../../../../foo.so + This relies on the .. entries in / to point to itself. + Args: path: The symlink to read root: The path to use for resolving absolute symlinks @@ -81,7 +85,7 @@ while os.path.islink(root + path): path = os.path.join(os.path.dirname(path), os.readlink(root + path)) - return (root + path) if prefixed else path + return normpath((root + path) if prefixed else path) def makedirs(path): @@ -284,7 +288,7 @@ debug: Enable debug output Returns: -the full path to the desired library +Tuple of the full path to the desired library and the real path to it dbg(debug, ' FindLib(%s)' % lib) @@ -293,17 +297,16 @@ target = readlink(path, root, prefixed=True) if path != target: dbg(debug, 'checking: %s - %s' % (path, target)) - path = target else: dbg(debug, 'checking:', path) -if os.path.exists(path): - with open(path, 'rb') as f: +if os.path.exists(target): + with open(target, 'rb') as f: libelf = ELFFile(f) if CompatibleELFs(elf, libelf): - return path + return (target, path) - return None + return (None, None) def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, @@ -345,6 +348,7 @@ ret = { 'interp': None, 'path': path if display is None else display, +'realpath': path, 'needed': [], 'rpath': [], 'runpath': [], @@ -367,6 +371,7 @@ ret['interp'] = normpath(root + interp) ret['libs'][os.path.basename(interp)] = { 'path': ret['interp'], + 'realpath': readlink(ret['interp'], root, prefixed=True), 'needed': [], } # XXX: Should read it and scan for /lib paths. @@ -417,8 +422,9 @@ continue if all_ldpaths is None: all_ldpaths = rpaths + ldpaths['rpath'] + ldpaths['env'] + runpaths + ldpaths['runpath'] + ldpaths['conf'] + ldpaths['interp'] - fullpath = FindLib(elf, lib, all_ldpaths, root, debug=debug) + realpath, fullpath = FindLib(elf, lib, all_ldpaths, root, debug=debug) _all_libs[lib] = { +'realpath': realpath, 'path': fullpath, 'needed': [], } @@ -437,7 +443,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.50 2014/07/30 08:22:07 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.51 2014/07/30 14:35:38 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0) @@ -486,8 +492,9 @@ def _StripRoot(path): return path[len(options.root) - 1:] - def _copy(src, striproot=True, wrapit=False, libpaths=(), outdir=None): -if src is None: + def _copy(realsrc, src, striproot=True, wrapit=False, libpaths=(), +outdir=None): +if realsrc is None: return if wrapit: @@ -506,7 +513,7 @@ try: # See if they're the same file. nstat = os.stat(dst + ('.elf' if wrapit else '')) - ostat = os.stat(src) + ostat = os.stat(realsrc) for field in ('mode', 'mtime', 'size'): if getattr(ostat, 'st_' + field) != \ getattr(nstat, 'st_' + field): @@ -522,10 +529,10 @@ makedirs(os.path.dirname(dst)) try: - shutil.copy2(src, dst) + shutil.copy2(realsrc, dst) except IOError:
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/07/30 04:06:56 Modified: lddtree.py Log: lddtree.py: update copyright Revision ChangesPath 1.45 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.45view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.45content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.44r2=1.45 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- lddtree.py 20 Mar 2014 08:25:45 - 1.44 +++ lddtree.py 30 Jul 2014 04:06:56 - 1.45 @@ -1,9 +1,10 @@ #!/usr/bin/python -# Copyright 2012-2013 Gentoo Foundation -# Copyright 2012-2013 Mike Frysinger vap...@gentoo.org +# Copyright 2012-2014 Gentoo Foundation +# Copyright 2012-2014 Mike Frysinger vap...@gentoo.org +# Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.44 2014/03/20 08:25:45 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.45 2014/07/30 04:06:56 vapier Exp $ # TODO: Handle symlinks. @@ -385,7 +386,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.44 2014/03/20 08:25:45 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.45 2014/07/30 04:06:56 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0)
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/07/30 04:07:43 Modified: lddtree.py Log: lddtree.py: use basename of argv[0] for warnings as it looks nicer Revision ChangesPath 1.46 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.46view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.46content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.45r2=1.46 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- lddtree.py 30 Jul 2014 04:06:56 - 1.45 +++ lddtree.py 30 Jul 2014 04:07:43 - 1.46 @@ -4,7 +4,7 @@ # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.45 2014/07/30 04:06:56 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.46 2014/07/30 04:07:43 vapier Exp $ # TODO: Handle symlinks. @@ -29,7 +29,7 @@ def warn(msg, prefix='warning'): Write |msg| to stderr with a |prefix| before it - print('%s: %s: %s' % (sys.argv[0], prefix, msg), file=sys.stderr) + print('%s: %s: %s' % (os.path.basename(sys.argv[0]), prefix, msg), file=sys.stderr) def err(msg, status=1): @@ -386,7 +386,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.45 2014/07/30 04:06:56 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.46 2014/07/30 04:07:43 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0)
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/07/30 04:16:25 Modified: lddtree.py Log: lddtree.py: rework debug handling and add a bit more throughout the processing Revision ChangesPath 1.47 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.47view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.47content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.46r2=1.47 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- lddtree.py 30 Jul 2014 04:07:43 - 1.46 +++ lddtree.py 30 Jul 2014 04:16:25 - 1.47 @@ -4,7 +4,7 @@ # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.46 2014/07/30 04:07:43 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.47 2014/07/30 04:16:25 vapier Exp $ # TODO: Handle symlinks. @@ -38,6 +38,12 @@ sys.exit(status) +def dbg(debug, *args, **kwargs): + Pass |args| and |kwargs| to print() when |debug| is True + if debug: +print(*args, **kwargs) + + def bstr(buf): Decode the byte string into a string return buf.decode('utf-8') @@ -243,19 +249,22 @@ elf1.header['e_machine'] == elf2.header['e_machine']) -def FindLib(elf, lib, ldpaths): +def FindLib(elf, lib, ldpaths, debug=False): Try to locate a |lib| that is compatible to |elf| in the given |ldpaths| Args: -elf: the elf which the library should be compatible with (ELF wise) -lib: the library (basename) to search for -ldpaths: a list of paths to search +elf: The elf which the library should be compatible with (ELF wise) +lib: The library (basename) to search for +ldpaths: A list of paths to search +debug: Enable debug output Returns: the full path to the desired library + dbg(debug, ' FindLib(%s)' % lib) for ldpath in ldpaths: path = os.path.join(ldpath, lib) +dbg(debug, 'checking:', path) if os.path.exists(path): with open(path, 'rb') as f: libelf = ELFFile(f) @@ -265,7 +274,7 @@ def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, - _first=True, _all_libs={}): + debug=False, _first=True, _all_libs={}): Parse the ELF dependency tree of the specified file Args: @@ -275,6 +284,7 @@ prefix: The path under |root| to search ldpaths: dict containing library paths to search; should have the keys: conf, env, interp +debug: Enable debug output _first: Recursive use only; is this the first ELF ? _all_libs: Recursive use only; dict of all libs we've seen @@ -307,6 +317,8 @@ 'libs': _all_libs, } + dbg(debug, 'ParseELF(%s)' % path) + with open(path, 'rb') as f: elf = ELFFile(f) @@ -317,6 +329,7 @@ continue interp = bstr(segment.get_interp_name()) +dbg(debug, ' interp =', interp) ret['interp'] = normpath(root + interp) ret['libs'][os.path.basename(interp)] = { 'path': ret['interp'], @@ -327,6 +340,7 @@ normpath(root + os.path.dirname(interp)), normpath(root + prefix + '/usr' + os.path.dirname(interp).lstrip(prefix)), ] +dbg(debug, ' ldpaths[interp] =', ldpaths['interp']) break # Parse the ELF's dynamic tags. @@ -356,6 +370,8 @@ # used at runtime to locate things. ldpaths['rpath'] = rpaths ldpaths['runpath'] = runpaths + dbg(debug, ' ldpaths[rpath] =', rpaths) + dbg(debug, ' ldpaths[runpath] =', runpaths) ret['rpath'] = rpaths ret['runpath'] = runpaths ret['needed'] = libs @@ -367,7 +383,7 @@ continue if all_ldpaths is None: all_ldpaths = rpaths + ldpaths['rpath'] + ldpaths['env'] + runpaths + ldpaths['runpath'] + ldpaths['conf'] + ldpaths['interp'] - fullpath = FindLib(elf, lib, all_ldpaths) + fullpath = FindLib(elf, lib, all_ldpaths, debug=debug) _all_libs[lib] = { 'path': fullpath, 'needed': [], @@ -386,7 +402,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.46 2014/07/30 04:07:43 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.47 2014/07/30 04:16:25 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0) @@ -612,32 +628,33 @@ if options.skip_non_elfs and options.copy_non_elfs: parser.error('pick one handler for non-ELFs: skip or copy') - if options.debug: -print('root =', options.root) -if options.dest: - print('dest =',
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/07/30 04:28:41 Modified: lddtree.py Log: lddtree.py: update ParseELF arg list after previous commit Revision ChangesPath 1.48 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.48view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.48content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.47r2=1.48 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- lddtree.py 30 Jul 2014 04:16:25 - 1.47 +++ lddtree.py 30 Jul 2014 04:28:41 - 1.48 @@ -4,7 +4,7 @@ # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.47 2014/07/30 04:16:25 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.48 2014/07/30 04:28:41 vapier Exp $ # TODO: Handle symlinks. @@ -389,7 +389,7 @@ 'needed': [], } if fullpath: -lret = ParseELF(fullpath, root, prefix, ldpaths, False, _all_libs) +lret = ParseELF(fullpath, root, prefix, ldpaths, debug, False, _all_libs) _all_libs[lib]['needed'] = lret['needed'] del elf @@ -402,7 +402,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.47 2014/07/30 04:16:25 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.48 2014/07/30 04:28:41 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0)
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/07/30 04:34:09 Modified: lddtree.py Log: lddtree.py: when searching for libs, make sure we resolve symlinks inside the root before checking if they exist Revision ChangesPath 1.49 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.49view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.49content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.48r2=1.49 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.48 retrieving revision 1.49 diff -u -r1.48 -r1.49 --- lddtree.py 30 Jul 2014 04:28:41 - 1.48 +++ lddtree.py 30 Jul 2014 04:34:09 - 1.49 @@ -4,7 +4,7 @@ # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.48 2014/07/30 04:28:41 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.49 2014/07/30 04:34:09 vapier Exp $ # TODO: Handle symlinks. @@ -60,6 +60,30 @@ return os.path.normpath(path).replace('//', '/') +def readlink(path, root, prefixed=False): + Like os.readlink(), but relative to a |root| + + Args: +path: The symlink to read +root: The path to use for resolving absolute symlinks +prefixed: When False, the |path| must not have |root| prefixed to it, nor + will the return value have |root| prefixed. When True, |path| + must have |root| prefixed, and the return value will have |root| + added. + + Returns: +A fully resolved symlink path + + root = root.rstrip('/') + if prefixed: +path = path[len(root):] + + while os.path.islink(root + path): +path = os.path.join(os.path.dirname(path), os.readlink(root + path)) + + return (root + path) if prefixed else path + + def makedirs(path): Like os.makedirs(), but ignore EEXIST errors try: @@ -249,27 +273,36 @@ elf1.header['e_machine'] == elf2.header['e_machine']) -def FindLib(elf, lib, ldpaths, debug=False): +def FindLib(elf, lib, ldpaths, root='/', debug=False): Try to locate a |lib| that is compatible to |elf| in the given |ldpaths| Args: elf: The elf which the library should be compatible with (ELF wise) lib: The library (basename) to search for ldpaths: A list of paths to search +root: The root path to resolve symlinks debug: Enable debug output Returns: the full path to the desired library dbg(debug, ' FindLib(%s)' % lib) + for ldpath in ldpaths: path = os.path.join(ldpath, lib) -dbg(debug, 'checking:', path) +target = readlink(path, root, prefixed=True) +if path != target: + dbg(debug, 'checking: %s - %s' % (path, target)) + path = target +else: + dbg(debug, 'checking:', path) + if os.path.exists(path): with open(path, 'rb') as f: libelf = ELFFile(f) if CompatibleELFs(elf, libelf): return path + return None @@ -383,7 +416,7 @@ continue if all_ldpaths is None: all_ldpaths = rpaths + ldpaths['rpath'] + ldpaths['env'] + runpaths + ldpaths['runpath'] + ldpaths['conf'] + ldpaths['interp'] - fullpath = FindLib(elf, lib, all_ldpaths, debug=debug) + fullpath = FindLib(elf, lib, all_ldpaths, root, debug=debug) _all_libs[lib] = { 'path': fullpath, 'needed': [], @@ -402,7 +435,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.48 2014/07/30 04:28:41 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.49 2014/07/30 04:34:09 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0)
[gentoo-commits] gentoo-projects commit in pax-utils: lddtree.py
vapier 14/03/20 08:25:45 Modified: lddtree.py Log: lddtree.py: initial prefix support by Benda Xu #488460 Revision ChangesPath 1.44 pax-utils/lddtree.py file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.44view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?rev=1.44content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/lddtree.py?r1=1.43r2=1.44 Index: lddtree.py === RCS file: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- lddtree.py 20 Mar 2014 08:18:06 - 1.43 +++ lddtree.py 20 Mar 2014 08:25:45 - 1.44 @@ -3,7 +3,7 @@ # Copyright 2012-2013 Mike Frysinger vap...@gentoo.org # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 -# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.43 2014/03/20 08:18:06 vapier Exp $ +# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.44 2014/03/20 08:25:45 vapier Exp $ # TODO: Handle symlinks. @@ -184,13 +184,14 @@ return paths -def LoadLdpaths(root='/'): +def LoadLdpaths(root='/', prefix=''): 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 +prefix: The path under |root| to search Returns: dict containing library paths to search @@ -213,7 +214,7 @@ ldpaths['env'] = ParseLdPaths(env_ldpath, path='') # Load up /etc/ld.so.conf. - ldpaths['conf'] = ParseLdSoConf(root + 'etc/ld.so.conf', root=root) + ldpaths['conf'] = ParseLdSoConf(root + prefix + '/etc/ld.so.conf', root=root) return ldpaths @@ -262,7 +263,7 @@ return None -def ParseELF(path, root='/', ldpaths={'conf':[], 'env':[], 'interp':[]}, +def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, _first=True, _all_libs={}): Parse the ELF dependency tree of the specified file @@ -270,6 +271,7 @@ 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 +prefix: The path under |root| to search ldpaths: dict containing library paths to search; should have the keys: conf, env, interp _first: Recursive use only; is this the first ELF ? @@ -322,7 +324,7 @@ # XXX: Should read it and scan for /lib paths. ldpaths['interp'] = [ normpath(root + os.path.dirname(interp)), - normpath(root + '/usr' + os.path.dirname(interp)), + normpath(root + prefix + '/usr' + os.path.dirname(interp).lstrip(prefix)), ] break @@ -370,7 +372,7 @@ 'needed': [], } if fullpath: -lret = ParseELF(fullpath, root, ldpaths, False, _all_libs) +lret = ParseELF(fullpath, root, prefix, ldpaths, False, _all_libs) _all_libs[lib]['needed'] = lret['needed'] del elf @@ -383,7 +385,7 @@ def _ShowVersion(_option, _opt, _value, _parser): - d = '$Id: lddtree.py,v 1.43 2014/03/20 08:18:06 vapier Exp $'.split() + d = '$Id: lddtree.py,v 1.44 2014/03/20 08:25:45 vapier Exp $'.split() print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4])) sys.exit(0) @@ -550,6 +552,10 @@ default=os.environ.get('ROOT', ''), type='string', action='callback', callback=_NormalizePath, help='Search for all files/dependencies in ROOT') + parser.add_option('-P', '--prefix', +default=os.environ.get('EPREFIX', '@GENTOO_PORTAGE_EPREFIX@'), type='string', +action='callback', callback=_NormalizePath, +help='Specify EPREFIX for binaries (for Gentoo Prefix)') parser.add_option('--no-auto-root', dest='auto_root', action='store_false', default=True, help='Do not automatically prefix input ELFs with ROOT') @@ -594,6 +600,8 @@ if options.root != '/': options.root += '/' + if options.prefix == '@''GENTOO_PORTAGE_EPREFIX''@': +options.prefix = '' if options.bindir and options.bindir[0] != '/': parser.error('--bindir accepts absolute paths only') @@ -610,7 +618,7 @@ if not paths: err('missing ELF files to scan') - ldpaths = LoadLdpaths(options.root) + ldpaths = LoadLdpaths(options.root, options.prefix) if options.debug: print('ldpaths[conf] =', ldpaths['conf']) print('ldpaths[env] =', ldpaths['env']) @@ -628,7 +636,7 @@ for p in glob.iglob(path): matched = True try: -elf = ParseELF(p, options.root, ldpaths) +elf = ParseELF(p, options.root, options.prefix, ldpaths) except exceptions.ELFError as e: if options.skip_non_elfs: continue