1 |
commit: 320b76139ae04eea3cbe74c424cda489bbf61882 |
2 |
Author: Mike Frysinger <vapier <AT> chromium <DOT> org> |
3 |
AuthorDate: Thu Jan 28 22:38:43 2016 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jan 28 22:38:43 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=320b7613 |
7 |
|
8 |
lddtree: handle exceptions thrown when parsing other ELFs |
9 |
|
10 |
We have a top level exception handler for catching ELF errors, but if we |
11 |
hit a problem with a dependency, we end up diagnosing it as a problem in |
12 |
the first ELF. e.g. If "foo" is linked against "libc.so", and "libc.so" |
13 |
is a linker script, when we try to read the libc.so ELF, it fails, and |
14 |
we end up saying: |
15 |
lddtree: warning: foo: Magic number does not match |
16 |
|
17 |
This makes no sense because "foo" is a proper ELF with the right magic, |
18 |
and we end up halting the whole parsing process. Now we show: |
19 |
lddtree: warning: /usr/lib/libc.so: Magic number does not match |
20 |
foo (interpreter => /some/interp) |
21 |
libc.so => None |
22 |
|
23 |
lddtree.py | 16 +++++++++++----- |
24 |
1 file changed, 11 insertions(+), 5 deletions(-) |
25 |
|
26 |
diff --git a/lddtree.py b/lddtree.py |
27 |
index 100f475..e663d32 100755 |
28 |
--- a/lddtree.py |
29 |
+++ b/lddtree.py |
30 |
@@ -338,9 +338,12 @@ def FindLib(elf, lib, ldpaths, root='/', debug=False): |
31 |
|
32 |
if os.path.exists(target): |
33 |
with open(target, 'rb') as f: |
34 |
- libelf = ELFFile(f) |
35 |
- if CompatibleELFs(elf, libelf): |
36 |
- return (target, path) |
37 |
+ try: |
38 |
+ libelf = ELFFile(f) |
39 |
+ if CompatibleELFs(elf, libelf): |
40 |
+ return (target, path) |
41 |
+ except exceptions.ELFError as e: |
42 |
+ warn('%s: %s' % (target, e)) |
43 |
|
44 |
return (None, None) |
45 |
|
46 |
@@ -475,8 +478,11 @@ def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[ |
47 |
'needed': [], |
48 |
} |
49 |
if fullpath: |
50 |
- lret = ParseELF(realpath, root, prefix, ldpaths, display=fullpath, |
51 |
- debug=debug, _first=False, _all_libs=_all_libs) |
52 |
+ try: |
53 |
+ lret = ParseELF(realpath, root, prefix, ldpaths, display=fullpath, |
54 |
+ debug=debug, _first=False, _all_libs=_all_libs) |
55 |
+ except exceptions.ELFError as e: |
56 |
+ warn('%s: %s' % (realpath, e)) |
57 |
_all_libs[lib]['needed'] = lret['needed'] |
58 |
|
59 |
del elf |