summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2014-07-30 04:23:52 -0400
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-01 22:40:54 +0000
commit918b1ec7e71a84a86f0a4c6cffdabeb35cd84fb9 (patch)
treeb4d6800e46f21d6dfced1b66cb3d8b1fd1ee781a
parentdff3e7bf27bb84aa6b68321631d84822151dcde0 (diff)
downloadchromite-918b1ec7e71a84a86f0a4c6cffdabeb35cd84fb9.tar.gz
lddtree: resolve command line symlinks against the selected root
When we're given a path to look up in the root on the command line, but it's a symlink itself, we end up implicitly resovling it to the / dir. Add some logic so we resolve it relative to root instead. BUG=chromium:393018 TEST=`lddtree /usr/bin/as --root /build/stumpy_moblab/` now works TEST=`cbuildbot arm-generic-full` passes Change-Id: Ie593686e462a0fe5eb8af2d91ee8160e2fa448d0 Reviewed-on: https://chromium-review.googlesource.com/210354 Reviewed-by: Luis Lozano <llozano@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
-rw-r--r--third_party/lddtree.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/third_party/lddtree.py b/third_party/lddtree.py
index 69cb70475..27924799f 100644
--- a/third_party/lddtree.py
+++ b/third_party/lddtree.py
@@ -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.49 2014/07/30 04:34:09 vapier Exp $
-
-# TODO: Handle symlinks.
+# $Header: /var/cvsroot/gentoo-projects/pax-utils/lddtree.py,v 1.53 2014/08/01 02:20:20 vapier Exp $
"""Read the ELF dependency tree and show it
@@ -443,7 +441,7 @@ def _NormalizePath(option, _opt, value, parser):
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.53 2014/08/01 02:20:20 vapier Exp $'.split()
print('%s-%s %s %s' % (d[1].split('.')[0], d[2], d[3], d[4]))
sys.exit(0)
@@ -696,10 +694,26 @@ they need will be placed into /foo/lib/ only.""")
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
@@ -712,7 +726,7 @@ they need will be placed into /foo/lib/ only.""")
'runpath': [],
'rpath': [],
'path': p,
- 'realpath': p,
+ 'realpath': realpath,
}
_ActionCopy(options, elf)
continue