1*8d67ca89SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*8d67ca89SAndroid Build Coastguard Worker# 3*8d67ca89SAndroid Build Coastguard Worker# Copyright (C) 2015 The Android Open Source Project 4*8d67ca89SAndroid Build Coastguard Worker# 5*8d67ca89SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the 'License'); 6*8d67ca89SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*8d67ca89SAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*8d67ca89SAndroid Build Coastguard Worker# 9*8d67ca89SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*8d67ca89SAndroid Build Coastguard Worker# 11*8d67ca89SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*8d67ca89SAndroid Build Coastguard Worker# distributed under the License is distributed on an 'AS IS' BASIS, 13*8d67ca89SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*8d67ca89SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*8d67ca89SAndroid Build Coastguard Worker# limitations under the License. 16*8d67ca89SAndroid Build Coastguard Worker# 17*8d67ca89SAndroid Build Coastguard Worker# pylint: disable=bad-indentation,bad-continuation 18*8d67ca89SAndroid Build Coastguard Workerimport glob 19*8d67ca89SAndroid Build Coastguard Workerimport os 20*8d67ca89SAndroid Build Coastguard Workerimport re 21*8d67ca89SAndroid Build Coastguard Workerimport sys 22*8d67ca89SAndroid Build Coastguard Worker 23*8d67ca89SAndroid Build Coastguard Workerimport symbols 24*8d67ca89SAndroid Build Coastguard Worker 25*8d67ca89SAndroid Build Coastguard Workeronly_unwanted = False 26*8d67ca89SAndroid Build Coastguard Workerif len(sys.argv) > 1: 27*8d67ca89SAndroid Build Coastguard Worker if sys.argv[1] in ('-u', '--unwanted'): 28*8d67ca89SAndroid Build Coastguard Worker only_unwanted = True 29*8d67ca89SAndroid Build Coastguard Worker 30*8d67ca89SAndroid Build Coastguard Workertoolchain = os.environ['ANDROID_TOOLCHAIN'] 31*8d67ca89SAndroid Build Coastguard Workerarch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain) 32*8d67ca89SAndroid Build Coastguard Workerif arch == 'aarch64': 33*8d67ca89SAndroid Build Coastguard Worker arch = 'arm64' 34*8d67ca89SAndroid Build Coastguard Worker 35*8d67ca89SAndroid Build Coastguard Workerdef MangleGlibcNameToBionic(name): 36*8d67ca89SAndroid Build Coastguard Worker if name in glibc_to_bionic_names: 37*8d67ca89SAndroid Build Coastguard Worker return glibc_to_bionic_names[name] 38*8d67ca89SAndroid Build Coastguard Worker return name 39*8d67ca89SAndroid Build Coastguard Worker 40*8d67ca89SAndroid Build Coastguard Workerdef GetNdkIgnored(arch): # pylint: disable=redefined-outer-name 41*8d67ca89SAndroid Build Coastguard Worker ignored_symbols = set() 42*8d67ca89SAndroid Build Coastguard Worker files = glob.glob('%s/ndk/build/tools/unwanted-symbols/%s/*' % 43*8d67ca89SAndroid Build Coastguard Worker (os.getenv('ANDROID_BUILD_TOP'), arch)) 44*8d67ca89SAndroid Build Coastguard Worker for f in files: 45*8d67ca89SAndroid Build Coastguard Worker ignored_symbols |= set(open(f, 'r').read().splitlines()) 46*8d67ca89SAndroid Build Coastguard Worker return ignored_symbols 47*8d67ca89SAndroid Build Coastguard Worker 48*8d67ca89SAndroid Build Coastguard Workerglibc_to_bionic_names = { 49*8d67ca89SAndroid Build Coastguard Worker '__res_init': 'res_init', 50*8d67ca89SAndroid Build Coastguard Worker '__res_mkquery': 'res_mkquery', 51*8d67ca89SAndroid Build Coastguard Worker '__res_query': 'res_query', 52*8d67ca89SAndroid Build Coastguard Worker '__res_search': 'res_search', 53*8d67ca89SAndroid Build Coastguard Worker '__xpg_basename': '__gnu_basename', 54*8d67ca89SAndroid Build Coastguard Worker} 55*8d67ca89SAndroid Build Coastguard Worker 56*8d67ca89SAndroid Build Coastguard Workerglibc = symbols.GetFromSystemSo([ 57*8d67ca89SAndroid Build Coastguard Worker 'libc.so.*', 58*8d67ca89SAndroid Build Coastguard Worker 'librt.so.*', 59*8d67ca89SAndroid Build Coastguard Worker 'libpthread.so.*', 60*8d67ca89SAndroid Build Coastguard Worker 'libresolv.so.*', 61*8d67ca89SAndroid Build Coastguard Worker 'libm.so.*', 62*8d67ca89SAndroid Build Coastguard Worker 'libutil.so.*', 63*8d67ca89SAndroid Build Coastguard Worker]) 64*8d67ca89SAndroid Build Coastguard Worker 65*8d67ca89SAndroid Build Coastguard Workerbionic = symbols.GetFromAndroidSo(['libc.so', 'libm.so']) 66*8d67ca89SAndroid Build Coastguard Workerthis_dir = os.path.dirname(os.path.realpath(__file__)) 67*8d67ca89SAndroid Build Coastguard Workerposix = symbols.GetFromTxt(os.path.join(this_dir, 'posix-2013.txt')) 68*8d67ca89SAndroid Build Coastguard Workerndk_ignored = GetNdkIgnored(arch) 69*8d67ca89SAndroid Build Coastguard Worker 70*8d67ca89SAndroid Build Coastguard Workerglibc = set(map(MangleGlibcNameToBionic, glibc)) 71*8d67ca89SAndroid Build Coastguard Worker 72*8d67ca89SAndroid Build Coastguard Worker# bionic includes various BSD symbols to ease porting other BSD-licensed code. 73*8d67ca89SAndroid Build Coastguard Workerbsd_stuff = set([ 74*8d67ca89SAndroid Build Coastguard Worker 'arc4random', 75*8d67ca89SAndroid Build Coastguard Worker 'arc4random_buf', 76*8d67ca89SAndroid Build Coastguard Worker 'arc4random_uniform', 77*8d67ca89SAndroid Build Coastguard Worker 'basename_r', 78*8d67ca89SAndroid Build Coastguard Worker 'dirname_r', 79*8d67ca89SAndroid Build Coastguard Worker 'fgetln', 80*8d67ca89SAndroid Build Coastguard Worker 'fpurge', 81*8d67ca89SAndroid Build Coastguard Worker 'funopen', 82*8d67ca89SAndroid Build Coastguard Worker 'funopen64', 83*8d67ca89SAndroid Build Coastguard Worker 'gamma_r', 84*8d67ca89SAndroid Build Coastguard Worker 'gammaf_r', 85*8d67ca89SAndroid Build Coastguard Worker 'getprogname', 86*8d67ca89SAndroid Build Coastguard Worker 'setprogname', 87*8d67ca89SAndroid Build Coastguard Worker 'strlcat', 88*8d67ca89SAndroid Build Coastguard Worker 'strlcpy', 89*8d67ca89SAndroid Build Coastguard Worker 'sys_signame', 90*8d67ca89SAndroid Build Coastguard Worker 'wcslcat', 91*8d67ca89SAndroid Build Coastguard Worker 'wcslcpy', 92*8d67ca89SAndroid Build Coastguard Worker]) 93*8d67ca89SAndroid Build Coastguard Worker# Some symbols are part of the FORTIFY implementation. 94*8d67ca89SAndroid Build Coastguard WorkerFORTIFY_stuff = set([ 95*8d67ca89SAndroid Build Coastguard Worker '__FD_CLR_chk', 96*8d67ca89SAndroid Build Coastguard Worker '__FD_ISSET_chk', 97*8d67ca89SAndroid Build Coastguard Worker '__FD_SET_chk', 98*8d67ca89SAndroid Build Coastguard Worker '__fwrite_chk', 99*8d67ca89SAndroid Build Coastguard Worker '__memchr_chk', 100*8d67ca89SAndroid Build Coastguard Worker '__memrchr_chk', 101*8d67ca89SAndroid Build Coastguard Worker '__pwrite64_chk', 102*8d67ca89SAndroid Build Coastguard Worker '__pwrite_chk', 103*8d67ca89SAndroid Build Coastguard Worker '__sendto_chk', 104*8d67ca89SAndroid Build Coastguard Worker '__stack_chk_guard', 105*8d67ca89SAndroid Build Coastguard Worker '__stpncpy_chk2', 106*8d67ca89SAndroid Build Coastguard Worker '__strchr_chk', 107*8d67ca89SAndroid Build Coastguard Worker '__strlcat_chk', 108*8d67ca89SAndroid Build Coastguard Worker '__strlcpy_chk', 109*8d67ca89SAndroid Build Coastguard Worker '__strlen_chk', 110*8d67ca89SAndroid Build Coastguard Worker '__strncpy_chk2', 111*8d67ca89SAndroid Build Coastguard Worker '__strrchr_chk', 112*8d67ca89SAndroid Build Coastguard Worker '__umask_chk', 113*8d67ca89SAndroid Build Coastguard Worker '__write_chk', 114*8d67ca89SAndroid Build Coastguard Worker]) 115*8d67ca89SAndroid Build Coastguard Worker# Some symbols are used to implement public functions/macros. 116*8d67ca89SAndroid Build Coastguard Workermacro_stuff = set([ 117*8d67ca89SAndroid Build Coastguard Worker '__assert2', 118*8d67ca89SAndroid Build Coastguard Worker '__errno', 119*8d67ca89SAndroid Build Coastguard Worker '__fe_dfl_env', 120*8d67ca89SAndroid Build Coastguard Worker '__get_h_errno', 121*8d67ca89SAndroid Build Coastguard Worker '__gnu_strerror_r', 122*8d67ca89SAndroid Build Coastguard Worker '__fpclassifyd', 123*8d67ca89SAndroid Build Coastguard Worker '__isfinite', 124*8d67ca89SAndroid Build Coastguard Worker '__isfinitef', 125*8d67ca89SAndroid Build Coastguard Worker '__isfinitel', 126*8d67ca89SAndroid Build Coastguard Worker '__isnormal', 127*8d67ca89SAndroid Build Coastguard Worker '__isnormalf', 128*8d67ca89SAndroid Build Coastguard Worker '__isnormall', 129*8d67ca89SAndroid Build Coastguard Worker '__sF', 130*8d67ca89SAndroid Build Coastguard Worker '__pthread_cleanup_pop', 131*8d67ca89SAndroid Build Coastguard Worker '__pthread_cleanup_push', 132*8d67ca89SAndroid Build Coastguard Worker]) 133*8d67ca89SAndroid Build Coastguard Worker# bionic exposes various Linux features that glibc doesn't. 134*8d67ca89SAndroid Build Coastguard Workerlinux_stuff = set([ 135*8d67ca89SAndroid Build Coastguard Worker 'getauxval', 136*8d67ca89SAndroid Build Coastguard Worker 'gettid', 137*8d67ca89SAndroid Build Coastguard Worker 'pthread_gettid_np', 138*8d67ca89SAndroid Build Coastguard Worker 'tgkill', 139*8d67ca89SAndroid Build Coastguard Worker]) 140*8d67ca89SAndroid Build Coastguard Worker# Some standard stuff isn't yet in the versions of glibc we're using. 141*8d67ca89SAndroid Build Coastguard Workerstd_stuff = set([ 142*8d67ca89SAndroid Build Coastguard Worker 'at_quick_exit', 143*8d67ca89SAndroid Build Coastguard Worker 'c16rtomb', 144*8d67ca89SAndroid Build Coastguard Worker 'c32rtomb', 145*8d67ca89SAndroid Build Coastguard Worker 'mbrtoc16', 146*8d67ca89SAndroid Build Coastguard Worker 'mbrtoc32', 147*8d67ca89SAndroid Build Coastguard Worker]) 148*8d67ca89SAndroid Build Coastguard Worker# These have mangled names in glibc, with a macro taking the "obvious" name. 149*8d67ca89SAndroid Build Coastguard Workerweird_stuff = set([ 150*8d67ca89SAndroid Build Coastguard Worker 'fstat', 151*8d67ca89SAndroid Build Coastguard Worker 'fstat64', 152*8d67ca89SAndroid Build Coastguard Worker 'fstatat', 153*8d67ca89SAndroid Build Coastguard Worker 'fstatat64', 154*8d67ca89SAndroid Build Coastguard Worker 'isfinite', 155*8d67ca89SAndroid Build Coastguard Worker 'isfinitef', 156*8d67ca89SAndroid Build Coastguard Worker 'isfinitel', 157*8d67ca89SAndroid Build Coastguard Worker 'isnormal', 158*8d67ca89SAndroid Build Coastguard Worker 'isnormalf', 159*8d67ca89SAndroid Build Coastguard Worker 'isnormall', 160*8d67ca89SAndroid Build Coastguard Worker 'lstat', 161*8d67ca89SAndroid Build Coastguard Worker 'lstat64', 162*8d67ca89SAndroid Build Coastguard Worker 'mknod', 163*8d67ca89SAndroid Build Coastguard Worker 'mknodat', 164*8d67ca89SAndroid Build Coastguard Worker 'stat', 165*8d67ca89SAndroid Build Coastguard Worker 'stat64', 166*8d67ca89SAndroid Build Coastguard Worker 'optreset', 167*8d67ca89SAndroid Build Coastguard Worker 'sigsetjmp', 168*8d67ca89SAndroid Build Coastguard Worker]) 169*8d67ca89SAndroid Build Coastguard Worker# These exist in glibc, but under slightly different names (generally one extra 170*8d67ca89SAndroid Build Coastguard Worker# or one fewer _). TODO: check against glibc names. 171*8d67ca89SAndroid Build Coastguard Workerlibresolv_stuff = set([ 172*8d67ca89SAndroid Build Coastguard Worker '__res_send_setqhook', 173*8d67ca89SAndroid Build Coastguard Worker '__res_send_setrhook', 174*8d67ca89SAndroid Build Coastguard Worker '_resolv_delete_cache_for_net', 175*8d67ca89SAndroid Build Coastguard Worker '_resolv_flush_cache_for_net', 176*8d67ca89SAndroid Build Coastguard Worker '_resolv_set_nameservers_for_net', 177*8d67ca89SAndroid Build Coastguard Worker 'dn_expand', 178*8d67ca89SAndroid Build Coastguard Worker 'nsdispatch', 179*8d67ca89SAndroid Build Coastguard Worker]) 180*8d67ca89SAndroid Build Coastguard Worker# Implementation details we know we export (and can't get away from). 181*8d67ca89SAndroid Build Coastguard Workerknown = set([ 182*8d67ca89SAndroid Build Coastguard Worker '_ctype_', 183*8d67ca89SAndroid Build Coastguard Worker '__libc_init', 184*8d67ca89SAndroid Build Coastguard Worker]) 185*8d67ca89SAndroid Build Coastguard Worker# POSIX has some stuff that's unusable in the modern world (a64l) or not 186*8d67ca89SAndroid Build Coastguard Worker# actually implemented in glibc unless you count always failing with ENOSYS 187*8d67ca89SAndroid Build Coastguard Worker# as being implemented (fattach). Other stuff (fmtmsg) isn't used in any 188*8d67ca89SAndroid Build Coastguard Worker# codebase I have access to, internal or external. 189*8d67ca89SAndroid Build Coastguard Workerin_posix_and_glibc_but_dead_or_useless = set([ 190*8d67ca89SAndroid Build Coastguard Worker 'a64l', # obsolete 191*8d67ca89SAndroid Build Coastguard Worker 'confstr', # obsolete 192*8d67ca89SAndroid Build Coastguard Worker 'endutxent', # no utmp on Android 193*8d67ca89SAndroid Build Coastguard Worker 'fattach', # <stropts.h> marked obsolescent 194*8d67ca89SAndroid Build Coastguard Worker 'fdetach', # <stropts.h> marked obsolescent 195*8d67ca89SAndroid Build Coastguard Worker 'fmtmsg', # unused 196*8d67ca89SAndroid Build Coastguard Worker 'getdate', # unused 197*8d67ca89SAndroid Build Coastguard Worker 'getdate_err', # unused 198*8d67ca89SAndroid Build Coastguard Worker 'gethostid', # obsolete 199*8d67ca89SAndroid Build Coastguard Worker 'getmsg', # <stropts.h> marked obsolescent 200*8d67ca89SAndroid Build Coastguard Worker 'getpmsg', # <stropts.h> marked obsolescent 201*8d67ca89SAndroid Build Coastguard Worker 'getutxent', # no utmp on Android 202*8d67ca89SAndroid Build Coastguard Worker 'getutxid', # no utmp on Android 203*8d67ca89SAndroid Build Coastguard Worker 'getutxline', # no utmp on Android 204*8d67ca89SAndroid Build Coastguard Worker 'isastream', # <stropts.h> marked obsolescent 205*8d67ca89SAndroid Build Coastguard Worker 'l64a', # obsolete 206*8d67ca89SAndroid Build Coastguard Worker 'mq_close', # disallowed by SELinux 207*8d67ca89SAndroid Build Coastguard Worker 'mq_getattr', # disallowed by SELinux 208*8d67ca89SAndroid Build Coastguard Worker 'mq_notify', # disallowed by SELinux 209*8d67ca89SAndroid Build Coastguard Worker 'mq_open', # disallowed by SELinux 210*8d67ca89SAndroid Build Coastguard Worker 'mq_receive', # disallowed by SELinux 211*8d67ca89SAndroid Build Coastguard Worker 'mq_send', # disallowed by SELinux 212*8d67ca89SAndroid Build Coastguard Worker 'mq_setattr', # disallowed by SELinux 213*8d67ca89SAndroid Build Coastguard Worker 'mq_timedreceive', # disallowed by SELinux 214*8d67ca89SAndroid Build Coastguard Worker 'mq_timedsend', # disallowed by SELinux 215*8d67ca89SAndroid Build Coastguard Worker 'mq_unlink', # disallowed by SELinux 216*8d67ca89SAndroid Build Coastguard Worker 'pthread_getconcurrency', # marked obsolescent 217*8d67ca89SAndroid Build Coastguard Worker 'pthread_setconcurrency', # marked obsolescent 218*8d67ca89SAndroid Build Coastguard Worker 'putmsg', # <stropts.h> marked obsolescent 219*8d67ca89SAndroid Build Coastguard Worker 'putpmsg', # <stropts.h> marked obsolescent 220*8d67ca89SAndroid Build Coastguard Worker 'pututxline', # no utmp on Android 221*8d67ca89SAndroid Build Coastguard Worker 'shm_open', # disallowed by SELinux 222*8d67ca89SAndroid Build Coastguard Worker 'shm_unlink', # disallowed by SELinux 223*8d67ca89SAndroid Build Coastguard Worker 'setutxent', # no utmp on Android 224*8d67ca89SAndroid Build Coastguard Worker 'sockatmark', # obsolete (https://tools.ietf.org/html/rfc6093) 225*8d67ca89SAndroid Build Coastguard Worker 'strfmon', # icu4c 226*8d67ca89SAndroid Build Coastguard Worker 'strfmon_l', # icu4c 227*8d67ca89SAndroid Build Coastguard Worker 'ulimit', # <ulimit.h> marked obsolescent 228*8d67ca89SAndroid Build Coastguard Worker]) 229*8d67ca89SAndroid Build Coastguard Worker 230*8d67ca89SAndroid Build Coastguard Workerposix = posix - in_posix_and_glibc_but_dead_or_useless 231*8d67ca89SAndroid Build Coastguard Workerglibc = glibc - in_posix_and_glibc_but_dead_or_useless 232*8d67ca89SAndroid Build Coastguard Worker 233*8d67ca89SAndroid Build Coastguard Workerif not only_unwanted: 234*8d67ca89SAndroid Build Coastguard Worker #print('glibc:') 235*8d67ca89SAndroid Build Coastguard Worker #for symbol in sorted(glibc): 236*8d67ca89SAndroid Build Coastguard Worker # print(symbol) 237*8d67ca89SAndroid Build Coastguard Worker #print() 238*8d67ca89SAndroid Build Coastguard Worker 239*8d67ca89SAndroid Build Coastguard Worker #print('bionic:') 240*8d67ca89SAndroid Build Coastguard Worker #for symbol in sorted(bionic): 241*8d67ca89SAndroid Build Coastguard Worker # print(symbol) 242*8d67ca89SAndroid Build Coastguard Worker #print() 243*8d67ca89SAndroid Build Coastguard Worker 244*8d67ca89SAndroid Build Coastguard Worker print('in glibc (but not posix) but not bionic:') 245*8d67ca89SAndroid Build Coastguard Worker for symbol in sorted((glibc - posix).difference(bionic)): 246*8d67ca89SAndroid Build Coastguard Worker print(symbol) 247*8d67ca89SAndroid Build Coastguard Worker print() 248*8d67ca89SAndroid Build Coastguard Worker 249*8d67ca89SAndroid Build Coastguard Worker print('in posix (and implemented in glibc) but not bionic:') 250*8d67ca89SAndroid Build Coastguard Worker for symbol in sorted((posix.intersection(glibc)).difference(bionic)): 251*8d67ca89SAndroid Build Coastguard Worker print(symbol) 252*8d67ca89SAndroid Build Coastguard Worker print() 253*8d67ca89SAndroid Build Coastguard Worker 254*8d67ca89SAndroid Build Coastguard Worker print('in bionic but not glibc:') 255*8d67ca89SAndroid Build Coastguard Worker 256*8d67ca89SAndroid Build Coastguard Workerallowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff | 257*8d67ca89SAndroid Build Coastguard Worker std_stuff | weird_stuff | libresolv_stuff | known) 258*8d67ca89SAndroid Build Coastguard Workerfor symbol in sorted((bionic - allowed_stuff).difference(glibc)): 259*8d67ca89SAndroid Build Coastguard Worker if symbol in ndk_ignored: 260*8d67ca89SAndroid Build Coastguard Worker symbol += '*' 261*8d67ca89SAndroid Build Coastguard Worker print(symbol) 262*8d67ca89SAndroid Build Coastguard Worker 263*8d67ca89SAndroid Build Coastguard Workersys.exit(0) 264