Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 (offset, length, name) from the binary | 20 1. Get the symbol infos (offset, length, name) from the binary |
|
pasko
2015/02/02 14:32:37
nit:
(name, offset, size, section)
Benoit L
2015/02/02 15:37:05
Done.
| |
| 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 sys | 29 import sys |
| 30 | 30 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 line = _StripPrefix(line) | 115 line = _StripPrefix(line) |
| 116 name = _RemoveClone(line) | 116 name = _RemoveClone(line) |
| 117 if name == '' or name == '*' or name == '.text': | 117 if name == '' or name == '*' or name == '.text': |
| 118 continue | 118 continue |
| 119 if not line in unique_symbols: | 119 if not line in unique_symbols: |
| 120 symbols.append(line) | 120 symbols.append(line) |
| 121 unique_symbols.add(line) | 121 unique_symbols.add(line) |
| 122 return symbols | 122 return symbols |
| 123 | 123 |
| 124 | 124 |
| 125 def _GetSymbolsFromOrderfile(filename): | 125 def GetSymbolsFromOrderfile(filename): |
|
pasko
2015/02/02 14:32:37
thanks for this change. So this natirally leads me
Benoit L
2015/02/02 15:37:05
I would argue that once a function has been writte
pasko
2015/02/02 15:52:28
git blame -C
?
but yeah, I don't like moving func
| |
| 126 """Return the symbols from an orderfile. | 126 """Return the symbols from an orderfile. |
| 127 | 127 |
| 128 Args: | 128 Args: |
| 129 filename: The name of the orderfile. | 129 filename: The name of the orderfile. |
| 130 | 130 |
| 131 Returns: | 131 Returns: |
| 132 A list of symbol names. | 132 A list of symbol names. |
| 133 """ | 133 """ |
| 134 with open(filename, 'r') as f: | 134 with open(filename, 'r') as f: |
| 135 return _GetSymbolsFromStream(f.xreadlines()) | 135 return _GetSymbolsFromStream(f.xreadlines()) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 204 |
| 205 | 205 |
| 206 def main(argv): | 206 def main(argv): |
| 207 if len(argv) != 3: | 207 if len(argv) != 3: |
| 208 print 'Usage: %s <unpatched_orderfile> <libchrome.so>' % argv[0] | 208 print 'Usage: %s <unpatched_orderfile> <libchrome.so>' % argv[0] |
| 209 return 1 | 209 return 1 |
| 210 orderfile_filename = argv[1] | 210 orderfile_filename = argv[1] |
| 211 binary_filename = argv[2] | 211 binary_filename = argv[2] |
| 212 (offset_to_symbol_infos, name_to_symbol_infos) = _GroupSymbolInfosFromBinary( | 212 (offset_to_symbol_infos, name_to_symbol_infos) = _GroupSymbolInfosFromBinary( |
| 213 binary_filename) | 213 binary_filename) |
| 214 profiled_symbols = _GetSymbolsFromOrderfile(orderfile_filename) | 214 profiled_symbols = GetSymbolsFromOrderfile(orderfile_filename) |
| 215 expanded_symbols = _ExpandSymbols( | 215 expanded_symbols = _ExpandSymbols( |
| 216 profiled_symbols, name_to_symbol_infos, offset_to_symbol_infos) | 216 profiled_symbols, name_to_symbol_infos, offset_to_symbol_infos) |
| 217 _PrintSymbolsWithPrefixes(expanded_symbols, sys.stdout) | 217 _PrintSymbolsWithPrefixes(expanded_symbols, sys.stdout) |
| 218 # The following is needed otherwise Gold only applies a partial sort. | 218 # The following is needed otherwise Gold only applies a partial sort. |
| 219 print '.text' # gets methods not in a section, such as assembly | 219 print '.text' # gets methods not in a section, such as assembly |
| 220 print '.text.*' # gets everything else | 220 print '.text.*' # gets everything else |
| 221 return 0 | 221 return 0 |
| 222 | 222 |
| 223 | 223 |
| 224 if __name__ == '__main__': | 224 if __name__ == '__main__': |
| 225 logging.basicConfig(level=logging.INFO) | 225 logging.basicConfig(level=logging.INFO) |
| 226 sys.exit(main(sys.argv)) | 226 sys.exit(main(sys.argv)) |
| OLD | NEW |