mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
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. llvm-svn: 274365
This commit is contained in:
parent
73e9436c33
commit
5cfa5bd1e5
@ -15,6 +15,7 @@ files (i.e. template instantiations) and we would get defined in the thing
|
|||||||
importing these symbols anyway.
|
importing these symbols anyway.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@ -30,7 +31,8 @@ import argparse
|
|||||||
|
|
||||||
def dumpbin_get_symbols(lib):
|
def dumpbin_get_symbols(lib):
|
||||||
process = subprocess.Popen(['dumpbin','/symbols',lib], bufsize=1,
|
process = subprocess.Popen(['dumpbin','/symbols',lib], bufsize=1,
|
||||||
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
process.stdin.close()
|
process.stdin.close()
|
||||||
for line in process.stdout:
|
for line in process.stdout:
|
||||||
# Look for external symbols that are defined in some section
|
# Look for external symbols that are defined in some section
|
||||||
@ -41,7 +43,8 @@ def dumpbin_get_symbols(lib):
|
|||||||
|
|
||||||
def nm_get_symbols(lib):
|
def nm_get_symbols(lib):
|
||||||
process = subprocess.Popen(['nm',lib], bufsize=1,
|
process = subprocess.Popen(['nm',lib], bufsize=1,
|
||||||
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
process.stdin.close()
|
process.stdin.close()
|
||||||
for line in process.stdout:
|
for line in process.stdout:
|
||||||
# Look for external symbols that are defined in some section
|
# Look for external symbols that are defined in some section
|
||||||
@ -52,7 +55,8 @@ def nm_get_symbols(lib):
|
|||||||
|
|
||||||
def readobj_get_symbols(lib):
|
def readobj_get_symbols(lib):
|
||||||
process = subprocess.Popen(['llvm-readobj','-symbols',lib], bufsize=1,
|
process = subprocess.Popen(['llvm-readobj','-symbols',lib], bufsize=1,
|
||||||
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
process.stdin.close()
|
process.stdin.close()
|
||||||
for line in process.stdout:
|
for line in process.stdout:
|
||||||
# When looking through the output of llvm-readobj we expect to see Name,
|
# When looking through the output of llvm-readobj we expect to see Name,
|
||||||
@ -81,7 +85,8 @@ def dumpbin_is_32bit_windows(lib):
|
|||||||
# dumpbin /headers can output a huge amount of data (>100MB in a debug
|
# dumpbin /headers can output a huge amount of data (>100MB in a debug
|
||||||
# build) so we read only up to the 'machine' line then close the output.
|
# build) so we read only up to the 'machine' line then close the output.
|
||||||
process = subprocess.Popen(['dumpbin','/headers',lib], bufsize=1,
|
process = subprocess.Popen(['dumpbin','/headers',lib], bufsize=1,
|
||||||
stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
process.stdin.close()
|
process.stdin.close()
|
||||||
retval = False
|
retval = False
|
||||||
for line in process.stdout:
|
for line in process.stdout:
|
||||||
@ -94,7 +99,8 @@ def dumpbin_is_32bit_windows(lib):
|
|||||||
return retval
|
return retval
|
||||||
|
|
||||||
def objdump_is_32bit_windows(lib):
|
def objdump_is_32bit_windows(lib):
|
||||||
output = subprocess.check_output(['objdump','-f',lib])
|
output = subprocess.check_output(['objdump','-f',lib],
|
||||||
|
universal_newlines=True)
|
||||||
for line in output:
|
for line in output:
|
||||||
match = re.match('.+file format (\S+)', line)
|
match = re.match('.+file format (\S+)', line)
|
||||||
if match:
|
if match:
|
||||||
@ -102,7 +108,8 @@ def objdump_is_32bit_windows(lib):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def readobj_is_32bit_windows(lib):
|
def readobj_is_32bit_windows(lib):
|
||||||
output = subprocess.check_output(['llvm-readobj','-file-headers',lib])
|
output = subprocess.check_output(['llvm-readobj','-file-headers',lib],
|
||||||
|
universal_newlines=True)
|
||||||
for line in output:
|
for line in output:
|
||||||
match = re.match('Format: (\S+)', line)
|
match = re.match('Format: (\S+)', line)
|
||||||
if match:
|
if match:
|
||||||
@ -345,7 +352,8 @@ if __name__ == '__main__':
|
|||||||
# want the process to wait for something on stdin.
|
# want the process to wait for something on stdin.
|
||||||
p = subprocess.Popen([exe], stdout=subprocess.PIPE,
|
p = subprocess.Popen([exe], stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE)
|
stdin=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
p.stdout.close()
|
p.stdout.close()
|
||||||
p.stderr.close()
|
p.stderr.close()
|
||||||
p.stdin.close()
|
p.stdin.close()
|
||||||
@ -361,10 +369,10 @@ if __name__ == '__main__':
|
|||||||
except OSError:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
if not get_symbols:
|
if not get_symbols:
|
||||||
print >>sys.stderr, "Couldn't find a program to read symbols with"
|
print("Couldn't find a program to read symbols with", file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
if not is_32bit_windows:
|
if not is_32bit_windows:
|
||||||
print >>sys.stderr, "Couldn't find a program to determing the target"
|
print("Couldn't find a program to determing the target", file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# How we determine which symbols to keep and which to discard depends on
|
# How we determine which symbols to keep and which to discard depends on
|
||||||
@ -390,7 +398,7 @@ if __name__ == '__main__':
|
|||||||
lib = 'lib'+lib+s
|
lib = 'lib'+lib+s
|
||||||
break
|
break
|
||||||
if not any([lib.endswith(s) for s in suffixes]):
|
if not any([lib.endswith(s) for s in suffixes]):
|
||||||
print >>sys.stderr, "Don't know what to do with argument "+lib
|
print("Don't know what to do with argument "+lib, file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
libs.append(lib)
|
libs.append(lib)
|
||||||
|
|
||||||
@ -423,7 +431,7 @@ if __name__ == '__main__':
|
|||||||
# Merge everything into a single dict
|
# Merge everything into a single dict
|
||||||
symbols = dict()
|
symbols = dict()
|
||||||
for this_lib_symbols in libs_symbols:
|
for this_lib_symbols in libs_symbols:
|
||||||
for k,v in this_lib_symbols.items():
|
for k,v in list(this_lib_symbols.items()):
|
||||||
symbols[k] = v + symbols.setdefault(k,0)
|
symbols[k] = v + symbols.setdefault(k,0)
|
||||||
|
|
||||||
# Count instances of member functions of template classes, and map the
|
# Count instances of member functions of template classes, and map the
|
||||||
@ -482,7 +490,7 @@ if __name__ == '__main__':
|
|||||||
outfile = open(args.o,'w')
|
outfile = open(args.o,'w')
|
||||||
else:
|
else:
|
||||||
outfile = sys.stdout
|
outfile = sys.stdout
|
||||||
for k,v in symbols.items():
|
for k,v in list(symbols.items()):
|
||||||
template_count = template_function_count[template_function_mapping[k]]
|
template_count = template_function_count[template_function_mapping[k]]
|
||||||
if v == 1 and template_count < 100:
|
if v == 1 and template_count < 100:
|
||||||
print >>outfile, k
|
print(k, file=outfile)
|
||||||
|
Loading…
Reference in New Issue
Block a user