llvm.org GIT mirror llvm / 2b0881d
Make extract_symbols.py be compatible with Python 3 This involved running 2to3 on it and adjusting all uses of subprocess to use universal_newlines=True so the output is text instead of binary. It remains compatible with Python 2.7. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274365 91177308-0d34-0410-b5e6-96231b3b80d8 John Brawn 3 years ago
1 changed file(s) with 21 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
1414 importing these symbols anyway.
1515 """
1616
17 from __future__ import print_function
1718 import sys
1819 import re
1920 import os
2930
3031 def dumpbin_get_symbols(lib):
3132 process = subprocess.Popen(['dumpbin','/symbols',lib], bufsize=1,
32 stdout=subprocess.PIPE, stdin=subprocess.PIPE)
33 stdout=subprocess.PIPE, stdin=subprocess.PIPE,
34 universal_newlines=True)
3335 process.stdin.close()
3436 for line in process.stdout:
3537 # Look for external symbols that are defined in some section
4042
4143 def nm_get_symbols(lib):
4244 process = subprocess.Popen(['nm',lib], bufsize=1,
43 stdout=subprocess.PIPE, stdin=subprocess.PIPE)
45 stdout=subprocess.PIPE, stdin=subprocess.PIPE,
46 universal_newlines=True)
4447 process.stdin.close()
4548 for line in process.stdout:
4649 # Look for external symbols that are defined in some section
5154
5255 def readobj_get_symbols(lib):
5356 process = subprocess.Popen(['llvm-readobj','-symbols',lib], bufsize=1,
54 stdout=subprocess.PIPE, stdin=subprocess.PIPE)
57 stdout=subprocess.PIPE, stdin=subprocess.PIPE,
58 universal_newlines=True)
5559 process.stdin.close()
5660 for line in process.stdout:
5761 # When looking through the output of llvm-readobj we expect to see Name,
8084 # dumpbin /headers can output a huge amount of data (>100MB in a debug
8185 # build) so we read only up to the 'machine' line then close the output.
8286 process = subprocess.Popen(['dumpbin','/headers',lib], bufsize=1,
83 stdout=subprocess.PIPE, stdin=subprocess.PIPE)
87 stdout=subprocess.PIPE, stdin=subprocess.PIPE,
88 universal_newlines=True)
8489 process.stdin.close()
8590 retval = False
8691 for line in process.stdout:
9398 return retval
9499
95100 def objdump_is_32bit_windows(lib):
96 output = subprocess.check_output(['objdump','-f',lib])
101 output = subprocess.check_output(['objdump','-f',lib],
102 universal_newlines=True)
97103 for line in output:
98104 match = re.match('.+file format (\S+)', line)
99105 if match:
101107 return False
102108
103109 def readobj_is_32bit_windows(lib):
104 output = subprocess.check_output(['llvm-readobj','-file-headers',lib])
110 output = subprocess.check_output(['llvm-readobj','-file-headers',lib],
111 universal_newlines=True)
105112 for line in output:
106113 match = re.match('Format: (\S+)', line)
107114 if match:
344351 # want the process to wait for something on stdin.
345352 p = subprocess.Popen([exe], stdout=subprocess.PIPE,
346353 stderr=subprocess.PIPE,
347 stdin=subprocess.PIPE)
354 stdin=subprocess.PIPE,
355 universal_newlines=True)
348356 p.stdout.close()
349357 p.stderr.close()
350358 p.stdin.close()
360368 except OSError:
361369 continue
362370 if not get_symbols:
363 print >>sys.stderr, "Couldn't find a program to read symbols with"
371 print("Couldn't find a program to read symbols with", file=sys.stderr)
364372 exit(1)
365373 if not is_32bit_windows:
366 print >>sys.stderr, "Couldn't find a program to determing the target"
374 print("Couldn't find a program to determing the target", file=sys.stderr)
367375 exit(1)
368376
369377 # How we determine which symbols to keep and which to discard depends on
389397 lib = 'lib'+lib+s
390398 break
391399 if not any([lib.endswith(s) for s in suffixes]):
392 print >>sys.stderr, "Don't know what to do with argument "+lib
400 print("Don't know what to do with argument "+lib, file=sys.stderr)
393401 exit(1)
394402 libs.append(lib)
395403
422430 # Merge everything into a single dict
423431 symbols = dict()
424432 for this_lib_symbols in libs_symbols:
425 for k,v in this_lib_symbols.items():
433 for k,v in list(this_lib_symbols.items()):
426434 symbols[k] = v + symbols.setdefault(k,0)
427435
428436 # Count instances of member functions of template classes, and map the
481489 outfile = open(args.o,'w')
482490 else:
483491 outfile = sys.stdout
484 for k,v in symbols.items():
492 for k,v in list(symbols.items()):
485493 template_count = template_function_count[template_function_mapping[k]]
486494 if v == 1 and template_count < 100:
487 print >>outfile, k
495 print(k, file=outfile)