diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2014-06-03 20:20:34 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-06-03 20:20:34 -0400 |
commit | a32f1be0a8aa82db6d1b4992b8c13793538e8870 (patch) | |
tree | fdb2452273ae5fdf27360a913bb47e12b999a97f | |
parent | misc/ldd: recursively search all_dt_needed_paths (diff) | |
download | elfix-a32f1be0a8aa82db6d1b4992b8c13793538e8870.tar.gz elfix-a32f1be0a8aa82db6d1b4992b8c13793538e8870.tar.bz2 elfix-a32f1be0a8aa82db6d1b4992b8c13793538e8870.zip |
misc/ldd: add caching to speed up recursion
-rwxr-xr-x | misc/ldd/ldd.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/misc/ldd/ldd.py b/misc/ldd/ldd.py index 3574137..447614e 100755 --- a/misc/ldd/ldd.py +++ b/misc/ldd/ldd.py @@ -76,23 +76,35 @@ def ldpaths(ld_so_conf='/etc/ld.so.conf'): return paths +# We cache the dependencies for speed. The structure is +# { ELFClass : { SONAME : library, ... }, ELFClass : ... } +cache = {} + def dynamic_dt_needed_paths( dt_needed, eclass, paths): """ Search library paths for the library file corresponding to the given DT_NEEDED and ELF Class. """ + global cache + if not eclass in cache: + cache[eclass] = {} + dt_needed_paths = {} for n in dt_needed: - for p in paths: - lib = p + os.sep + n - if os.path.exists(lib): - with open(lib, 'rb') as file: - try: - readlib = ReadElf(file) - if eclass == readlib.elf_class(): - dt_needed_paths[n] = lib - except ELFError as ex: - sys.stderr.write('ELF error: %s\n' % ex) - sys.exit(1) + if n in cache[eclass].keys(): + dt_needed_paths[n] = cache[eclass][n] + else: + for p in paths: + lib = p + os.sep + n + if os.path.exists(lib): + with open(lib, 'rb') as file: + try: + readlib = ReadElf(file) + if eclass == readlib.elf_class(): + dt_needed_paths[n] = lib + cache[eclass][n] = lib + except ELFError as ex: + sys.stderr.write('ELF error: %s\n' % ex) + sys.exit(1) return dt_needed_paths |