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

Side by Side Diff: tools/cygprofile/patch_orderfile.py

Issue 902633002: Fix a bunch of issues blocking 64-bit orderfile generation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Patch an orderfile. 6 """Patch an orderfile.
7 7
8 Starting with a list of symbols in a binary and an orderfile (ordered list of 8 Starting with a list of symbols in a binary and an orderfile (ordered list of
9 symbols), matches the symbols in the orderfile and augments each symbol with the 9 symbols), matches the symbols in the orderfile and augments each symbol with the
10 symbols residing at the same address (due to having identical code). 10 symbols residing at the same address (due to having identical code).
11 11
12 Note: It is possible to have. 12 Note: It is possible to have.
13 - Several symbols mapping to the same offset in the binary. 13 - Several symbols mapping to the same offset in the binary.
14 - Several offsets for a given symbol (because we strip the ".clone." suffix) 14 - Several offsets for a given symbol (because we strip the ".clone." suffix)
15 15
16 TODO(lizeb): Since the suffix ".clone." is only used with -O3 that we don't 16 TODO(lizeb): Since the suffix ".clone." is only used with -O3 that we don't
17 currently use, simplify the logic by removing the suffix handling. 17 currently use, simplify the logic by removing the suffix handling.
18 18
19 The general pipeline is: 19 The general pipeline is:
20 1. Get the symbol infos (name, offset, size, section) from the binary 20 1. Get the symbol infos (name, offset, size, section) from the binary
21 2. Get the symbol names from the orderfile 21 2. Get the symbol names from the orderfile
22 3. Find the orderfile symbol names in the symbols coming from the binary 22 3. Find the orderfile symbol names in the symbols coming from the binary
23 4. For each symbol found, get all the symbols at the same address 23 4. For each symbol found, get all the symbols at the same address
24 5. Output them to an updated orderfile, with several different prefixes 24 5. Output them to an updated orderfile, with several different prefixes
25 """ 25 """
26 26
27 import collections 27 import collections
28 import logging 28 import logging
29 import optparse
29 import sys 30 import sys
30 31
31 import symbol_extractor 32 import symbol_extractor
32 33
33 # Prefixes for the symbols. We strip them from the incoming symbols, and add 34 # Prefixes for the symbols. We strip them from the incoming symbols, and add
34 # them back in the output file. 35 # them back in the output file.
35 _PREFIXES = ('.text.startup.', '.text.hot.', '.text.unlikely.', '.text.') 36 _PREFIXES = ('.text.startup.', '.text.hot.', '.text.unlikely.', '.text.')
36 37
37 38
38 def _RemoveClone(name): 39 def _RemoveClone(name):
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 unique_outputs = set() 198 unique_outputs = set()
198 for name in symbol_names: 199 for name in symbol_names:
199 for prefix in _PREFIXES: 200 for prefix in _PREFIXES:
200 linker_section = prefix + name 201 linker_section = prefix + name
201 if not linker_section in unique_outputs: 202 if not linker_section in unique_outputs:
202 output_file.write(linker_section + '\n') 203 output_file.write(linker_section + '\n')
203 unique_outputs.add(linker_section) 204 unique_outputs.add(linker_section)
204 205
205 206
206 def main(argv): 207 def main(argv):
208 parser = optparse.OptionParser()
209 parser.add_option('--target_arch', action='store', type='string',
210 dest='arch', default='arm',
211 help='The target architecture for libchrome.so')
212 options, argv = parser.parse_args(argv)
207 if len(argv) != 3: 213 if len(argv) != 3:
208 print 'Usage: %s <unpatched_orderfile> <libchrome.so>' % argv[0] 214 print 'Usage: %s <unpatched_orderfile> <libchrome.so>' % argv[0]
209 return 1 215 return 1
210 orderfile_filename = argv[1] 216 orderfile_filename = argv[1]
211 binary_filename = argv[2] 217 binary_filename = argv[2]
218 symbol_extractor.SetArchitecture(options.arch)
212 (offset_to_symbol_infos, name_to_symbol_infos) = _GroupSymbolInfosFromBinary( 219 (offset_to_symbol_infos, name_to_symbol_infos) = _GroupSymbolInfosFromBinary(
213 binary_filename) 220 binary_filename)
214 profiled_symbols = GetSymbolsFromOrderfile(orderfile_filename) 221 profiled_symbols = GetSymbolsFromOrderfile(orderfile_filename)
215 expanded_symbols = _ExpandSymbols( 222 expanded_symbols = _ExpandSymbols(
216 profiled_symbols, name_to_symbol_infos, offset_to_symbol_infos) 223 profiled_symbols, name_to_symbol_infos, offset_to_symbol_infos)
217 _PrintSymbolsWithPrefixes(expanded_symbols, sys.stdout) 224 _PrintSymbolsWithPrefixes(expanded_symbols, sys.stdout)
218 # The following is needed otherwise Gold only applies a partial sort. 225 # The following is needed otherwise Gold only applies a partial sort.
219 print '.text' # gets methods not in a section, such as assembly 226 print '.text' # gets methods not in a section, such as assembly
220 print '.text.*' # gets everything else 227 print '.text.*' # gets everything else
221 return 0 228 return 0
222 229
223 230
224 if __name__ == '__main__': 231 if __name__ == '__main__':
225 logging.basicConfig(level=logging.INFO) 232 logging.basicConfig(level=logging.INFO)
226 sys.exit(main(sys.argv)) 233 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698