Commit bdba7075 authored by Matthew Cary's avatar Matthew Cary Committed by Commit Bot

Orderfile: renable misordered symbol threshold in check_orderfile.py.

Bug: 873380
Change-Id: Iaa194b57f57985a6bc851a2b826555a6d087a57c
Reviewed-on: https://chromium-review.googlesource.com/1171234
Commit-Queue: Matthew Cary <mattcary@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582409}
parent 3bb07ab0
...@@ -16,7 +16,7 @@ import patch_orderfile ...@@ -16,7 +16,7 @@ import patch_orderfile
import symbol_extractor import symbol_extractor
def _VerifySymbolOrder(orderfile_symbols, symbol_infos): def _VerifySymbolOrder(orderfile_symbols, symbol_infos, threshold):
"""Verify symbol ordering. """Verify symbol ordering.
Checks that the non-section symbols in |orderfile_filename| are consistent Checks that the non-section symbols in |orderfile_filename| are consistent
...@@ -25,13 +25,16 @@ def _VerifySymbolOrder(orderfile_symbols, symbol_infos): ...@@ -25,13 +25,16 @@ def _VerifySymbolOrder(orderfile_symbols, symbol_infos):
Args: Args:
orderfile_symbols: ([str]) list of symbols from orderfile. orderfile_symbols: ([str]) list of symbols from orderfile.
symbol_infos: ([SymbolInfo]) symbol infos from binary. symbol_infos: ([SymbolInfo]) symbol infos from binary.
threshold: (int) The number of misordered symbols beyond which we error.
Returns: Returns:
True iff the ordering is consistent. True iff the ordering is consistent within |threshold|.
""" """
last_offset = 0 last_offset = 0
name_to_offset = {si.name: si.offset for si in symbol_infos} name_to_offset = {si.name: si.offset for si in symbol_infos}
missing_count = 0 missing_count = 0
misorder_count = 0
misordered_syms = []
for sym in orderfile_symbols: for sym in orderfile_symbols:
if '.' in sym: if '.' in sym:
continue # sym is a section name. continue # sym is a section name.
...@@ -40,10 +43,17 @@ def _VerifySymbolOrder(orderfile_symbols, symbol_infos): ...@@ -40,10 +43,17 @@ def _VerifySymbolOrder(orderfile_symbols, symbol_infos):
continue continue
next_offset = name_to_offset[sym] next_offset = name_to_offset[sym]
if next_offset < last_offset: if next_offset < last_offset:
logging.error('Out of order at %s (%x/%x)', sym, next_offset, last_offset) misorder_count += 1
return False misordered_syms.append((sym, next_offset, last_offset))
last_offset = next_offset last_offset = next_offset
logging.warning('Missing symbols in verification: %d', missing_count) logging.warning('Missing symbols in verification: %d', missing_count)
if misorder_count:
logging.warning('%d misordered symbols:\n %s', misorder_count,
'\n '.join(str(x) for x in misordered_syms[:10]))
if misorder_count > threshold:
logging.error('%d misordered symbols over threshold %d, failing',
misorder_count, threshold)
return False
return True return True
...@@ -53,7 +63,8 @@ def main(): ...@@ -53,7 +63,8 @@ def main():
parser.add_option('--target-arch', action='store', dest='arch', parser.add_option('--target-arch', action='store', dest='arch',
choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'], choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'],
help='The target architecture for the binary.') help='The target architecture for the binary.')
parser.add_option('--threshold', action='store', dest='threshold', default=20, parser.add_option('--threshold', action='store', dest='threshold',
default=20, type=int,
help='The maximum allowed number of out-of-order symbols.') help='The maximum allowed number of out-of-order symbols.')
options, argv = parser.parse_args(sys.argv) options, argv = parser.parse_args(sys.argv)
if not options.arch: if not options.arch:
...@@ -67,7 +78,7 @@ def main(): ...@@ -67,7 +78,7 @@ def main():
symbol_infos = symbol_extractor.SymbolInfosFromBinary(binary_filename) symbol_infos = symbol_extractor.SymbolInfosFromBinary(binary_filename)
if not _VerifySymbolOrder([sym.strip() for sym in file(orderfile_filename)], if not _VerifySymbolOrder([sym.strip() for sym in file(orderfile_filename)],
symbol_infos): symbol_infos, options.threshold):
return 1 return 1
......
...@@ -18,10 +18,13 @@ class TestCheckOrderFile(unittest.TestCase): ...@@ -18,10 +18,13 @@ class TestCheckOrderFile(unittest.TestCase):
def testVerifySymbolOrder(self): def testVerifySymbolOrder(self):
self.assertTrue(check_orderfile._VerifySymbolOrder( self.assertTrue(check_orderfile._VerifySymbolOrder(
['.second', 'first', 'eighth', 'third'], ['.second', 'first', 'eighth', 'third'],
self._SYMBOL_INFOS)) self._SYMBOL_INFOS, 0))
self.assertFalse(check_orderfile._VerifySymbolOrder( self.assertFalse(check_orderfile._VerifySymbolOrder(
['second', 'first', 'eighth', 'third'], ['second', 'first', 'eighth', 'third'],
self._SYMBOL_INFOS)) self._SYMBOL_INFOS, 0))
self.assertTrue(check_orderfile._VerifySymbolOrder(
['second', 'first', 'eighth', 'third'],
self._SYMBOL_INFOS, 1))
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment