Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/elfix:master commit in: misc/ldd/
Date: Wed, 04 Jun 2014 00:16:02
Message-Id: 1401841234.a32f1be0a8aa82db6d1b4992b8c13793538e8870.blueness@gentoo
1 commit: a32f1be0a8aa82db6d1b4992b8c13793538e8870
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jun 4 00:20:34 2014 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Wed Jun 4 00:20:34 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=a32f1be0
7
8 misc/ldd: add caching to speed up recursion
9
10 ---
11 misc/ldd/ldd.py | 34 +++++++++++++++++++++++-----------
12 1 file changed, 23 insertions(+), 11 deletions(-)
13
14 diff --git a/misc/ldd/ldd.py b/misc/ldd/ldd.py
15 index 3574137..447614e 100755
16 --- a/misc/ldd/ldd.py
17 +++ b/misc/ldd/ldd.py
18 @@ -76,23 +76,35 @@ def ldpaths(ld_so_conf='/etc/ld.so.conf'):
19 return paths
20
21
22 +# We cache the dependencies for speed. The structure is
23 +# { ELFClass : { SONAME : library, ... }, ELFClass : ... }
24 +cache = {}
25 +
26 def dynamic_dt_needed_paths( dt_needed, eclass, paths):
27 """ Search library paths for the library file corresponding
28 to the given DT_NEEDED and ELF Class.
29 """
30 + global cache
31 + if not eclass in cache:
32 + cache[eclass] = {}
33 +
34 dt_needed_paths = {}
35 for n in dt_needed:
36 - for p in paths:
37 - lib = p + os.sep + n
38 - if os.path.exists(lib):
39 - with open(lib, 'rb') as file:
40 - try:
41 - readlib = ReadElf(file)
42 - if eclass == readlib.elf_class():
43 - dt_needed_paths[n] = lib
44 - except ELFError as ex:
45 - sys.stderr.write('ELF error: %s\n' % ex)
46 - sys.exit(1)
47 + if n in cache[eclass].keys():
48 + dt_needed_paths[n] = cache[eclass][n]
49 + else:
50 + for p in paths:
51 + lib = p + os.sep + n
52 + if os.path.exists(lib):
53 + with open(lib, 'rb') as file:
54 + try:
55 + readlib = ReadElf(file)
56 + if eclass == readlib.elf_class():
57 + dt_needed_paths[n] = lib
58 + cache[eclass][n] = lib
59 + except ELFError as ex:
60 + sys.stderr.write('ELF error: %s\n' % ex)
61 + sys.exit(1)
62
63 return dt_needed_paths