OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """Pack ARM relative relocations in a library (or copy unchanged). | |
8 | |
9 If --enable-packing, invoke the relocation_packer tool to pack the .rel.dyn | |
10 section in the given library files. This step is inserted after the libraries | |
11 are stripped. Packing adds a new .android.rel.dyn section to the file and | |
12 reduces the size of .rel.dyn accordingly. | |
13 | |
14 Currently packing only understands ARM32 shared libraries. For all other | |
15 architectures --enable-packing should be set to zero. In this case the | |
16 script copies files verbatim, with no attempt to pack relative relocations. | |
17 | |
18 Any library listed in --suppress-packing is also copied verbatim, irrespective | |
19 of any --enable-packing setting. Typically, 'libchromium_android_linker.so'. | |
20 """ | |
21 | |
22 import json | |
23 import optparse | |
24 import os | |
25 import shlex | |
26 import shutil | |
27 import sys | |
28 import tempfile | |
29 | |
30 from util import build_utils | |
31 | |
32 def PackArmLibraryRelocations(android_pack_relocations, | |
33 android_objcopy, | |
34 library_path, | |
35 output_path): | |
36 if not build_utils.IsTimeStale(output_path, [library_path]): | |
37 return | |
38 | |
39 # Copy and add a 'NULL' .android.rel.dyn section for the packing tool. | |
40 with tempfile.NamedTemporaryFile() as stream: | |
41 stream.write('NULL') | |
42 stream.flush() | |
43 objcopy_command = [android_objcopy, | |
44 '--add-section', '.android.rel.dyn=%s' % stream.name, | |
45 library_path, output_path] | |
46 build_utils.CheckOutput(objcopy_command) | |
47 | |
48 # Pack R_ARM_RELATIVE relocations. | |
49 pack_command = [android_pack_relocations, output_path] | |
50 build_utils.CheckOutput(pack_command) | |
51 | |
52 | |
53 def CopyArmLibraryUnchanged(library_path, output_path): | |
54 if not build_utils.IsTimeStale(output_path, [library_path]): | |
55 return | |
56 | |
57 shutil.copy(library_path, output_path) | |
58 | |
59 | |
60 def main(): | |
61 parser = optparse.OptionParser() | |
62 | |
63 parser.add_option('--enable-packing', | |
64 choices=['0', '1'], | |
65 help='Pack relocations if 1, otherwise plain file copy') | |
66 parser.add_option('--suppress-packing', | |
67 help='Names of any libraries explicitly not packed') | |
68 parser.add_option('--android-pack-relocations', | |
69 help='Path to the ARM relocations packer binary') | |
70 parser.add_option('--android-objcopy', | |
71 help='Path to the toolchain\'s objcopy binary') | |
72 parser.add_option('--stripped-libraries-dir', | |
73 help='Directory for stripped libraries') | |
74 parser.add_option('--packed-libraries-dir', | |
75 help='Directory for packed libraries') | |
76 parser.add_option('--libraries-file', | |
77 help='Path to json file containing list of libraries') | |
78 parser.add_option('--stamp', help='Path to touch on success') | |
79 | |
80 options, _ = parser.parse_args() | |
81 enable_packing = options.enable_packing == '1' | |
82 if enable_packing: | |
83 suppress_packing = shlex.split(options.suppress_packing) | |
84 else: | |
85 suppress_packing = [] | |
rmcilroy
2014/07/01 11:13:03
nit - just add a default to the parser option?
simonb (inactive)
2014/07/01 14:20:29
Done.
| |
86 | |
87 with open(options.libraries_file, 'r') as libfile: | |
88 libraries = json.load(libfile) | |
89 | |
90 for library in libraries: | |
91 library_path = os.path.join(options.stripped_libraries_dir, library) | |
92 output_path = os.path.join(options.packed_libraries_dir, library) | |
93 | |
94 if enable_packing and library not in suppress_packing: | |
95 PackArmLibraryRelocations(options.android_pack_relocations, | |
96 options.android_objcopy, | |
97 library_path, | |
98 output_path) | |
99 else: | |
100 CopyArmLibraryUnchanged(library_path, output_path) | |
101 | |
102 if options.stamp: | |
103 build_utils.Touch(options.stamp) | |
104 | |
105 return 0 | |
106 | |
107 | |
108 if __name__ == '__main__': | |
109 sys.exit(main()) | |
OLD | NEW |