Commit d0cc2794 authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[SuperSize] Hide llvm-nm stderr messages during archive.

When llvm-nm finds no symbols in an object file (.o file or embedded in
in .a file) it prints 'no symbols' to stderr. This produces a lot of
noise when running 'supersize archive' from command line.

This CL makes SuperSize capture stderr for calls to llvm-nm (and nm,
although it seems to be more quiet). The number of stderr lines (all
'no symbols' as far as we see), if non-0, is returned by
nm.RunNmOnIntermediates(), and printed by obj_analyzer._RunNm() as a
warning.

Change-Id: I2090f8762614d5fc3102f0ec94ef7e83fc305bfd
Reviewed-on: https://chromium-review.googlesource.com/c/1289989Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601031}
parent 3931a4fc
......@@ -80,8 +80,11 @@ def CollectAliasesByAddress(elf_path, tool_prefix):
# directly takes 3s.
args = [path_util.GetNmPath(tool_prefix), '--no-sort', '--defined-only',
elf_path]
output = subprocess.check_output(args)
for line in output.splitlines():
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# llvm-nm may write to stderr. Discard to denoise.
stdout, _ = proc.communicate()
assert proc.returncode == 0
for line in stdout.splitlines():
space_idx = line.find(' ')
address_str = line[:space_idx]
section = line[space_idx + 1]
......@@ -159,8 +162,14 @@ def RunNmOnIntermediates(target, tool_prefix, output_directory):
args.append(target)
else:
args.extend(target)
output = subprocess.check_output(args, cwd=output_directory)
lines = output.splitlines()
proc = subprocess.Popen(args, cwd=output_directory, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# llvm-nm can print 'no symbols' to stderr. Capture and count the number of
# lines, to be returned to the caller.
stdout, stderr = proc.communicate()
assert proc.returncode == 0
num_no_symbols = len(stderr.splitlines())
lines = stdout.splitlines()
# Empty .a file has no output.
if not lines:
return concurrent.EMPTY_ENCODED_DICT, concurrent.EMPTY_ENCODED_DICT
......@@ -191,4 +200,5 @@ def RunNmOnIntermediates(target, tool_prefix, output_directory):
# TODO(agrieve): We could use path indices as keys rather than paths to cut
# down on marshalling overhead.
return (concurrent.EncodeDictOfLists(symbol_names_by_path),
concurrent.EncodeDictOfLists(string_addresses_by_path))
concurrent.EncodeDictOfLists(string_addresses_by_path),
num_no_symbols)
......@@ -146,7 +146,9 @@ class _BulkObjectFileAnalyzerWorker(object):
# Names are still mangled.
all_paths_by_name = self._paths_by_name
for encoded_syms, encoded_strs in results:
total_no_symbols = 0
for encoded_syms, encoded_strs, num_no_symbols in results:
total_no_symbols += num_no_symbols
symbol_names_by_path = concurrent.DecodeDictOfLists(encoded_syms)
for path, names in symbol_names_by_path.iteritems():
for name in names:
......@@ -154,6 +156,8 @@ class _BulkObjectFileAnalyzerWorker(object):
if encoded_strs != concurrent.EMPTY_ENCODED_DICT:
self._encoded_string_addresses_by_path_chunks.append(encoded_strs)
if total_no_symbols:
logging.warn('nm found no symbols in %d objects.', total_no_symbols)
def _RunLlvmBcAnalyzer(self, paths_by_type):
"""Calls llvm-bcanalyzer to extract string data (for LLD-LTO)."""
......
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