Dan Albert | 169eb66 | 2015-01-21 16:42:02 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # |
| 3 | # Copyright (C) 2015 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the 'License'); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an 'AS IS' BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # pylint: disable=bad-indentation,bad-continuation |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 18 | import glob |
| 19 | import os |
| 20 | import re |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 21 | import sys |
| 22 | |
Dan Albert | 169eb66 | 2015-01-21 16:42:02 -0800 | [diff] [blame] | 23 | import symbols |
| 24 | |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 25 | only_unwanted = False |
| 26 | if len(sys.argv) > 1: |
| 27 | if sys.argv[1] in ('-u', '--unwanted'): |
| 28 | only_unwanted = True |
| 29 | |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 30 | toolchain = os.environ['ANDROID_TOOLCHAIN'] |
| 31 | arch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain) |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 32 | if arch == 'aarch64': |
| 33 | arch = 'arm64' |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 34 | |
Elliott Hughes | e8e4534 | 2014-06-13 11:50:07 -0700 | [diff] [blame] | 35 | def MangleGlibcNameToBionic(name): |
| 36 | if name in glibc_to_bionic_names: |
| 37 | return glibc_to_bionic_names[name] |
| 38 | return name |
| 39 | |
Dan Albert | 169eb66 | 2015-01-21 16:42:02 -0800 | [diff] [blame] | 40 | def GetNdkIgnored(arch): # pylint: disable=redefined-outer-name |
| 41 | ignored_symbols = set() |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 42 | files = glob.glob('%s/ndk/build/tools/unwanted-symbols/%s/*' % |
| 43 | (os.getenv('ANDROID_BUILD_TOP'), arch)) |
| 44 | for f in files: |
Dan Albert | 169eb66 | 2015-01-21 16:42:02 -0800 | [diff] [blame] | 45 | ignored_symbols |= set(open(f, 'r').read().splitlines()) |
| 46 | return ignored_symbols |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 47 | |
Elliott Hughes | e8e4534 | 2014-06-13 11:50:07 -0700 | [diff] [blame] | 48 | glibc_to_bionic_names = { |
| 49 | '__res_init': 'res_init', |
| 50 | '__res_mkquery': 'res_mkquery', |
| 51 | '__res_query': 'res_query', |
| 52 | '__res_search': 'res_search', |
Dan Albert | 2320b02 | 2014-08-21 11:36:07 -0700 | [diff] [blame] | 53 | '__xpg_basename': '__gnu_basename', |
Elliott Hughes | e8e4534 | 2014-06-13 11:50:07 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Dan Albert | 169eb66 | 2015-01-21 16:42:02 -0800 | [diff] [blame] | 56 | glibc = symbols.GetFromSystemSo([ |
| 57 | 'libc.so.*', |
| 58 | 'librt.so.*', |
| 59 | 'libpthread.so.*', |
| 60 | 'libresolv.so.*', |
| 61 | 'libm.so.*', |
| 62 | 'libutil.so.*', |
| 63 | ]) |
| 64 | |
| 65 | bionic = symbols.GetFromAndroidSo(['libc.so', 'libm.so']) |
| 66 | this_dir = os.path.dirname(os.path.realpath(__file__)) |
| 67 | posix = symbols.GetFromTxt(os.path.join(this_dir, 'posix-2013.txt')) |
| 68 | ndk_ignored = GetNdkIgnored(arch) |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 69 | |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 70 | glibc = set(map(MangleGlibcNameToBionic, glibc)) |
Elliott Hughes | e8e4534 | 2014-06-13 11:50:07 -0700 | [diff] [blame] | 71 | |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 72 | # bionic includes various BSD symbols to ease porting other BSD-licensed code. |
| 73 | bsd_stuff = set([ |
Elliott Hughes | 45bf4c3 | 2014-05-22 18:53:21 -0700 | [diff] [blame] | 74 | 'basename_r', |
| 75 | 'dirname_r', |
| 76 | 'fgetln', |
| 77 | 'fpurge', |
| 78 | 'funopen', |
| 79 | 'gamma_r', |
| 80 | 'gammaf_r', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 81 | 'getprogname', |
| 82 | 'setprogname', |
| 83 | 'strlcat', |
| 84 | 'strlcpy', |
Elliott Hughes | 45bf4c3 | 2014-05-22 18:53:21 -0700 | [diff] [blame] | 85 | 'sys_signame', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 86 | 'wcslcat', |
| 87 | 'wcslcpy' |
| 88 | ]) |
| 89 | # Some symbols are part of the FORTIFY implementation. |
| 90 | FORTIFY_stuff = set([ |
| 91 | '__FD_CLR_chk', |
| 92 | '__FD_ISSET_chk', |
| 93 | '__FD_SET_chk', |
| 94 | '__stack_chk_guard', |
| 95 | '__stpncpy_chk2', |
| 96 | '__strchr_chk', |
| 97 | '__strlcat_chk', |
| 98 | '__strlcpy_chk', |
| 99 | '__strlen_chk', |
| 100 | '__strncpy_chk2', |
| 101 | '__strrchr_chk', |
| 102 | '__umask_chk' |
| 103 | ]) |
Elliott Hughes | b497c43 | 2014-05-20 20:37:56 -0700 | [diff] [blame] | 104 | # Some symbols are used to implement public macros. |
| 105 | macro_stuff = set([ |
| 106 | '__assert2', |
| 107 | '__errno', |
| 108 | '__fe_dfl_env', |
| 109 | '__get_h_errno', |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 110 | '__fpclassifyd', |
| 111 | '__isfinite', |
| 112 | '__isfinitef', |
| 113 | '__isfinitel', |
| 114 | '__isnormal', |
| 115 | '__isnormalf', |
| 116 | '__isnormall', |
| 117 | '__sF', |
| 118 | '__pthread_cleanup_pop', |
| 119 | '__pthread_cleanup_push', |
Elliott Hughes | b497c43 | 2014-05-20 20:37:56 -0700 | [diff] [blame] | 120 | ]) |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 121 | # bionic exposes various Linux features that glibc doesn't. |
| 122 | linux_stuff = set([ |
| 123 | 'getauxval', |
| 124 | 'gettid', |
| 125 | 'tgkill' |
| 126 | ]) |
| 127 | # Some standard stuff isn't yet in the versions of glibc we're using. |
| 128 | std_stuff = set([ |
Elliott Hughes | f6b1d43 | 2014-06-06 15:20:50 -0700 | [diff] [blame] | 129 | 'at_quick_exit', |
| 130 | 'c16rtomb', |
| 131 | 'c32rtomb', |
| 132 | 'mbrtoc16', |
| 133 | 'mbrtoc32', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 134 | ]) |
| 135 | # These have mangled names in glibc, with a macro taking the "obvious" name. |
| 136 | weird_stuff = set([ |
| 137 | 'fstat', |
| 138 | 'fstat64', |
| 139 | 'fstatat', |
| 140 | 'fstatat64', |
| 141 | 'isfinite', |
| 142 | 'isfinitef', |
| 143 | 'isfinitel', |
| 144 | 'isnormal', |
| 145 | 'isnormalf', |
| 146 | 'isnormall', |
| 147 | 'lstat', |
| 148 | 'lstat64', |
| 149 | 'mknod', |
| 150 | 'mknodat', |
| 151 | 'stat', |
| 152 | 'stat64', |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 153 | 'optreset', |
| 154 | 'sigsetjmp', |
| 155 | ]) |
| 156 | # These exist in glibc, but under slightly different names (generally one extra |
| 157 | # or one fewer _). TODO: check against glibc names. |
| 158 | libresolv_stuff = set([ |
| 159 | '__res_send_setqhook', |
| 160 | '__res_send_setrhook', |
| 161 | '_resolv_flush_cache_for_net', |
| 162 | '_resolv_set_nameservers_for_net', |
| 163 | 'dn_expand', |
| 164 | 'nsdispatch', |
| 165 | ]) |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 166 | # Implementation details we know we export (and can't get away from). |
| 167 | known = set([ |
| 168 | '_ctype_', |
| 169 | '__libc_init', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 170 | ]) |
| 171 | |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 172 | if not only_unwanted: |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 173 | #print 'glibc:' |
| 174 | #for symbol in sorted(glibc): |
| 175 | # print symbol |
| 176 | #print |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 177 | |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 178 | #print 'bionic:' |
| 179 | #for symbol in sorted(bionic): |
| 180 | # print symbol |
| 181 | #print |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 182 | |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 183 | print 'in glibc (but not posix) but not bionic:' |
| 184 | for symbol in sorted((glibc - posix).difference(bionic)): |
Elliott Hughes | 6370aed | 2014-11-05 16:22:26 -0800 | [diff] [blame] | 185 | print symbol |
Elliott Hughes | 6370aed | 2014-11-05 16:22:26 -0800 | [diff] [blame] | 186 | print |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 187 | |
| 188 | print 'in posix (and implemented in glibc) but not bionic:' |
| 189 | for symbol in sorted((posix.intersection(glibc)).difference(bionic)): |
| 190 | print symbol |
| 191 | print |
| 192 | |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 193 | print 'in bionic but not glibc:' |
| 194 | |
| 195 | allowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff | |
Dan Albert | fd5ee9a | 2014-08-15 14:20:04 -0700 | [diff] [blame] | 196 | std_stuff | weird_stuff | libresolv_stuff | known) |
Elliott Hughes | b497c43 | 2014-05-20 20:37:56 -0700 | [diff] [blame] | 197 | for symbol in sorted((bionic - allowed_stuff).difference(glibc)): |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 198 | if symbol in ndk_ignored: |
| 199 | symbol += '*' |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 200 | print symbol |
| 201 | |
| 202 | sys.exit(0) |