Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Dan Albert | 169eb66 | 2015-01-21 16:42:02 -0800 | [diff] [blame] | 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 | d07c443 | 2016-01-15 19:54:31 -0800 | [diff] [blame] | 74 | 'arc4random', |
| 75 | 'arc4random_buf', |
| 76 | 'arc4random_uniform', |
Elliott Hughes | 45bf4c3 | 2014-05-22 18:53:21 -0700 | [diff] [blame] | 77 | 'basename_r', |
| 78 | 'dirname_r', |
| 79 | 'fgetln', |
| 80 | 'fpurge', |
| 81 | 'funopen', |
Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 82 | 'funopen64', |
Elliott Hughes | 45bf4c3 | 2014-05-22 18:53:21 -0700 | [diff] [blame] | 83 | 'gamma_r', |
| 84 | 'gammaf_r', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 85 | 'getprogname', |
| 86 | 'setprogname', |
| 87 | 'strlcat', |
| 88 | 'strlcpy', |
Elliott Hughes | 45bf4c3 | 2014-05-22 18:53:21 -0700 | [diff] [blame] | 89 | 'sys_signame', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 90 | 'wcslcat', |
Elliott Hughes | 2adde7b | 2016-05-06 15:44:26 -0700 | [diff] [blame] | 91 | 'wcslcpy', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 92 | ]) |
| 93 | # Some symbols are part of the FORTIFY implementation. |
| 94 | FORTIFY_stuff = set([ |
| 95 | '__FD_CLR_chk', |
| 96 | '__FD_ISSET_chk', |
| 97 | '__FD_SET_chk', |
Elliott Hughes | d07c443 | 2016-01-15 19:54:31 -0800 | [diff] [blame] | 98 | '__fwrite_chk', |
| 99 | '__memchr_chk', |
| 100 | '__memrchr_chk', |
| 101 | '__pwrite64_chk', |
| 102 | '__pwrite_chk', |
Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 103 | '__sendto_chk', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 104 | '__stack_chk_guard', |
| 105 | '__stpncpy_chk2', |
| 106 | '__strchr_chk', |
| 107 | '__strlcat_chk', |
| 108 | '__strlcpy_chk', |
| 109 | '__strlen_chk', |
| 110 | '__strncpy_chk2', |
| 111 | '__strrchr_chk', |
Elliott Hughes | 2178826 | 2016-05-06 14:43:50 -0700 | [diff] [blame] | 112 | '__umask_chk', |
Elliott Hughes | d07c443 | 2016-01-15 19:54:31 -0800 | [diff] [blame] | 113 | '__write_chk', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 114 | ]) |
Elliott Hughes | 2178826 | 2016-05-06 14:43:50 -0700 | [diff] [blame] | 115 | # Some symbols are used to implement public functions/macros. |
Elliott Hughes | b497c43 | 2014-05-20 20:37:56 -0700 | [diff] [blame] | 116 | macro_stuff = set([ |
| 117 | '__assert2', |
| 118 | '__errno', |
| 119 | '__fe_dfl_env', |
| 120 | '__get_h_errno', |
Elliott Hughes | 2178826 | 2016-05-06 14:43:50 -0700 | [diff] [blame] | 121 | '__gnu_strerror_r', |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 122 | '__fpclassifyd', |
| 123 | '__isfinite', |
| 124 | '__isfinitef', |
| 125 | '__isfinitel', |
| 126 | '__isnormal', |
| 127 | '__isnormalf', |
| 128 | '__isnormall', |
| 129 | '__sF', |
| 130 | '__pthread_cleanup_pop', |
| 131 | '__pthread_cleanup_push', |
Elliott Hughes | b497c43 | 2014-05-20 20:37:56 -0700 | [diff] [blame] | 132 | ]) |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 133 | # bionic exposes various Linux features that glibc doesn't. |
| 134 | linux_stuff = set([ |
| 135 | 'getauxval', |
| 136 | 'gettid', |
Elliott Hughes | 2178826 | 2016-05-06 14:43:50 -0700 | [diff] [blame] | 137 | 'pthread_gettid_np', |
| 138 | 'tgkill', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 139 | ]) |
| 140 | # Some standard stuff isn't yet in the versions of glibc we're using. |
| 141 | std_stuff = set([ |
Elliott Hughes | f6b1d43 | 2014-06-06 15:20:50 -0700 | [diff] [blame] | 142 | 'at_quick_exit', |
| 143 | 'c16rtomb', |
| 144 | 'c32rtomb', |
| 145 | 'mbrtoc16', |
| 146 | 'mbrtoc32', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 147 | ]) |
| 148 | # These have mangled names in glibc, with a macro taking the "obvious" name. |
| 149 | weird_stuff = set([ |
| 150 | 'fstat', |
| 151 | 'fstat64', |
| 152 | 'fstatat', |
| 153 | 'fstatat64', |
| 154 | 'isfinite', |
| 155 | 'isfinitef', |
| 156 | 'isfinitel', |
| 157 | 'isnormal', |
| 158 | 'isnormalf', |
| 159 | 'isnormall', |
| 160 | 'lstat', |
| 161 | 'lstat64', |
| 162 | 'mknod', |
| 163 | 'mknodat', |
| 164 | 'stat', |
| 165 | 'stat64', |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 166 | 'optreset', |
| 167 | 'sigsetjmp', |
| 168 | ]) |
| 169 | # These exist in glibc, but under slightly different names (generally one extra |
| 170 | # or one fewer _). TODO: check against glibc names. |
| 171 | libresolv_stuff = set([ |
| 172 | '__res_send_setqhook', |
| 173 | '__res_send_setrhook', |
Elliott Hughes | 2178826 | 2016-05-06 14:43:50 -0700 | [diff] [blame] | 174 | '_resolv_delete_cache_for_net', |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 175 | '_resolv_flush_cache_for_net', |
| 176 | '_resolv_set_nameservers_for_net', |
| 177 | 'dn_expand', |
| 178 | 'nsdispatch', |
| 179 | ]) |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 180 | # Implementation details we know we export (and can't get away from). |
| 181 | known = set([ |
| 182 | '_ctype_', |
| 183 | '__libc_init', |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 184 | ]) |
Elliott Hughes | cf34653 | 2020-07-31 10:35:03 -0700 | [diff] [blame] | 185 | # POSIX has some stuff that's unusable in the modern world (a64l) or not |
| 186 | # actually implemented in glibc unless you count always failing with ENOSYS |
| 187 | # as being implemented (fattach). Other stuff (fmtmsg) isn't used in any |
Elliott Hughes | 01a57d1 | 2017-10-18 14:00:13 -0700 | [diff] [blame] | 188 | # codebase I have access to, internal or external. |
Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 189 | in_posix_and_glibc_but_dead_or_useless = set([ |
| 190 | 'a64l', # obsolete |
| 191 | 'confstr', # obsolete |
Elliott Hughes | d036a8d | 2017-10-12 20:32:22 -0700 | [diff] [blame] | 192 | 'endutxent', # no utmp on Android |
Elliott Hughes | 90e3f44 | 2017-10-19 21:52:51 -0700 | [diff] [blame] | 193 | 'fattach', # <stropts.h> marked obsolescent |
| 194 | 'fdetach', # <stropts.h> marked obsolescent |
Elliott Hughes | 01a57d1 | 2017-10-18 14:00:13 -0700 | [diff] [blame] | 195 | 'fmtmsg', # unused |
| 196 | 'getdate', # unused |
| 197 | 'getdate_err', # unused |
Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 198 | 'gethostid', # obsolete |
Elliott Hughes | 90e3f44 | 2017-10-19 21:52:51 -0700 | [diff] [blame] | 199 | 'getmsg', # <stropts.h> marked obsolescent |
| 200 | 'getpmsg', # <stropts.h> marked obsolescent |
Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 201 | 'getutxent', # no utmp on Android |
| 202 | 'getutxid', # no utmp on Android |
| 203 | 'getutxline', # no utmp on Android |
Elliott Hughes | 90e3f44 | 2017-10-19 21:52:51 -0700 | [diff] [blame] | 204 | 'isastream', # <stropts.h> marked obsolescent |
Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 205 | 'l64a', # obsolete |
| 206 | 'mq_close', # disallowed by SELinux |
| 207 | 'mq_getattr', # disallowed by SELinux |
| 208 | 'mq_notify', # disallowed by SELinux |
| 209 | 'mq_open', # disallowed by SELinux |
| 210 | 'mq_receive', # disallowed by SELinux |
| 211 | 'mq_send', # disallowed by SELinux |
| 212 | 'mq_setattr', # disallowed by SELinux |
| 213 | 'mq_timedreceive', # disallowed by SELinux |
| 214 | 'mq_timedsend', # disallowed by SELinux |
| 215 | 'mq_unlink', # disallowed by SELinux |
Elliott Hughes | 6244627 | 2017-10-13 10:21:37 -0700 | [diff] [blame] | 216 | 'pthread_getconcurrency', # marked obsolescent |
| 217 | 'pthread_setconcurrency', # marked obsolescent |
Elliott Hughes | 90e3f44 | 2017-10-19 21:52:51 -0700 | [diff] [blame] | 218 | 'putmsg', # <stropts.h> marked obsolescent |
| 219 | 'putpmsg', # <stropts.h> marked obsolescent |
Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 220 | 'pututxline', # no utmp on Android |
| 221 | 'shm_open', # disallowed by SELinux |
| 222 | 'shm_unlink', # disallowed by SELinux |
| 223 | 'setutxent', # no utmp on Android |
Elliott Hughes | 61c9c80 | 2017-10-19 14:54:05 -0700 | [diff] [blame] | 224 | 'sockatmark', # obsolete (https://tools.ietf.org/html/rfc6093) |
Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 225 | 'strfmon', # icu4c |
| 226 | 'strfmon_l', # icu4c |
Elliott Hughes | 90e3f44 | 2017-10-19 21:52:51 -0700 | [diff] [blame] | 227 | 'ulimit', # <ulimit.h> marked obsolescent |
Elliott Hughes | 187d37d | 2016-04-06 13:29:22 -0700 | [diff] [blame] | 228 | ]) |
| 229 | |
Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 230 | posix = posix - in_posix_and_glibc_but_dead_or_useless |
| 231 | glibc = glibc - in_posix_and_glibc_but_dead_or_useless |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 232 | |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 233 | if not only_unwanted: |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 234 | #print('glibc:') |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 235 | #for symbol in sorted(glibc): |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 236 | # print(symbol) |
| 237 | #print() |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 238 | |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 239 | #print('bionic:') |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 240 | #for symbol in sorted(bionic): |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 241 | # print(symbol) |
| 242 | #print() |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 243 | |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 244 | print('in glibc (but not posix) but not bionic:') |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 245 | for symbol in sorted((glibc - posix).difference(bionic)): |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 246 | print(symbol) |
| 247 | print() |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 248 | |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 249 | print('in posix (and implemented in glibc) but not bionic:') |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 250 | for symbol in sorted((posix.intersection(glibc)).difference(bionic)): |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 251 | print(symbol) |
| 252 | print() |
Elliott Hughes | 0393221 | 2014-12-04 11:24:48 -0800 | [diff] [blame] | 253 | |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 254 | print('in bionic but not glibc:') |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 255 | |
| 256 | allowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff | |
Dan Albert | fd5ee9a | 2014-08-15 14:20:04 -0700 | [diff] [blame] | 257 | std_stuff | weird_stuff | libresolv_stuff | known) |
Elliott Hughes | b497c43 | 2014-05-20 20:37:56 -0700 | [diff] [blame] | 258 | for symbol in sorted((bionic - allowed_stuff).difference(glibc)): |
Dan Albert | 76212ee | 2014-08-13 13:04:28 -0700 | [diff] [blame] | 259 | if symbol in ndk_ignored: |
| 260 | symbol += '*' |
Elliott Hughes | 6b586e7 | 2021-04-15 13:39:08 -0700 | [diff] [blame] | 261 | print(symbol) |
Elliott Hughes | 5a93e88 | 2014-05-16 14:44:38 -0700 | [diff] [blame] | 262 | |
| 263 | sys.exit(0) |