Index: tools/binary_size/libsupersize/nm.py |
diff --git a/tools/binary_size/libsupersize/nm.py b/tools/binary_size/libsupersize/nm.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c6811d6b8ff7ac4b6edf3529b81f9e5183022167 |
--- /dev/null |
+++ b/tools/binary_size/libsupersize/nm.py |
@@ -0,0 +1,37 @@ |
+# Copyright 2017 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Dealing with "nm" tool.""" |
+ |
+import collections |
+import subprocess |
+ |
+ |
+def CollectAliasesByAddress(elf_path, tool_prefix): |
+ names_by_address = collections.defaultdict(list) |
+ |
+ # About 60mb of output, but piping takes ~30s, and loading it into RAM |
+ # directly takes 3s. |
+ args = [tool_prefix + 'nm', '--no-sort', '--defined-only', '--demangle', |
+ elf_path] |
+ output = subprocess.check_output(args) |
+ for line in output.splitlines(): |
+ address_str, section, name = line.split(' ', 2) |
+ if section not in 'tT' or not name or name[0] == '$': |
+ continue |
+ |
+ address = int(address_str, 16) & 0xfffffffffffffffe |
+ if not address: |
+ continue |
+ # Constructors often show up twice. |
+ name_list = names_by_address[address] |
+ if name not in name_list: |
+ name_list.append(name) |
+ |
+ # Since this is run in a separate process, minimize data passing by returning |
+ # only aliased symbols. |
+ names_by_address = {k: v for k, v in names_by_address.iteritems() |
+ if len(v) > 1} |
+ |
+ return names_by_address |