Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 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 | def GetSymbolsFromSo(so_file): |
| 14 | |
| 15 | # Example readelf output: |
| 16 | # 264: 0001623c 4 FUNC GLOBAL DEFAULT 8 cabsf |
| 17 | # 266: 00016244 4 FUNC GLOBAL DEFAULT 8 dremf |
| 18 | # 267: 00019018 4 OBJECT GLOBAL DEFAULT 11 __fe_dfl_env |
| 19 | # 268: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_dcmplt |
| 20 | |
| 21 | r = re.compile(r' +\d+: [0-9a-f]+ +\d+ (I?FUNC|OBJECT) +\S+ +\S+ +\d+ (\S+)') |
| 22 | |
| 23 | symbols = set() |
| 24 | |
| 25 | for line in subprocess.check_output(['readelf', '--dyn-syms', '-W', so_file]).split('\n'): |
| 26 | if ' HIDDEN ' in line or ' UND ' in line: |
| 27 | continue |
| 28 | m = r.match(line) |
| 29 | if m: |
| 30 | symbol = m.group(2) |
| 31 | symbol = re.sub('@.*', '', symbol) |
| 32 | symbols.add(symbol) |
| 33 | |
| 34 | return symbols |
| 35 | |
| 36 | def GetSymbolsFromAndroidSo(*files): |
| 37 | symbols = set() |
| 38 | for f in files: |
| 39 | symbols = symbols | GetSymbolsFromSo('%s/system/lib64/%s' % (os.environ['ANDROID_PRODUCT_OUT'], f)) |
| 40 | return symbols |
| 41 | |
| 42 | def GetSymbolsFromSystemSo(*files): |
| 43 | symbols = set() |
| 44 | for f in files: |
| 45 | f = glob.glob('/lib/x86_64-linux-gnu/%s' % f)[-1] |
| 46 | symbols = symbols | GetSymbolsFromSo(f) |
| 47 | return symbols |
| 48 | |
| 49 | glibc = GetSymbolsFromSystemSo('libc.so.*', 'librt.so.*', 'libpthread.so.*', 'libresolv.so.*', 'libm.so.*') |
| 50 | bionic = GetSymbolsFromAndroidSo('libc.so', 'libm.so') |
| 51 | |
| 52 | # bionic includes various BSD symbols to ease porting other BSD-licensed code. |
| 53 | bsd_stuff = set([ |
Elliott Hughes | 45bf4c3 | 2014-05-22 18:53:21 -0700 | [diff] [blame^] | 54 | 'basename_r', |
| 55 | 'dirname_r', |
| 56 | 'fgetln', |
| 57 | 'fpurge', |
| 58 | 'funopen', |
| 59 | 'gamma_r', |
| 60 | 'gammaf_r', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 61 | 'getprogname', |
| 62 | 'setprogname', |
| 63 | 'strlcat', |
| 64 | 'strlcpy', |
Elliott Hughes | 45bf4c3 | 2014-05-22 18:53:21 -0700 | [diff] [blame^] | 65 | 'sys_signame', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 66 | 'wcslcat', |
| 67 | 'wcslcpy' |
| 68 | ]) |
| 69 | # Some symbols are part of the FORTIFY implementation. |
| 70 | FORTIFY_stuff = set([ |
| 71 | '__FD_CLR_chk', |
| 72 | '__FD_ISSET_chk', |
| 73 | '__FD_SET_chk', |
| 74 | '__stack_chk_guard', |
| 75 | '__stpncpy_chk2', |
| 76 | '__strchr_chk', |
| 77 | '__strlcat_chk', |
| 78 | '__strlcpy_chk', |
| 79 | '__strlen_chk', |
| 80 | '__strncpy_chk2', |
| 81 | '__strrchr_chk', |
| 82 | '__umask_chk' |
| 83 | ]) |
Elliott Hughes | b497c43 | 2014-05-20 20:37:56 -0700 | [diff] [blame] | 84 | # Some symbols are used to implement public macros. |
| 85 | macro_stuff = set([ |
| 86 | '__assert2', |
| 87 | '__errno', |
| 88 | '__fe_dfl_env', |
| 89 | '__get_h_errno', |
| 90 | ]) |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 91 | # bionic exposes various Linux features that glibc doesn't. |
| 92 | linux_stuff = set([ |
| 93 | 'getauxval', |
| 94 | 'gettid', |
| 95 | 'tgkill' |
| 96 | ]) |
| 97 | # Some standard stuff isn't yet in the versions of glibc we're using. |
| 98 | std_stuff = set([ |
| 99 | 'at_quick_exit' |
| 100 | ]) |
| 101 | # These have mangled names in glibc, with a macro taking the "obvious" name. |
| 102 | weird_stuff = set([ |
| 103 | 'fstat', |
| 104 | 'fstat64', |
| 105 | 'fstatat', |
| 106 | 'fstatat64', |
| 107 | 'isfinite', |
| 108 | 'isfinitef', |
| 109 | 'isfinitel', |
| 110 | 'isnormal', |
| 111 | 'isnormalf', |
| 112 | 'isnormall', |
| 113 | 'lstat', |
| 114 | 'lstat64', |
| 115 | 'mknod', |
| 116 | 'mknodat', |
| 117 | 'stat', |
| 118 | 'stat64', |
| 119 | ]) |
| 120 | |
| 121 | print 'glibc:' |
| 122 | for symbol in sorted(glibc): |
| 123 | print symbol |
| 124 | |
| 125 | print |
| 126 | print 'bionic:' |
| 127 | for symbol in sorted(bionic): |
| 128 | print symbol |
| 129 | |
| 130 | print |
| 131 | print 'in bionic but not glibc:' |
Elliott Hughes | b497c43 | 2014-05-20 20:37:56 -0700 | [diff] [blame] | 132 | allowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff | std_stuff | weird_stuff) |
| 133 | for symbol in sorted((bionic - allowed_stuff).difference(glibc)): |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 134 | print symbol |
| 135 | |
| 136 | sys.exit(0) |