Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: build/android/gyp/pack_arm_relocations.py

Issue 1072533002: crazy linker: convert relocation unpacking to Android style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates to gn to match gyp. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/all.gyp ('k') | build/android/pack_arm_relocations.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Pack ARM relative relocations in a library (or copy unchanged). 7 """Pack relocations in a library (or copy unchanged).
8 8
9 If --enable-packing and --configuration-name=='Release', invoke the 9 If --enable-packing and --configuration-name=='Release', invoke the
10 relocation_packer tool to pack the .rel.dyn or .rela.dyn section in the given 10 relocation_packer tool to pack the .rel.dyn or .rela.dyn section in the given
11 library files. This step is inserted after the libraries are stripped. 11 library files. This step is inserted after the libraries are stripped.
12 Packing adds a new .android.rel.dyn or .android.rela.dyn section to the file
13 and reduces the size of .rel.dyn or .rela.dyn accordingly.
14 12
15 Currently packing only understands ARM32 shared libraries. For all other 13 If --enable-packing is zero, the script copies files verbatim, with no
16 architectures --enable-packing should be set to zero. In this case the 14 attempt to pack relocations.
17 script copies files verbatim, with no attempt to pack relative relocations.
18 15
19 Any library listed in --exclude-packing-list is also copied verbatim, 16 Any library listed in --exclude-packing-list is also copied verbatim,
20 irrespective of any --enable-packing setting. Typically this would be 17 irrespective of any --enable-packing setting. Typically this would be
21 'libchromium_android_linker.so'. 18 'libchromium_android_linker.so'.
22 """ 19 """
23 20
24 import optparse 21 import optparse
25 import os 22 import os
26 import shlex 23 import shlex
27 import shutil 24 import shutil
28 import sys 25 import sys
29 import tempfile 26 import tempfile
30 27
31 from util import build_utils 28 from util import build_utils
32 29
33 def PackArmLibraryRelocations(android_pack_relocations, 30 def PackLibraryRelocations(android_pack_relocations, library_path, output_path):
34 android_objcopy, 31 shutil.copy(library_path, output_path)
35 has_relocations_with_addends,
36 library_path,
37 output_path):
38 # Select an appropriate name for the section we add.
39 if has_relocations_with_addends:
40 new_section = '.android.rela.dyn'
41 else:
42 new_section = '.android.rel.dyn'
43
44 # Copy and add a 'NULL' packed relocations section for the packing tool.
45 with tempfile.NamedTemporaryFile() as stream:
46 stream.write('NULL')
47 stream.flush()
48 objcopy_command = [android_objcopy,
49 '--add-section', '%s=%s' % (new_section, stream.name),
50 library_path, output_path]
51 build_utils.CheckOutput(objcopy_command)
52
53 # Pack R_ARM_RELATIVE relocations.
54 pack_command = [android_pack_relocations, output_path] 32 pack_command = [android_pack_relocations, output_path]
55 build_utils.CheckOutput(pack_command) 33 build_utils.CheckOutput(pack_command)
56 34
57 35
58 def CopyArmLibraryUnchanged(library_path, output_path): 36 def CopyLibraryUnchanged(library_path, output_path):
59 shutil.copy(library_path, output_path) 37 shutil.copy(library_path, output_path)
60 38
61 39
62 def main(args): 40 def main(args):
63 args = build_utils.ExpandFileArgs(args) 41 args = build_utils.ExpandFileArgs(args)
64 parser = optparse.OptionParser() 42 parser = optparse.OptionParser()
65 build_utils.AddDepfileOption(parser) 43 build_utils.AddDepfileOption(parser)
66 parser.add_option('--clear-dir', action='store_true', 44 parser.add_option('--clear-dir', action='store_true',
67 help='If set, the destination directory will be deleted ' 45 help='If set, the destination directory will be deleted '
68 'before copying files to it. This is highly recommended to ' 46 'before copying files to it. This is highly recommended to '
69 'ensure that no stale files are left in the directory.') 47 'ensure that no stale files are left in the directory.')
70 48
71 parser.add_option('--configuration-name', 49 parser.add_option('--configuration-name',
72 default='Release', 50 default='Release',
73 help='Gyp configuration name (i.e. Debug, Release)') 51 help='Gyp configuration name (i.e. Debug, Release)')
74 parser.add_option('--enable-packing', 52 parser.add_option('--enable-packing',
75 choices=['0', '1'], 53 choices=['0', '1'],
76 help=('Pack relocations if 1 and configuration name is \'Release\',' 54 help=('Pack relocations if 1 and configuration name is \'Release\','
77 ' otherwise plain file copy')) 55 ' otherwise plain file copy'))
78 parser.add_option('--has-relocations-with-addends',
79 choices=['0', '1'],
80 help=('Pack into \'.android.rela.dyn\' if 1, else \'.android.rel.dyn\''))
81 parser.add_option('--exclude-packing-list', 56 parser.add_option('--exclude-packing-list',
82 default='', 57 default='',
83 help='Names of any libraries explicitly not packed') 58 help='Names of any libraries explicitly not packed')
84 parser.add_option('--android-pack-relocations', 59 parser.add_option('--android-pack-relocations',
85 help='Path to the ARM relocations packer binary') 60 help='Path to the relocations packer binary')
86 parser.add_option('--android-objcopy',
87 help='Path to the toolchain\'s objcopy binary')
88 parser.add_option('--stripped-libraries-dir', 61 parser.add_option('--stripped-libraries-dir',
89 help='Directory for stripped libraries') 62 help='Directory for stripped libraries')
90 parser.add_option('--packed-libraries-dir', 63 parser.add_option('--packed-libraries-dir',
91 help='Directory for packed libraries') 64 help='Directory for packed libraries')
92 parser.add_option('--libraries', action='append', 65 parser.add_option('--libraries', action='append',
93 help='List of libraries') 66 help='List of libraries')
94 parser.add_option('--stamp', help='Path to touch on success') 67 parser.add_option('--stamp', help='Path to touch on success')
95 68
96 options, _ = parser.parse_args(args) 69 options, _ = parser.parse_args(args)
97 enable_packing = (options.enable_packing == '1' and 70 enable_packing = (options.enable_packing == '1' and
98 options.configuration_name == 'Release') 71 options.configuration_name == 'Release')
99 has_relocations_with_addends = (options.has_relocations_with_addends == '1')
100 exclude_packing_set = set(shlex.split(options.exclude_packing_list)) 72 exclude_packing_set = set(shlex.split(options.exclude_packing_list))
101 73
102 libraries = [] 74 libraries = []
103 for libs_arg in options.libraries: 75 for libs_arg in options.libraries:
104 libraries += build_utils.ParseGypList(libs_arg) 76 libraries += build_utils.ParseGypList(libs_arg)
105 77
106 if options.clear_dir: 78 if options.clear_dir:
107 build_utils.DeleteDirectory(options.packed_libraries_dir) 79 build_utils.DeleteDirectory(options.packed_libraries_dir)
108 80
109 build_utils.MakeDirectory(options.packed_libraries_dir) 81 build_utils.MakeDirectory(options.packed_libraries_dir)
110 82
111 for library in libraries: 83 for library in libraries:
112 library_path = os.path.join(options.stripped_libraries_dir, library) 84 library_path = os.path.join(options.stripped_libraries_dir, library)
113 output_path = os.path.join( 85 output_path = os.path.join(
114 options.packed_libraries_dir, os.path.basename(library)) 86 options.packed_libraries_dir, os.path.basename(library))
115 87
116 if enable_packing and library not in exclude_packing_set: 88 if enable_packing and library not in exclude_packing_set:
117 PackArmLibraryRelocations(options.android_pack_relocations, 89 PackLibraryRelocations(options.android_pack_relocations,
118 options.android_objcopy, 90 library_path,
119 has_relocations_with_addends, 91 output_path)
120 library_path,
121 output_path)
122 else: 92 else:
123 CopyArmLibraryUnchanged(library_path, output_path) 93 CopyLibraryUnchanged(library_path, output_path)
124 94
125 if options.depfile: 95 if options.depfile:
126 build_utils.WriteDepfile( 96 build_utils.WriteDepfile(
127 options.depfile, 97 options.depfile,
128 libraries + build_utils.GetPythonDependencies()) 98 libraries + build_utils.GetPythonDependencies())
129 99
130 if options.stamp: 100 if options.stamp:
131 build_utils.Touch(options.stamp) 101 build_utils.Touch(options.stamp)
132 102
133 return 0 103 return 0
134 104
135 105
136 if __name__ == '__main__': 106 if __name__ == '__main__':
137 sys.exit(main(sys.argv[1:])) 107 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « build/all.gyp ('k') | build/android/pack_arm_relocations.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698