Commit 14195b4f authored by Matthew Cary's avatar Matthew Cary Committed by Commit Bot

Orderfile: direct verification of symbol ordering.

Bug: 869997
Change-Id: I867cb67d5fc3e4e4a7b3343053c6f38123c3e776
Reviewed-on: https://chromium-review.googlesource.com/1162154Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Commit-Queue: Matthew Cary <mattcary@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582163}
parent 94a8710d
...@@ -68,6 +68,36 @@ def _CountMisorderedSymbols(symbols, symbol_infos): ...@@ -68,6 +68,36 @@ def _CountMisorderedSymbols(symbols, symbol_infos):
return (misordered_count, len(matched_symbol_infos), missing_count) return (misordered_count, len(matched_symbol_infos), missing_count)
def _VerifySymbolOrder(orderfile_symbols, symbol_infos):
"""Verify symbol ordering.
Checks that the non-section symbols in |orderfile_filename| are consistent
with the offsets |symbol_infos|.
Args:
orderfile_symbols: ([str]) list of symbols from orderfile.
symbol_infos: ([SymbolInfo]) symbol infos from binary.
Returns:
True iff the ordering is consistent.
"""
last_offset = 0
name_to_offset = {si.name: si.offset for si in symbol_infos}
missing_count = 0
for sym in orderfile_symbols:
if '.' in sym:
continue # sym is a section name.
if sym not in name_to_offset:
missing_count += 1
continue
next_offset = name_to_offset[sym]
if next_offset < last_offset:
logging.error('Out of order at %s (%x/%x)', sym, next_offset, last_offset)
return False
last_offset = next_offset
logging.warning('Missing symbols in verification: %d', missing_count)
return True
def main(): def main():
parser = optparse.OptionParser(usage= parser = optparse.OptionParser(usage=
'usage: %prog [options] <binary> <orderfile>') 'usage: %prog [options] <binary> <orderfile>')
...@@ -93,6 +123,11 @@ def main(): ...@@ -93,6 +123,11 @@ def main():
symbols = patch_orderfile.GetSymbolsFromOrderfile(orderfile_filename, symbols = patch_orderfile.GetSymbolsFromOrderfile(orderfile_filename,
section_to_symbols_map) section_to_symbols_map)
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)],
symbol_infos):
return 1
# Missing symbols is not an error since some of them can be eliminated through # Missing symbols is not an error since some of them can be eliminated through
# inlining. # inlining.
(misordered_pairs_count, matched_symbols, _) = _CountMisorderedSymbols( (misordered_pairs_count, matched_symbols, _) = _CountMisorderedSymbols(
......
...@@ -41,6 +41,14 @@ class TestCheckOrderFile(unittest.TestCase): ...@@ -41,6 +41,14 @@ class TestCheckOrderFile(unittest.TestCase):
check_orderfile._CountMisorderedSymbols(symbols, self._SYMBOL_INFOS)) check_orderfile._CountMisorderedSymbols(symbols, self._SYMBOL_INFOS))
self.assertEquals(misordered_pairs_count, 1) self.assertEquals(misordered_pairs_count, 1)
def testVerifySymbolOrder(self):
self.assertTrue(check_orderfile._VerifySymbolOrder(
['.second', 'first', 'eighth', 'third'],
self._SYMBOL_INFOS))
self.assertFalse(check_orderfile._VerifySymbolOrder(
['second', 'first', 'eighth', 'third'],
self._SYMBOL_INFOS))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.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