1 #!/usr/bin/python 2 3 import glob 4 import os 5 import re 6 import string 7 import subprocess 8 import sys 9 10 toolchain = os.environ['ANDROID_TOOLCHAIN'] 11 arch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain) 12 13 sys.stderr.write('Checking symbols for arch "%s"...\n' % arch) 14 15 def GetSymbols(library, functions_or_variables): 16 api = '9' 17 if library == 'libm' and arch == 'arm': 18 api = '3' 19 path = '%s/development/ndk/platforms/android-%s/arch-%s/symbols/%s.so.%s.txt' % (os.environ['ANDROID_BUILD_TOP'], api, arch, library, functions_or_variables) 20 symbols = set() 21 for line in open(path, 'r'): 22 symbols.add(line.rstrip()) 23 #sys.stdout.write('%d %s in %s for %s\n' % (len(symbols), functions_or_variables, library, arch)) 24 return symbols 25 26 def CheckSymbols(library, functions_or_variables): 27 expected_symbols = GetSymbols(library, functions_or_variables) 28 29 so_file = '%s/system/lib/%s.so' % (os.environ['ANDROID_PRODUCT_OUT'], library) 30 31 # Example readelf output: 32 # 264: 0001623c 4 FUNC GLOBAL DEFAULT 8 cabsf 33 # 266: 00016244 4 FUNC GLOBAL DEFAULT 8 dremf 34 # 267: 00019018 4 OBJECT GLOBAL DEFAULT 11 __fe_dfl_env 35 # 268: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_dcmplt 36 37 38 r = re.compile(r' +\d+: [0-9a-f]+ +\d+ (FUNC|OBJECT) +\S+ +\S+ +\d+ (\S+)') 39 40 actual_symbols = set() 41 for line in subprocess.check_output(['readelf', '--dyn-syms', so_file]).split('\n'): 42 m = r.match(line) 43 if m: 44 if m.group(1) == 'FUNC' and functions_or_variables == 'functions': 45 actual_symbols.add(m.group(2)) 46 elif m.group(1) == 'OBJECT' and functions_or_variables == 'variables': 47 actual_symbols.add(m.group(2)) 48 #else: 49 #print 'ignoring: ' % line 50 51 missing = expected_symbols - actual_symbols 52 if len(missing) > 0: 53 sys.stderr.write('%d missing %s in %s for %s:\n' % (len(missing), functions_or_variables, library, arch)) 54 for miss in sorted(missing): 55 sys.stderr.write(' %s\n' % miss) 56 57 return len(missing) == 0 58 59 CheckSymbols("libc", "functions") 60 CheckSymbols("libc", "variables") 61 CheckSymbols("libm", "functions") 62 CheckSymbols("libm", "variables") 63 64 sys.exit(0) 65