1 |
commit: b196a92359419799bd414be7f5643fd5b8545e37 |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed May 28 16:32:49 2014 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed May 28 16:32:49 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=b196a923 |
7 |
|
8 |
misc/ldd: refactor all_dt_needed_paths for recursion |
9 |
|
10 |
--- |
11 |
misc/ldd/ldd.py | 33 +++++++++++++++++++-------------- |
12 |
1 file changed, 19 insertions(+), 14 deletions(-) |
13 |
|
14 |
diff --git a/misc/ldd/ldd.py b/misc/ldd/ldd.py |
15 |
index 5a15786..1819607 100755 |
16 |
--- a/misc/ldd/ldd.py |
17 |
+++ b/misc/ldd/ldd.py |
18 |
@@ -96,6 +96,22 @@ def dynamic_dt_needed_paths( dt_needed, eclass, paths): |
19 |
|
20 |
return dt_needed_paths |
21 |
|
22 |
+ |
23 |
+def all_dt_needed_paths(f, paths): |
24 |
+ with open(f, 'rb') as file: |
25 |
+ try: |
26 |
+ readelf = ReadElf(file) |
27 |
+ eclass = readelf.elf_class() |
28 |
+ # This needs to be iterated until we traverse the entire linkage tree |
29 |
+ dt_needed = readelf.dynamic_dt_needed() |
30 |
+ dt_needed_paths = dynamic_dt_needed_paths( dt_needed, eclass, paths) |
31 |
+ for n, lib in dt_needed_paths.items(): |
32 |
+ sys.stdout.write('\t%s => %s\n' % (n, lib)) |
33 |
+ except ELFError as ex: |
34 |
+ sys.stderr.write('ELF error: %s\n' % ex) |
35 |
+ sys.exit(1) |
36 |
+ |
37 |
+ |
38 |
SCRIPT_DESCRIPTION = 'Print shared library dependencies' |
39 |
VERSION_STRING = '%%prog: based on pyelftools %s' % __version__ |
40 |
|
41 |
@@ -118,20 +134,9 @@ def main(): |
42 |
paths = ldpaths() |
43 |
|
44 |
for f in args: |
45 |
- with open(f, 'rb') as file: |
46 |
- try: |
47 |
- readelf = ReadElf(file) |
48 |
- if len(args) > 1: |
49 |
- sys.stdout.write('%s : \n' % f) |
50 |
- eclass = readelf.elf_class() |
51 |
- # This needs to be iterated until we traverse the entire linkage tree |
52 |
- dt_needed = readelf.dynamic_dt_needed() |
53 |
- dt_needed_paths = dynamic_dt_needed_paths( dt_needed, eclass, paths) |
54 |
- for n, lib in dt_needed_paths.items(): |
55 |
- sys.stdout.write('\t%s => %s\n' % (n, lib)) |
56 |
- except ELFError as ex: |
57 |
- sys.stderr.write('ELF error: %s\n' % ex) |
58 |
- sys.exit(1) |
59 |
+ if len(args) > 1: |
60 |
+ sys.stdout.write('%s : \n' % f) |
61 |
+ all_dt_needed_paths(f, paths) |
62 |
|
63 |
if __name__ == '__main__': |
64 |
main() |