| 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 import commands | 6 import commands |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 orderfile = sys.argv[1] | 10 orderfile = sys.argv[1] |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 while nm_index < len(nmlines) and nm_int == int ( | 32 while nm_index < len(nmlines) and nm_int == int ( |
| 33 nmlines[nm_index].split()[0], 16): | 33 nmlines[nm_index].split()[0], 16): |
| 34 fnames.append(nmlines[nm_index].split()[3]) | 34 fnames.append(nmlines[nm_index].split()[3]) |
| 35 nm_index = nm_index + 1 | 35 nm_index = nm_index + 1 |
| 36 addressMap[nm_int] = fnames | 36 addressMap[nm_int] = fnames |
| 37 uniqueAddrs.append((nm_int, size)) | 37 uniqueAddrs.append((nm_int, size)) |
| 38 else: | 38 else: |
| 39 nm_index = nm_index + 1 | 39 nm_index = nm_index + 1 |
| 40 | 40 |
| 41 def binary_search (addr, start, end): | 41 def binary_search (addr, start, end): |
| 42 # print "addr: " + str(addr) + " start: " + str(start) + " end: " + str(end) | |
| 43 if start >= end or start == end - 1: | 42 if start >= end or start == end - 1: |
| 44 (nm_addr, size) = uniqueAddrs[start] | 43 (nm_addr, size) = uniqueAddrs[start] |
| 45 if not (addr >= nm_addr and addr < nm_addr + size): | 44 if not (addr >= nm_addr and addr < nm_addr + size): |
| 46 sys.stderr.write ("ERROR: did not find function in binary: addr: " + | 45 sys.stderr.write ("ERROR: did not find function in binary: addr: " + |
| 47 hex(addr) + " nm_addr: " + str(nm_addr) + " start: " + str(start) + | 46 hex(addr) + " nm_addr: " + str(nm_addr) + " start: " + str(start) + |
| 48 " end: " + str(end) + "\n") | 47 " end: " + str(end) + "\n") |
| 49 raise Error("error") | 48 raise Error("error") |
| 50 return (addressMap[nm_addr], size) | 49 return (addressMap[nm_addr], size) |
| 51 else: | 50 else: |
| 52 halfway = start + ((end - start) / 2) | 51 halfway = start + ((end - start) / 2) |
| 53 (nm_addr, size) = uniqueAddrs[halfway] | 52 (nm_addr, size) = uniqueAddrs[halfway] |
| 54 # print "nm_addr: " + str(nm_addr) + " halfway: " + str(halfway) | |
| 55 if (addr >= nm_addr and addr < nm_addr + size): | 53 if (addr >= nm_addr and addr < nm_addr + size): |
| 56 return (addressMap[nm_addr], size) | 54 return (addressMap[nm_addr], size) |
| 57 elif (addr < nm_addr): | 55 elif (addr < nm_addr): |
| 58 return binary_search (addr, start, halfway) | 56 return binary_search (addr, start, halfway) |
| 59 elif (addr >= nm_addr + size): | 57 elif (addr >= nm_addr + size): |
| 60 return binary_search (addr, halfway, end) | 58 return binary_search (addr, halfway, end) |
| 61 else: | 59 else: |
| 62 raise "ERROR: did not expect this case" | 60 raise "ERROR: did not expect this case" |
| 63 | 61 |
| 64 f = open (orderfile) | 62 f = open (orderfile) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 addrs = [] | 98 addrs = [] |
| 101 # sys.stderr.write ("WARNING: could not find symbol " + function + "\n") | 99 # sys.stderr.write ("WARNING: could not find symbol " + function + "\n") |
| 102 for addr in addrs: | 100 for addr in addrs: |
| 103 if not (addr in addresses): | 101 if not (addr in addresses): |
| 104 addresses.append(addr) | 102 addresses.append(addr) |
| 105 sys.stderr.write ("symbols found: " + str(symbols_found) + "\n") | 103 sys.stderr.write ("symbols found: " + str(symbols_found) + "\n") |
| 106 | 104 |
| 107 sys.stderr.write ("number of addresses: " + str(len(addresses)) + "\n") | 105 sys.stderr.write ("number of addresses: " + str(len(addresses)) + "\n") |
| 108 total_size = 0 | 106 total_size = 0 |
| 109 for addr in addresses: | 107 for addr in addresses: |
| 110 # if (count % 500 == 0): | |
| 111 # print "current count: " + str(count) | |
| 112 (functions, size) = binary_search (addr, 0, len(uniqueAddrs)) | 108 (functions, size) = binary_search (addr, 0, len(uniqueAddrs)) |
| 113 total_size = total_size + size | 109 total_size = total_size + size |
| 110 prefixes = ['.text.', '.text.startup.', '.text.hot.', '.text.unlikely.'] |
| 114 for function in functions: | 111 for function in functions: |
| 115 print ".text." + function | 112 for prefix in prefixes: |
| 116 print "" | 113 print prefix + function |
| 114 |
| 115 # The following is needed otherwise Gold only applies a partial sort. |
| 116 print '.text.*' |
| 117 sys.stderr.write ("total_size: " + str(total_size) + "\n") | 117 sys.stderr.write ("total_size: " + str(total_size) + "\n") |
| OLD | NEW |