Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Check that symbols are ordered into a binary as they appear in the orderfile. | |
| 7 """ | |
| 8 | |
| 9 import logging | |
| 10 import sys | |
| 11 | |
| 12 import symbol_extractor | |
| 13 import patch_orderfile | |
|
pasko
2015/02/02 10:00:30
nit: alpha
Benoit L
2015/02/02 13:11:45
Done.
| |
| 14 | |
| 15 | |
| 16 _MAX_WARNINGS_TO_PRINT = 200 | |
| 17 | |
| 18 | |
| 19 def _CountMisorderedSymbols(symbols, symbol_infos): | |
| 20 """Count the number of misordered symbols, and log them. | |
| 21 | |
| 22 Args: | |
| 23 symbols: ordered sequence of symbols from the orderfile | |
| 24 symbol_infos: list of SymbolInfo from the binary | |
|
pasko
2015/02/02 10:00:30
nit:
s/list/ordered list/
(seems tiny-ish confusin
Benoit L
2015/02/02 13:11:45
Done.
| |
| 25 | |
| 26 Returns: | |
| 27 (misordered_pairs_count, matched_symbols, unmatched_symbols) | |
|
pasko
2015/02/02 10:00:30
matched_symbols_count and unmatched_symbols_count?
Benoit L
2015/02/02 13:11:45
Done.
| |
| 28 """ | |
| 29 name_to_symbol_info = symbol_extractor.CreateNameToSymbolInfo(symbol_infos) | |
|
pasko
2015/02/02 10:00:30
here we are creating a mapping [name -> info], but
Benoit L
2015/02/02 13:11:45
Yes, I think it is better to keep the whole Symbol
pasko
2015/02/02 14:32:37
OK, given your consideration, seems like a good en
| |
| 30 matched_symbol_infos = [] | |
| 31 missing_count = 0 | |
| 32 | |
| 33 # Find the SymbolInfo matching the orderfile symbols in the binary. | |
| 34 for symbol in symbols: | |
| 35 if symbol in name_to_symbol_info: | |
| 36 matched_symbol_infos.append(name_to_symbol_info[symbol]) | |
| 37 else: | |
| 38 missing_count += 1 | |
| 39 if missing_count < _MAX_WARNINGS_TO_PRINT: | |
| 40 logging.warning('Symbol "%s" is in the orderfile, not in the binary' % | |
| 41 symbol) | |
| 42 logging.warning('%d matched symbols, %d un-matched (Only the first %d ' | |
|
pasko
2015/02/02 10:00:30
this warning should be under:
if missing_count > 0
Benoit L
2015/02/02 13:11:45
I think that printing the number of matched symbol
pasko
2015/02/02 14:32:37
ok, then let's make it log.info to avoid the sea o
| |
| 43 'unmatched symbols are shown)' % ( | |
| 44 len(matched_symbol_infos), missing_count, | |
| 45 _MAX_WARNINGS_TO_PRINT)) | |
| 46 | |
| 47 # In the order of the orderfile, find all the symbols that are at an offset | |
| 48 # smaller than their immediate predecessor, and record the pair. | |
| 49 misordered_symbol_infos = [] | |
| 50 previous_symbol_info = symbol_extractor.SymbolInfo( | |
| 51 name='', offset=-1, size=0, section='') | |
| 52 for symbol_info in matched_symbol_infos: | |
| 53 if symbol_info.offset < previous_symbol_info.offset: | |
| 54 misordered_symbol_infos.append((symbol_info, previous_symbol_info)) | |
| 55 previous_symbol_info = symbol_info | |
| 56 | |
| 57 if len(misordered_symbol_infos) > 0: | |
| 58 for (first, second) in misordered_symbol_infos: | |
|
pasko
2015/02/02 10:00:30
Iterating for it second time makes it harder to re
Benoit L
2015/02/02 13:11:45
Done, but still printing the whole SymbolInfo (for
pasko
2015/02/02 14:32:37
Acknowledged.
| |
| 59 logging.warning("Unordered pair: %s - %s" % (str(first), str(second))) | |
| 60 return (len(misordered_symbol_infos), len(matched_symbol_infos), | |
| 61 missing_count) | |
| 62 | |
| 63 | |
| 64 def main(): | |
| 65 if len(sys.argv) != 4: | |
| 66 logging.error('Usage: check_orderfile.py binary orderfile threshold') | |
|
pasko
2015/02/02 10:00:30
I'm about polishing again: can threshold be option
Benoit L
2015/02/02 13:11:45
Done.
| |
| 67 return 1 | |
| 68 (binary_filename, orderfile_filename, threshold) = sys.argv[1:] | |
| 69 threshold = int(threshold) | |
| 70 | |
| 71 symbols = patch_orderfile._GetSymbolsFromOrderfile(orderfile_filename) | |
| 72 symbol_infos = symbol_extractor.SymbolInfosFromBinary(binary_filename) | |
| 73 (misordered_pairs_count, _, _) = _CountMisorderedSymbols( | |
|
pasko
2015/02/02 10:00:30
Please mention in the comment the non-obvious obse
Benoit L
2015/02/02 13:11:45
Done.
| |
| 74 symbols, symbol_infos) | |
| 75 return misordered_pairs_count > threshold | |
| 76 | |
| 77 | |
| 78 if __name__ == '__main__': | |
| 79 logging.basicConfig(level=logging.INFO) | |
| 80 sys.exit(main()) | |
| OLD | NEW |