OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 """Classes that comprise the data model for binary size analysis. | 4 """Classes that comprise the data model for binary size analysis. |
5 | 5 |
6 The primary classes are Symbol, and SymbolGroup. | 6 The primary classes are Symbol, and SymbolGroup. |
7 | 7 |
8 Description of common properties: | 8 Description of common properties: |
9 * address: The start address of the symbol. | 9 * address: The start address of the symbol. |
10 May be 0 (e.g. for .bss or for SymbolGroups). | 10 May be 0 (e.g. for .bss or for SymbolGroups). |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 't': '.text', | 50 't': '.text', |
51 } | 51 } |
52 | 52 |
53 FLAG_ANONYMOUS = 1 | 53 FLAG_ANONYMOUS = 1 |
54 FLAG_STARTUP = 2 | 54 FLAG_STARTUP = 2 |
55 FLAG_UNLIKELY = 4 | 55 FLAG_UNLIKELY = 4 |
56 FLAG_REL = 8 | 56 FLAG_REL = 8 |
57 FLAG_REL_LOCAL = 16 | 57 FLAG_REL_LOCAL = 16 |
58 | 58 |
59 | 59 |
60 def _StripCloneSuffix(name): | |
61 clone_idx = name.find(' [clone ') | |
62 if clone_idx != -1: | |
63 return name[:clone_idx] | |
64 return name | |
65 | |
66 | |
67 class SizeInfo(object): | 60 class SizeInfo(object): |
68 """Represents all size information for a single binary. | 61 """Represents all size information for a single binary. |
69 | 62 |
70 Fields: | 63 Fields: |
71 section_sizes: A dict of section_name -> size. | 64 section_sizes: A dict of section_name -> size. |
72 symbols: A SymbolGroup containing all symbols, sorted by address. | 65 symbols: A SymbolGroup containing all symbols, sorted by address. |
73 metadata: A dict. | 66 metadata: A dict. |
74 """ | 67 """ |
75 __slots__ = ( | 68 __slots__ = ( |
76 'section_sizes', | 69 'section_sizes', |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 return self.section_name == '.bss' | 164 return self.section_name == '.bss' |
172 | 165 |
173 def IsGroup(self): | 166 def IsGroup(self): |
174 return False | 167 return False |
175 | 168 |
176 def IsGenerated(self): | 169 def IsGenerated(self): |
177 # TODO(agrieve): Also match generated functions such as: | 170 # TODO(agrieve): Also match generated functions such as: |
178 # startup._GLOBAL__sub_I_page_allocator.cc | 171 # startup._GLOBAL__sub_I_page_allocator.cc |
179 return self.name.endswith(']') and not self.name.endswith('[]') | 172 return self.name.endswith(']') and not self.name.endswith('[]') |
180 | 173 |
181 def _Key(self): | |
182 """Returns a tuple that can be used to see if two Symbol are the same. | |
183 | |
184 Keys are not guaranteed to be unique within a SymbolGroup. For example, it | |
185 is common to have multiple "** merge strings" symbols, which will have a | |
186 common key.""" | |
187 stripped_full_name = self.full_name | |
188 if stripped_full_name: | |
189 stripped_full_name = _StripCloneSuffix(stripped_full_name) | |
190 return (self.section_name, stripped_full_name or self.name) | |
191 | |
192 | 174 |
193 class Symbol(BaseSymbol): | 175 class Symbol(BaseSymbol): |
194 """Represents a single symbol within a binary. | 176 """Represents a single symbol within a binary. |
195 | 177 |
196 Refer to module docs for field descriptions. | 178 Refer to module docs for field descriptions. |
197 """ | 179 """ |
198 | 180 |
199 __slots__ = ( | 181 __slots__ = ( |
200 'address', | 182 'address', |
201 'full_name', | 183 'full_name', |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 694 |
713 def _ExtractPrefixBeforeSeparator(string, separator, count=1): | 695 def _ExtractPrefixBeforeSeparator(string, separator, count=1): |
714 idx = -len(separator) | 696 idx = -len(separator) |
715 prev_idx = None | 697 prev_idx = None |
716 for _ in xrange(count): | 698 for _ in xrange(count): |
717 idx = string.find(separator, idx + len(separator)) | 699 idx = string.find(separator, idx + len(separator)) |
718 if idx < 0: | 700 if idx < 0: |
719 break | 701 break |
720 prev_idx = idx | 702 prev_idx = idx |
721 return string[:prev_idx] | 703 return string[:prev_idx] |
OLD | NEW |