1 |
commit: 0ebc3cb8dc5588d7be43b07cfd24fed93e8523a2 |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jun 1 02:10:27 2014 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Jun 1 02:10:27 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=0ebc3cb8 |
7 |
|
8 |
misc/ldd: recursively search all_dt_needed_paths |
9 |
|
10 |
--- |
11 |
misc/ldd/ldd.py | 17 ++++++++++++----- |
12 |
1 file changed, 12 insertions(+), 5 deletions(-) |
13 |
|
14 |
diff --git a/misc/ldd/ldd.py b/misc/ldd/ldd.py |
15 |
index 1819607..3574137 100755 |
16 |
--- a/misc/ldd/ldd.py |
17 |
+++ b/misc/ldd/ldd.py |
18 |
@@ -78,7 +78,7 @@ def ldpaths(ld_so_conf='/etc/ld.so.conf'): |
19 |
|
20 |
def dynamic_dt_needed_paths( dt_needed, eclass, paths): |
21 |
""" Search library paths for the library file corresponding |
22 |
- to the DT_NEEDED and ELF Class. |
23 |
+ to the given DT_NEEDED and ELF Class. |
24 |
""" |
25 |
dt_needed_paths = {} |
26 |
for n in dt_needed: |
27 |
@@ -97,20 +97,25 @@ def dynamic_dt_needed_paths( dt_needed, eclass, paths): |
28 |
return dt_needed_paths |
29 |
|
30 |
|
31 |
-def all_dt_needed_paths(f, paths): |
32 |
+def all_dynamic_dt_needed_paths(f, paths): |
33 |
+ """ Return a dictionary of all the DT_NEEDED => Library Paths for |
34 |
+ a given ELF file obtained by recursively following linkage. |
35 |
+ """ |
36 |
with open(f, 'rb') as file: |
37 |
try: |
38 |
readelf = ReadElf(file) |
39 |
eclass = readelf.elf_class() |
40 |
# This needs to be iterated until we traverse the entire linkage tree |
41 |
dt_needed = readelf.dynamic_dt_needed() |
42 |
- dt_needed_paths = dynamic_dt_needed_paths( dt_needed, eclass, paths) |
43 |
+ dt_needed_paths = dynamic_dt_needed_paths(dt_needed, eclass, paths) |
44 |
for n, lib in dt_needed_paths.items(): |
45 |
- sys.stdout.write('\t%s => %s\n' % (n, lib)) |
46 |
+ dt_needed_paths = dict(all_dynamic_dt_needed_paths(lib, paths), **dt_needed_paths) |
47 |
except ELFError as ex: |
48 |
sys.stderr.write('ELF error: %s\n' % ex) |
49 |
sys.exit(1) |
50 |
|
51 |
+ return dt_needed_paths |
52 |
+ |
53 |
|
54 |
SCRIPT_DESCRIPTION = 'Print shared library dependencies' |
55 |
VERSION_STRING = '%%prog: based on pyelftools %s' % __version__ |
56 |
@@ -136,7 +141,9 @@ def main(): |
57 |
for f in args: |
58 |
if len(args) > 1: |
59 |
sys.stdout.write('%s : \n' % f) |
60 |
- all_dt_needed_paths(f, paths) |
61 |
+ all_dt_needed_paths = all_dynamic_dt_needed_paths(f, paths) |
62 |
+ for n, lib in all_dt_needed_paths.items(): |
63 |
+ sys.stdout.write('\t%s => %s\n' % (n, lib)) |
64 |
|
65 |
if __name__ == '__main__': |
66 |
main() |