15a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes#!/usr/bin/python 25a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 35a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesimport glob 45a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesimport os 55a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesimport re 65a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesimport string 75a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesimport subprocess 85a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesimport sys 95a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 105a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughestoolchain = os.environ['ANDROID_TOOLCHAIN'] 115a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesarch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain) 125a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 135a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesdef GetSymbolsFromSo(so_file): 145a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes # Example readelf output: 155a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes # 264: 0001623c 4 FUNC GLOBAL DEFAULT 8 cabsf 165a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes # 266: 00016244 4 FUNC GLOBAL DEFAULT 8 dremf 175a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes # 267: 00019018 4 OBJECT GLOBAL DEFAULT 11 __fe_dfl_env 185a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes # 268: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_dcmplt 195a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 205a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes r = re.compile(r' +\d+: [0-9a-f]+ +\d+ (I?FUNC|OBJECT) +\S+ +\S+ +\d+ (\S+)') 215a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 225a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes symbols = set() 235a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 245a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes for line in subprocess.check_output(['readelf', '--dyn-syms', '-W', so_file]).split('\n'): 25e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes if ' HIDDEN ' in line or ' UND ' in line: 26e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes continue 27e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes m = r.match(line) 28e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes if m: 29e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes symbol = m.group(2) 30e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes symbol = re.sub('@.*', '', symbol) 31e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes symbols.add(symbol) 325a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 335a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes return symbols 345a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 355a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesdef GetSymbolsFromAndroidSo(*files): 365a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes symbols = set() 375a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes for f in files: 385a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes symbols = symbols | GetSymbolsFromSo('%s/system/lib64/%s' % (os.environ['ANDROID_PRODUCT_OUT'], f)) 395a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes return symbols 405a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 415a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesdef GetSymbolsFromSystemSo(*files): 425a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes symbols = set() 435a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes for f in files: 445a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes f = glob.glob('/lib/x86_64-linux-gnu/%s' % f)[-1] 455a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes symbols = symbols | GetSymbolsFromSo(f) 465a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes return symbols 475a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 48e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughesdef MangleGlibcNameToBionic(name): 49e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes if name in glibc_to_bionic_names: 50e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes return glibc_to_bionic_names[name] 51e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes return name 52e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes 53e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughesglibc_to_bionic_names = { 54e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes '__res_init': 'res_init', 55e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes '__res_mkquery': 'res_mkquery', 56e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes '__res_query': 'res_query', 57e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes '__res_search': 'res_search', 58e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes} 59e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes 605a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesglibc = GetSymbolsFromSystemSo('libc.so.*', 'librt.so.*', 'libpthread.so.*', 'libresolv.so.*', 'libm.so.*') 615a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesbionic = GetSymbolsFromAndroidSo('libc.so', 'libm.so') 625a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 63e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughesglibc = map(MangleGlibcNameToBionic, glibc) 64e8e453439fa87d9fccf03006cc4dac76acadf44cElliott Hughes 655a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes# bionic includes various BSD symbols to ease porting other BSD-licensed code. 665a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesbsd_stuff = set([ 6745bf4c315d1e42fafa190b691ce98b152a5d5bf7Elliott Hughes 'basename_r', 6845bf4c315d1e42fafa190b691ce98b152a5d5bf7Elliott Hughes 'dirname_r', 6945bf4c315d1e42fafa190b691ce98b152a5d5bf7Elliott Hughes 'fgetln', 7045bf4c315d1e42fafa190b691ce98b152a5d5bf7Elliott Hughes 'fpurge', 7145bf4c315d1e42fafa190b691ce98b152a5d5bf7Elliott Hughes 'funopen', 7245bf4c315d1e42fafa190b691ce98b152a5d5bf7Elliott Hughes 'gamma_r', 7345bf4c315d1e42fafa190b691ce98b152a5d5bf7Elliott Hughes 'gammaf_r', 745a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'getprogname', 755a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'setprogname', 765a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'strlcat', 775a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'strlcpy', 7845bf4c315d1e42fafa190b691ce98b152a5d5bf7Elliott Hughes 'sys_signame', 795a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'wcslcat', 805a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'wcslcpy' 815a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes]) 825a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes# Some symbols are part of the FORTIFY implementation. 835a93e88c7f8d8ac7de39f8020c2056816deda28cElliott HughesFORTIFY_stuff = set([ 845a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__FD_CLR_chk', 855a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__FD_ISSET_chk', 865a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__FD_SET_chk', 875a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__stack_chk_guard', 885a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__stpncpy_chk2', 895a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__strchr_chk', 905a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__strlcat_chk', 915a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__strlcpy_chk', 925a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__strlen_chk', 935a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__strncpy_chk2', 945a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__strrchr_chk', 955a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes '__umask_chk' 965a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes]) 97b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughes# Some symbols are used to implement public macros. 98b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughesmacro_stuff = set([ 99b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughes '__assert2', 100b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughes '__errno', 101b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughes '__fe_dfl_env', 102b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughes '__get_h_errno', 103b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughes]) 1045a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes# bionic exposes various Linux features that glibc doesn't. 1055a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hugheslinux_stuff = set([ 1065a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'getauxval', 1075a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'gettid', 1085a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'tgkill' 1095a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes]) 1105a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes# Some standard stuff isn't yet in the versions of glibc we're using. 1115a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesstd_stuff = set([ 112f6b1d439ccbc34f8dec0d0c949f566f82786fa5bElliott Hughes 'at_quick_exit', 113f6b1d439ccbc34f8dec0d0c949f566f82786fa5bElliott Hughes 'c16rtomb', 114f6b1d439ccbc34f8dec0d0c949f566f82786fa5bElliott Hughes 'c32rtomb', 115f6b1d439ccbc34f8dec0d0c949f566f82786fa5bElliott Hughes 'mbrtoc16', 116f6b1d439ccbc34f8dec0d0c949f566f82786fa5bElliott Hughes 'mbrtoc32', 1175a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes]) 1185a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes# These have mangled names in glibc, with a macro taking the "obvious" name. 1195a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesweird_stuff = set([ 1205a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'fstat', 1215a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'fstat64', 1225a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'fstatat', 1235a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'fstatat64', 1245a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'isfinite', 1255a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'isfinitef', 1265a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'isfinitel', 1275a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'isnormal', 1285a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'isnormalf', 1295a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'isnormall', 1305a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'lstat', 1315a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'lstat64', 1325a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'mknod', 1335a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'mknodat', 1345a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'stat', 1355a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 'stat64', 1365a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes]) 1375a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 1385a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesprint 'glibc:' 1395a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesfor symbol in sorted(glibc): 1405a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes print symbol 1415a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 1425a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesprint 1435a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesprint 'bionic:' 1445a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesfor symbol in sorted(bionic): 1455a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes print symbol 1465a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 1475a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesprint 1485a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughesprint 'in bionic but not glibc:' 149b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughesallowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff | std_stuff | weird_stuff) 150b497c43336475ff5f0248436510a7fbeccfa96a9Elliott Hughesfor symbol in sorted((bionic - allowed_stuff).difference(glibc)): 1515a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes print symbol 1525a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughes 1535a93e88c7f8d8ac7de39f8020c2056816deda28cElliott Hughessys.exit(0) 154