#!/usr/bin/env python3 import os import sys import subprocess sys.stderr.write('scanning...\n') sys.stdout.flush() topnamespace = sys.argv[1] for d in sys.stdin: d = d.strip() objs = [d+'/'+fn for fn in os.listdir(d) if fn.endswith('.o')] namespace = topnamespace dsplit = d.split('/') if len(dsplit) >= 3: for dpart in dsplit: namespace += '_'+dpart.replace('-','_') try: p = subprocess.Popen(['nm','-pP','--defined-only']+objs,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=True) out,err = p.communicate() if err: sys.stderr.write('warning: nm error: %s\n' % err) elif p.returncode: sys.stderr.write('warning: nm failure: %s\n' % p.returncode) else: for line in out.splitlines(): line = line.strip() if line.endswith(':'): obj = line[:-1] continue line = line.split() if len(line) < 2: continue if line[1].startswith('b'): continue if line[1].startswith('d'): continue if line[1].startswith('r'): continue if line[1].startswith('t'): continue symbol = line[0] if symbol.startswith('__odr_asan.'): symbol = symbol[11:] if symbol.startswith('__x86.get_pc_thunk.'): continue if symbol == namespace: continue if symbol == '_'+namespace: continue if symbol.startswith(namespace+'_'): continue if symbol.startswith('_'+namespace+'_'): continue sys.stderr.write('warning: %s: symbol %s outside namespace\n' % (obj,symbol)) except Exception as e: sys.stderr.write('warning: nm failure: %s' % e)