OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Helper script to close over all transitive dependencies of a given .nexe | 5 """Helper script to close over all transitive dependencies of a given .nexe |
6 executable. | 6 executable. |
7 | 7 |
8 e.g. Given | 8 e.g. Given |
9 A -> B | 9 A -> B |
10 B -> C | 10 B -> C |
11 B -> D | 11 B -> D |
12 C -> E | 12 C -> E |
13 | 13 |
14 where "A -> B" means A depends on B, then GetNeeded(A) will return A, B, C, D | 14 where "A -> B" means A depends on B, then GetNeeded(A) will return A, B, C, D |
15 and E. | 15 and E. |
16 """ | 16 """ |
17 | 17 |
18 import os | 18 import os |
19 import re | 19 import re |
20 import subprocess | 20 import subprocess |
21 | 21 |
22 import elf | 22 import elf |
23 | 23 |
24 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
25 SDK_DIR = os.path.dirname(os.path.dirname(SCRIPT_DIR)) | |
26 | |
24 NeededMatcher = re.compile('^ *NEEDED *([^ ]+)\n$') | 27 NeededMatcher = re.compile('^ *NEEDED *([^ ]+)\n$') |
25 FormatMatcher = re.compile('^(.+):\\s*file format (.+)\n$') | 28 FormatMatcher = re.compile('^(.+):\\s*file format (.+)\n$') |
26 | 29 |
27 RUNNABLE_LD = 'runnable-ld.so' # Name of the dynamic loader | 30 RUNNABLE_LD = 'runnable-ld.so' # Name of the dynamic loader |
28 | 31 |
29 OBJDUMP_ARCH_MAP = { | 32 OBJDUMP_ARCH_MAP = { |
30 # Names returned by Linux's objdump: | 33 # Names returned by Linux's objdump: |
31 'elf64-x86-64': 'x86-64', | 34 'elf64-x86-64': 'x86-64', |
32 'elf32-i386': 'x86-32', | 35 'elf32-i386': 'x86-32', |
33 'elf32-little': 'arm', | 36 'elf32-little': 'arm', |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 for dirname in lib_path: | 207 for dirname in lib_path: |
205 # The libc.so files in the the glibc toolchain is actually a linker | 208 # The libc.so files in the the glibc toolchain is actually a linker |
206 # script which references libc.so.<SHA1>. This means the lib.so itself | 209 # script which references libc.so.<SHA1>. This means the lib.so itself |
207 # does not end up in the NEEDED section for glibc. However with bionic | 210 # does not end up in the NEEDED section for glibc. However with bionic |
208 # the SONAME is actually libc.so. If we pass glibc's libc.so to objdump | 211 # the SONAME is actually libc.so. If we pass glibc's libc.so to objdump |
209 # if fails to parse it, os this filters out libc.so expept for within | 212 # if fails to parse it, os this filters out libc.so expept for within |
210 # the bionic toolchain. | 213 # the bionic toolchain. |
211 # TODO(noelallen): Remove this once the SONAME in bionic is made to be | 214 # TODO(noelallen): Remove this once the SONAME in bionic is made to be |
212 # unique in the same it is under glibc: | 215 # unique in the same it is under glibc: |
213 # https://code.google.com/p/nativeclient/issues/detail?id=3833 | 216 # https://code.google.com/p/nativeclient/issues/detail?id=3833 |
214 if name == 'libc.so' and 'bionic' not in dirname: | 217 rel_dirname = os.path.relpath(dirname, SDK_DIR) |
218 if name == 'libc.so' and 'bionic' not in rel_dirname: | |
Sam Clegg
2014/06/18 18:21:30
Why not just update the check to "_arm_bionic"?
T
binji
2014/06/18 18:29:35
Because the problem would pop up again if the user
Sam Clegg
2014/06/18 18:36:23
Ok. I guess I was thinking that this check horrib
binji
2014/06/18 18:39:51
You're right, it's a hack either way. :) The real
| |
215 continue | 219 continue |
216 filename = os.path.join(dirname, name) | 220 filename = os.path.join(dirname, name) |
217 if os.path.exists(filename): | 221 if os.path.exists(filename): |
218 files.append(filename) | 222 files.append(filename) |
219 if not files: | 223 if not files: |
220 raise Error('cannot find library %s' % name) | 224 raise Error('cannot find library %s' % name) |
221 return files | 225 return files |
222 | 226 |
223 | 227 |
224 def _GetNeededStatic(main_files): | 228 def _GetNeededStatic(main_files): |
225 needed = {} | 229 needed = {} |
226 for filename in main_files: | 230 for filename in main_files: |
227 arch = elf.ParseElfHeader(filename)[0] | 231 arch = elf.ParseElfHeader(filename)[0] |
228 needed[filename] = arch | 232 needed[filename] = arch |
229 return needed | 233 return needed |
OLD | NEW |