]
-def get_symbols(nm, lib):
+def get_symbols_nm(nm, lib):
'''
List all the (non platform-specific) symbols exported by the library
+ using `nm`
'''
symbols = []
platform_name = platform.system()
assert symbol_name[0] == '_'
symbol_name = symbol_name[1:]
symbols.append(symbol_name)
+ return symbols
+
+def get_symbols_dumpbin(dumpbin, lib):
+ '''
+ List all the (non platform-specific) symbols exported by the library
+ using `dumpbin`
+ '''
+ symbols = []
+ output = subprocess.check_output([dumpbin, '/exports', lib],
+ stderr=open(os.devnull, 'w')).decode("ascii")
+ for line in output.splitlines():
+ fields = line.split()
+ # The lines with the symbols are made of at least 4 columns; see details below
+ if len(fields) < 4:
+ continue
+ try:
+ # Making sure the first 3 columns are a dec counter, a hex counter
+ # and a hex address
+ _ = int(fields[0], 10)
+ _ = int(fields[1], 16)
+ _ = int(fields[2], 16)
+ except ValueError:
+ continue
+ symbol_name = fields[3]
+ # De-mangle symbols
+ if symbol_name[0] == '_':
+ symbol_name = symbol_name[1:].split('@')[0]
+ symbols.append(symbol_name)
return symbols
help='path to library')
parser.add_argument('--nm',
action='store',
- required=True,
+ help='path to binary (or name in $PATH)')
+ parser.add_argument('--dumpbin',
+ action='store',
help='path to binary (or name in $PATH)')
args = parser.parse_args()
try:
- lib_symbols = get_symbols(args.nm, args.lib)
+ if platform.system() == 'Windows':
+ if not args.dumpbin:
+ parser.error('--dumpbin is mandatory')
+ lib_symbols = get_symbols_dumpbin(args.dumpbin, args.lib)
+ else:
+ if not args.nm:
+ parser.error('--nm is mandatory')
+ lib_symbols = get_symbols_nm(args.nm, args.lib)
except:
# We can't run this test, but we haven't technically failed it either
# Return the GNU "skip" error code
continue
if symbol in optional_symbols:
continue
+ if symbol[:2] == '_Z':
+ # Ignore random C++ symbols
+ #TODO: figure out if there's any way to avoid exporting them in the first place
+ continue
unknown_symbols.append(symbol)
missing_symbols = [