blob: 9aba2e2cd725027810678bac2d125d920ec54021 [file] [log] [blame]
Dan Albert169eb662015-01-21 16:42:02 -08001#!/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 Hughes5a93e882014-05-16 14:44:38 -070018import glob
19import os
20import re
Elliott Hughes5a93e882014-05-16 14:44:38 -070021import sys
22
Dan Albert169eb662015-01-21 16:42:02 -080023import symbols
24
Dan Albert76212ee2014-08-13 13:04:28 -070025only_unwanted = False
26if len(sys.argv) > 1:
27 if sys.argv[1] in ('-u', '--unwanted'):
28 only_unwanted = True
29
Elliott Hughes5a93e882014-05-16 14:44:38 -070030toolchain = os.environ['ANDROID_TOOLCHAIN']
31arch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain)
Dan Albert76212ee2014-08-13 13:04:28 -070032if arch == 'aarch64':
33 arch = 'arm64'
Elliott Hughes5a93e882014-05-16 14:44:38 -070034
Elliott Hughese8e45342014-06-13 11:50:07 -070035def MangleGlibcNameToBionic(name):
36 if name in glibc_to_bionic_names:
37 return glibc_to_bionic_names[name]
38 return name
39
Dan Albert169eb662015-01-21 16:42:02 -080040def GetNdkIgnored(arch): # pylint: disable=redefined-outer-name
41 ignored_symbols = set()
Dan Albert76212ee2014-08-13 13:04:28 -070042 files = glob.glob('%s/ndk/build/tools/unwanted-symbols/%s/*' %
43 (os.getenv('ANDROID_BUILD_TOP'), arch))
44 for f in files:
Dan Albert169eb662015-01-21 16:42:02 -080045 ignored_symbols |= set(open(f, 'r').read().splitlines())
46 return ignored_symbols
Dan Albert76212ee2014-08-13 13:04:28 -070047
Elliott Hughese8e45342014-06-13 11:50:07 -070048glibc_to_bionic_names = {
49 '__res_init': 'res_init',
50 '__res_mkquery': 'res_mkquery',
51 '__res_query': 'res_query',
52 '__res_search': 'res_search',
Dan Albert2320b022014-08-21 11:36:07 -070053 '__xpg_basename': '__gnu_basename',
Elliott Hughese8e45342014-06-13 11:50:07 -070054}
55
Dan Albert169eb662015-01-21 16:42:02 -080056glibc = symbols.GetFromSystemSo([
57 'libc.so.*',
58 'librt.so.*',
59 'libpthread.so.*',
60 'libresolv.so.*',
61 'libm.so.*',
62 'libutil.so.*',
63])
64
65bionic = symbols.GetFromAndroidSo(['libc.so', 'libm.so'])
66this_dir = os.path.dirname(os.path.realpath(__file__))
67posix = symbols.GetFromTxt(os.path.join(this_dir, 'posix-2013.txt'))
68ndk_ignored = GetNdkIgnored(arch)
Elliott Hughes5a93e882014-05-16 14:44:38 -070069
Elliott Hughes03932212014-12-04 11:24:48 -080070glibc = set(map(MangleGlibcNameToBionic, glibc))
Elliott Hughese8e45342014-06-13 11:50:07 -070071
Elliott Hughes5a93e882014-05-16 14:44:38 -070072# bionic includes various BSD symbols to ease porting other BSD-licensed code.
73bsd_stuff = set([
Elliott Hughesd07c4432016-01-15 19:54:31 -080074 'arc4random',
75 'arc4random_buf',
76 'arc4random_uniform',
Elliott Hughes45bf4c32014-05-22 18:53:21 -070077 'basename_r',
78 'dirname_r',
79 'fgetln',
80 'fpurge',
81 'funopen',
Elliott Hughesf226ee52016-02-03 11:24:28 -080082 'funopen64',
Elliott Hughes45bf4c32014-05-22 18:53:21 -070083 'gamma_r',
84 'gammaf_r',
Elliott Hughes5a93e882014-05-16 14:44:38 -070085 'getprogname',
86 'setprogname',
87 'strlcat',
88 'strlcpy',
Elliott Hughes45bf4c32014-05-22 18:53:21 -070089 'sys_signame',
Elliott Hughes5a93e882014-05-16 14:44:38 -070090 'wcslcat',
Elliott Hughes2adde7b2016-05-06 15:44:26 -070091 'wcslcpy',
Elliott Hughes5a93e882014-05-16 14:44:38 -070092])
93# Some symbols are part of the FORTIFY implementation.
94FORTIFY_stuff = set([
95 '__FD_CLR_chk',
96 '__FD_ISSET_chk',
97 '__FD_SET_chk',
Elliott Hughesd07c4432016-01-15 19:54:31 -080098 '__fwrite_chk',
99 '__memchr_chk',
100 '__memrchr_chk',
101 '__pwrite64_chk',
102 '__pwrite_chk',
Elliott Hughes0bfcbaf2017-08-28 09:18:34 -0700103 '__sendto_chk',
Elliott Hughes5a93e882014-05-16 14:44:38 -0700104 '__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 Hughes21788262016-05-06 14:43:50 -0700112 '__umask_chk',
Elliott Hughesd07c4432016-01-15 19:54:31 -0800113 '__write_chk',
Elliott Hughes5a93e882014-05-16 14:44:38 -0700114])
Elliott Hughes21788262016-05-06 14:43:50 -0700115# Some symbols are used to implement public functions/macros.
Elliott Hughesb497c432014-05-20 20:37:56 -0700116macro_stuff = set([
117 '__assert2',
118 '__errno',
119 '__fe_dfl_env',
120 '__get_h_errno',
Elliott Hughes21788262016-05-06 14:43:50 -0700121 '__gnu_strerror_r',
Dan Albert76212ee2014-08-13 13:04:28 -0700122 '__fpclassifyd',
123 '__isfinite',
124 '__isfinitef',
125 '__isfinitel',
126 '__isnormal',
127 '__isnormalf',
128 '__isnormall',
129 '__sF',
130 '__pthread_cleanup_pop',
131 '__pthread_cleanup_push',
Elliott Hughesb497c432014-05-20 20:37:56 -0700132])
Elliott Hughes5a93e882014-05-16 14:44:38 -0700133# bionic exposes various Linux features that glibc doesn't.
134linux_stuff = set([
135 'getauxval',
136 'gettid',
Elliott Hughes21788262016-05-06 14:43:50 -0700137 'pthread_gettid_np',
138 'tgkill',
Elliott Hughes5a93e882014-05-16 14:44:38 -0700139])
140# Some standard stuff isn't yet in the versions of glibc we're using.
141std_stuff = set([
Elliott Hughesf6b1d432014-06-06 15:20:50 -0700142 'at_quick_exit',
143 'c16rtomb',
144 'c32rtomb',
145 'mbrtoc16',
146 'mbrtoc32',
Elliott Hughes5a93e882014-05-16 14:44:38 -0700147])
148# These have mangled names in glibc, with a macro taking the "obvious" name.
149weird_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 Albert76212ee2014-08-13 13:04:28 -0700166 '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.
171libresolv_stuff = set([
172 '__res_send_setqhook',
173 '__res_send_setrhook',
Elliott Hughes21788262016-05-06 14:43:50 -0700174 '_resolv_delete_cache_for_net',
Dan Albert76212ee2014-08-13 13:04:28 -0700175 '_resolv_flush_cache_for_net',
176 '_resolv_set_nameservers_for_net',
177 'dn_expand',
178 'nsdispatch',
179])
Dan Albert76212ee2014-08-13 13:04:28 -0700180# Implementation details we know we export (and can't get away from).
181known = set([
182 '_ctype_',
183 '__libc_init',
Elliott Hughes5a93e882014-05-16 14:44:38 -0700184])
Elliott Hughes187d37d2016-04-06 13:29:22 -0700185# POSIX has some stuff that's too stupid for words (a64l) or not actually
186# implemented in glibc unless you count always failing with ENOSYS as
187# being implemented (fattach).
Elliott Hughes0bfcbaf2017-08-28 09:18:34 -0700188in_posix_and_glibc_but_dead_or_useless = set([
189 'a64l', # obsolete
190 'confstr', # obsolete
191 'fattach', # obsolete
192 'fdetach', # obsolete
193 'gethostid', # obsolete
194 'getmsg', # obsolete
195 'getpmsg', # obsolete
196 'getutxent', # no utmp on Android
197 'getutxid', # no utmp on Android
198 'getutxline', # no utmp on Android
199 'isastream', # obsolete
200 'l64a', # obsolete
201 'mq_close', # disallowed by SELinux
202 'mq_getattr', # disallowed by SELinux
203 'mq_notify', # disallowed by SELinux
204 'mq_open', # disallowed by SELinux
205 'mq_receive', # disallowed by SELinux
206 'mq_send', # disallowed by SELinux
207 'mq_setattr', # disallowed by SELinux
208 'mq_timedreceive', # disallowed by SELinux
209 'mq_timedsend', # disallowed by SELinux
210 'mq_unlink', # disallowed by SELinux
211 'putmsg', # obsolete
212 'putpmsg', # obsolete
213 'pututxline', # no utmp on Android
214 'shm_open', # disallowed by SELinux
215 'shm_unlink', # disallowed by SELinux
216 'setutxent', # no utmp on Android
217 'strfmon', # icu4c
218 'strfmon_l', # icu4c
219 'ulimit', # obsolete
Elliott Hughes187d37d2016-04-06 13:29:22 -0700220])
221
Elliott Hughes0bfcbaf2017-08-28 09:18:34 -0700222posix = posix - in_posix_and_glibc_but_dead_or_useless
223glibc = glibc - in_posix_and_glibc_but_dead_or_useless
Elliott Hughes5a93e882014-05-16 14:44:38 -0700224
Dan Albert76212ee2014-08-13 13:04:28 -0700225if not only_unwanted:
Elliott Hughes03932212014-12-04 11:24:48 -0800226 #print 'glibc:'
227 #for symbol in sorted(glibc):
228 # print symbol
229 #print
Elliott Hughes5a93e882014-05-16 14:44:38 -0700230
Elliott Hughes03932212014-12-04 11:24:48 -0800231 #print 'bionic:'
232 #for symbol in sorted(bionic):
233 # print symbol
234 #print
Elliott Hughes5a93e882014-05-16 14:44:38 -0700235
Elliott Hughes03932212014-12-04 11:24:48 -0800236 print 'in glibc (but not posix) but not bionic:'
237 for symbol in sorted((glibc - posix).difference(bionic)):
Elliott Hughes6370aed2014-11-05 16:22:26 -0800238 print symbol
Elliott Hughes6370aed2014-11-05 16:22:26 -0800239 print
Elliott Hughes03932212014-12-04 11:24:48 -0800240
241 print 'in posix (and implemented in glibc) but not bionic:'
242 for symbol in sorted((posix.intersection(glibc)).difference(bionic)):
243 print symbol
244 print
245
Dan Albert76212ee2014-08-13 13:04:28 -0700246 print 'in bionic but not glibc:'
247
248allowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff |
Dan Albertfd5ee9a2014-08-15 14:20:04 -0700249 std_stuff | weird_stuff | libresolv_stuff | known)
Elliott Hughesb497c432014-05-20 20:37:56 -0700250for symbol in sorted((bionic - allowed_stuff).difference(glibc)):
Dan Albert76212ee2014-08-13 13:04:28 -0700251 if symbol in ndk_ignored:
252 symbol += '*'
Elliott Hughes5a93e882014-05-16 14:44:38 -0700253 print symbol
254
255sys.exit(0)